Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit ee4d6b4

Browse files
committed
Reformat using recommended IntelliJ Kotlin style
1 parent 664c921 commit ee4d6b4

30 files changed

+533
-450
lines changed

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<artifactId>slf4j-simple</artifactId>
4949
<version>1.7.25</version>
5050
</dependency>
51+
<dependency>
52+
<groupId>io.javalin</groupId>
53+
<artifactId>javalin</artifactId>
54+
<version>3.12.0</version>
55+
</dependency>
5156
</dependencies>
5257

5358
<build>

src/main/kotlin/dev/rayzr/gameboi/Gameboi.kt

+44-42
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,23 @@ fun main() {
3838

3939
// Init JDA
4040
Gameboi.shardManager = DefaultShardManagerBuilder.create(
41-
GatewayIntent.GUILD_MESSAGES,
42-
GatewayIntent.GUILD_MESSAGE_REACTIONS
41+
GatewayIntent.GUILD_MESSAGES,
42+
GatewayIntent.GUILD_MESSAGE_REACTIONS
4343
)
44-
.setShardsTotal(Gameboi.shardCount)
45-
.setToken(Gameboi.token)
46-
.addEventListeners(Gameboi, ReactionListener, MessageListener)
47-
.build()
48-
49-
// val jda = JDABuilder(Gameboi.token)
50-
// .addEventListeners(Gameboi, ReactionListener, MessageListener)
51-
// .build()
52-
// .awaitReady()
44+
.setShardsTotal(Gameboi.shardCount)
45+
.setToken(Gameboi.token)
46+
.addEventListeners(Gameboi, ReactionListener, MessageListener)
47+
.build()
5348

5449
// Generate invite
55-
println(Gameboi.shardManager.shards.first().getInviteUrl(
50+
println(
51+
Gameboi.shardManager.shards.first().getInviteUrl(
5652
Permission.MESSAGE_WRITE,
5753
Permission.MESSAGE_MANAGE,
5854
Permission.MESSAGE_EMBED_LINKS,
5955
Permission.MESSAGE_ATTACH_FILES
60-
))
56+
)
57+
)
6158

6259
if (Gameboi.updateStatus) {
6360
Timer().scheduleAtFixedRate(0L, 30000L) { Gameboi.updatePresence() }
@@ -93,28 +90,28 @@ object Gameboi : EventListener {
9390
}
9491

9592
val commands: List<Command> = listOf(
96-
// Info
97-
HelpCommand,
98-
InviteCommand,
99-
AboutCommand,
100-
PingCommand,
101-
StatsCommand,
102-
// Invites
103-
// Multiplayer
104-
Connect4Invite,
105-
FightInvite,
106-
// Singleplayer
107-
Twenty48Invite,
108-
HangmanInvite,
109-
// Match commands
110-
QuitCommand,
111-
// Shop commands
112-
ShopCommand,
113-
BuyCommand,
114-
InventoryCommand,
115-
EquipCommand,
116-
// Settings commands
117-
SetPrefixCommand
93+
// Info
94+
HelpCommand,
95+
InviteCommand,
96+
AboutCommand,
97+
PingCommand,
98+
StatsCommand,
99+
// Invites
100+
// Multiplayer
101+
Connect4Invite,
102+
FightInvite,
103+
// Singleplayer
104+
Twenty48Invite,
105+
HangmanInvite,
106+
// Match commands
107+
QuitCommand,
108+
// Shop commands
109+
ShopCommand,
110+
BuyCommand,
111+
InventoryCommand,
112+
EquipCommand,
113+
// Settings commands
114+
SetPrefixCommand
118115
)
119116

120117
override fun onEvent(event: GenericEvent) {
@@ -131,10 +128,10 @@ object Gameboi : EventListener {
131128
}
132129

133130
val prefixes = listOfNotNull(
134-
taggedBotRole?.asMention,
135-
"<@${event.jda.selfUser.id}>",
136-
"<@!${event.jda.selfUser.id}>",
137-
guildSettings.realPrefix
131+
taggedBotRole?.asMention,
132+
"<@${event.jda.selfUser.id}>",
133+
"<@!${event.jda.selfUser.id}>",
134+
guildSettings.realPrefix
138135
)
139136

140137
val remainder = prefixes.find {
@@ -151,15 +148,20 @@ object Gameboi : EventListener {
151148
if (command != null) {
152149
command.handle(event, args)
153150
} else {
154-
MatchManager[event.author]?.run { game.handleMessage(Player[event.author], this, event.message) }
151+
MatchManager[event.author]?.run {
152+
game.handleMessage(Player[event.author], this, event.message)
153+
}
155154
}
156155
}
157156
}
158157
}
159158

160159
fun updatePresence() {
161-
shardManager.setPresence(OnlineStatus.ONLINE, Activity.watching(
160+
shardManager.setPresence(
161+
OnlineStatus.ONLINE,
162+
Activity.watching(
162163
"over ${shardManager.guilds.size} guilds | ${prefix}help"
163-
))
164+
)
165+
)
164166
}
165167
}

src/main/kotlin/dev/rayzr/gameboi/command/InfoCommands.kt

+21-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object HelpCommand : Command("help", "Shows you help for Gameboi", category = Ca
1414
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
1515
GuildSettingsManager.getGuildSettingsFor(event.guild).thenAccept { guildSettings ->
1616
val commands = Gameboi.commands.groupBy { it.category }
17-
.toSortedMap(Comparator.comparingInt { it.priority })
17+
.toSortedMap(Comparator.comparingInt { it.priority })
1818

1919
val embed = EmbedBuilder().run {
2020
setDescription(commands.map { category ->
@@ -24,7 +24,11 @@ object HelpCommand : Command("help", "Shows you help for Gameboi", category = Ca
2424

2525
"> __**${category.key.name}**__\n\n $categoryCommands"
2626
}.joinToString("\n\n"))
27-
setAuthor("Gameboi Help Commands", "https://github.com/RayzrDev/Gameboi", event.jda.selfUser.effectiveAvatarUrl)
27+
setAuthor(
28+
"Gameboi Help Commands",
29+
"https://github.com/RayzrDev/Gameboi",
30+
event.jda.selfUser.effectiveAvatarUrl
31+
)
2832
setColor(0x353940)
2933
build()
3034
}
@@ -53,21 +57,28 @@ object AboutCommand : Command("about", "Shows you more information about Gameboi
5357
val embed = EmbedBuilder().run {
5458
setTitle("What is Gameboi?")
5559

56-
setDescription("""
60+
setDescription(
61+
"""
5762
**Gameboi** is a simple Discord bot made for Discord Hack Week 2019 with a plethora of small games you can play, a charming and nostalgic pixel art style, and a global currency and rewards system!
5863
5964
With **2 multiplayer** games (Fight & Connect 4) and **2 singleplayer** games (Hangman & 2048), Gameboi is sure to liven up any server, and the charm of its retro pixel-art graphics feels right at home to any old-school gamer.
6065
6166
:tada: Click [here](${event.jda.getInviteUrl(Permission.MESSAGE_MANAGE)}) to add **Gameboi** to your server!
6267
:link: Click [here](https://github.com/RayzrDev/Gameboi) to check out the source code for **Gameboi**!
6368
:heart: Click [here](https://patreon.com/Rayzr522) if you want to support **Gameboi** and its creators!
64-
""".trimIndent())
69+
""".trimIndent()
70+
)
6571

6672
addField("Servers", "%,d".format(Gameboi.shardManager.guilds.size), true)
6773
addField("Users", "%,d".format(Gameboi.shardManager.users.size), true)
6874

6975
val shardInfo = event.jda.shardInfo
70-
setFooter("Created by Rayzr522#9429 and zp4rker#3333 || Shard %d/%d".format(shardInfo.shardId + 1, shardInfo.shardTotal))
76+
setFooter(
77+
"Created by Rayzr522#9429 and zp4rker#3333 || Shard %d/%d".format(
78+
shardInfo.shardId + 1,
79+
shardInfo.shardTotal
80+
)
81+
)
7182

7283
setImage("https://raw.githubusercontent.com/RayzrDev/Gameboi/master/res/banner.png")
7384

@@ -122,7 +133,11 @@ object StatsCommand : Command("stats", "Shows your game stats", "stats [game]",
122133
addStat(this, data, "Total Guesses", "hangman.total-guesses")
123134
addStat(this, data, "Correct Guesses", "hangman.correct-guesses")
124135
// TODO: Method for computed stats?
125-
addField("Accuracy", "${((data.getStat("hangman.correct-guesses") * 100.0) / data.getStat("hangman.total-guesses")).roundToInt()}%", true)
136+
addField(
137+
"Accuracy",
138+
"${((data.getStat("hangman.correct-guesses") * 100.0) / data.getStat("hangman.total-guesses")).roundToInt()}%",
139+
true
140+
)
126141
addStat(this, data, "Wins", "hangman.wins")
127142
}
128143
"2048" -> {

src/main/kotlin/dev/rayzr/gameboi/command/InviteCommands.kt

+17-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ fun checkPermissions(event: GuildMessageReceivedEvent): Boolean {
1818
return false
1919
}
2020

21-
if (!event.guild.selfMember.hasPermission(event.channel, Permission.MESSAGE_MANAGE, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS)) {
22-
event.channel.sendMessage(":x: This bot is missing the permissions required to manage/delete messages, attach images, and embed links!").queue()
21+
if (!event.guild.selfMember.hasPermission(
22+
event.channel,
23+
Permission.MESSAGE_MANAGE,
24+
Permission.MESSAGE_ATTACH_FILES,
25+
Permission.MESSAGE_EMBED_LINKS
26+
)
27+
) {
28+
event.channel.sendMessage(":x: This bot is missing the permissions required to manage/delete messages, attach images, and embed links!")
29+
.queue()
2330
return false
2431
}
2532

@@ -28,15 +35,17 @@ fun checkPermissions(event: GuildMessageReceivedEvent): Boolean {
2835

2936
fun checkValidPlayer(player: User) = !player.isBot
3037

31-
object Connect4Invite : Command("connect4", "Invites a player to play Connect4 with you!", "connect4 <other>", Categories.GAMES) {
38+
object Connect4Invite :
39+
Command("connect4", "Invites a player to play Connect4 with you!", "connect4 <other>", Categories.GAMES) {
3240
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
3341
if (!checkPermissions(event)) {
3442
return
3543
}
3644

3745
if (event.message.mentionedMembers.size < 1) {
3846
event.channel.sendMessage(":x: Please mention the user you would like to play with!").queue {
39-
it.textChannel.deleteMessages(listOf(it, event.message)).queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
47+
it.textChannel.deleteMessages(listOf(it, event.message))
48+
.queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
4049
}
4150
return
4251
}
@@ -60,7 +69,8 @@ object FightInvite : Command("fight", "Invites a player to play Fight with you!"
6069

6170
if (event.message.mentionedMembers.size < 1) {
6271
event.channel.sendMessage(":x: Please mention the user you would like to play with!").queue {
63-
it.textChannel.deleteMessages(listOf(it, event.message)).queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
72+
it.textChannel.deleteMessages(listOf(it, event.message))
73+
.queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
6474
}
6575
return
6676
}
@@ -76,7 +86,7 @@ object FightInvite : Command("fight", "Invites a player to play Fight with you!"
7686
}
7787
}
7888

79-
object Twenty48Invite: Command("2048", "Starts a 2048 game.", "2048", Categories.GAMES) {
89+
object Twenty48Invite : Command("2048", "Starts a 2048 game.", "2048", Categories.GAMES) {
8090
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
8191
if (!checkPermissions(event)) {
8292
return
@@ -86,7 +96,7 @@ object Twenty48Invite: Command("2048", "Starts a 2048 game.", "2048", Categories
8696
}
8797
}
8898

89-
object HangmanInvite: Command("hangman", "Starts a hangman game.", "hangman", Categories.GAMES) {
99+
object HangmanInvite : Command("hangman", "Starts a hangman game.", "hangman", Categories.GAMES) {
90100
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
91101
if (!checkPermissions(event)) {
92102
return

src/main/kotlin/dev/rayzr/gameboi/command/MatchCommands.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ object QuitCommand : Command("quit", "Quits you from your current match", catego
1111

1212
if (player.currentMatch == null) {
1313
event.channel.sendMessage(":x: You are not in a match currently!").queue {
14-
it.textChannel.deleteMessages(listOf(it, event.message)).queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
14+
it.textChannel.deleteMessages(listOf(it, event.message))
15+
.queueAfter(Gameboi.errorLife, TimeUnit.MILLISECONDS)
1516
}
1617
} else {
1718
player.currentMatch?.end()

src/main/kotlin/dev/rayzr/gameboi/command/SettingsCommands.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import dev.rayzr.gameboi.data.settings.GuildSettingsManager
44
import net.dv8tion.jda.api.Permission
55
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent
66

7-
object SetPrefixCommand : Command("setprefix", "Allows you to change Gameboi's prefix", "setprefix [new prefix]", Categories.SETTINGS) {
7+
object SetPrefixCommand :
8+
Command("setprefix", "Allows you to change Gameboi's prefix", "setprefix [new prefix]", Categories.SETTINGS) {
89
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
910
if (!event.member!!.hasPermission(Permission.MANAGE_SERVER)) {
1011
return fail(event, "Only admins (those with the **Manage Server** permission) can edit this!")
@@ -13,7 +14,8 @@ object SetPrefixCommand : Command("setprefix", "Allows you to change Gameboi's p
1314
GuildSettingsManager.editGuildSettings(event.guild) {
1415
if (args.isEmpty() || args[0].toLowerCase() == "none") {
1516
prefix = null
16-
event.channel.sendMessage(":white_check_mark: Removed custom prefix, you are now using the default `$realPrefix` prefix.").queue()
17+
event.channel.sendMessage(":white_check_mark: Removed custom prefix, you are now using the default `$realPrefix` prefix.")
18+
.queue()
1719
} else {
1820
prefix = args[0]
1921
event.channel.sendMessage(":white_check_mark: Updated prefix to `$prefix`!").queue()

src/main/kotlin/dev/rayzr/gameboi/command/ShopCommands.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import dev.rayzr.gameboi.data.shop.ShopRegistry
44
import dev.rayzr.gameboi.game.Player
55
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent
66

7-
object ShopCommand : Command("shop", "Lets you see what is available for purchase in the shop", category = Categories.SHOP) {
7+
object ShopCommand :
8+
Command("shop", "Lets you see what is available for purchase in the shop", category = Categories.SHOP) {
89
override fun handle(event: GuildMessageReceivedEvent, args: List<String>) {
910
val items = ShopRegistry.items.joinToString("\n\n") {
1011
"[__${it.slot.name}__] **${it.name}** (${it.cost} coins)"
@@ -59,7 +60,7 @@ object InventoryCommand : Command("inventory", "Shows you what items you current
5960
val items = when {
6061
it.inventory.isEmpty() -> "**You have no items.**"
6162
else -> "**Your items:**\n${
62-
it.inventory.map { item -> "- **${item.key.name}**x${item.value}" }.joinToString("\n")
63+
it.inventory.map { item -> "- **${item.key.name}**x${item.value}" }.joinToString("\n")
6364
}"
6465
}
6566

@@ -85,23 +86,26 @@ object EquipCommand : Command("equip", "Lets you equip different items", "equip
8586
if (availableItems.isEmpty()) {
8687
return@editData fail(event, "You don't have any items available for this slot.")
8788
} else {
88-
event.channel.sendMessage("**Available items:**\n${availableItems.joinToString("\n") { "- ${it.name}" }}").queue()
89+
event.channel.sendMessage("**Available items:**\n${availableItems.joinToString("\n") { "- ${it.name}" }}")
90+
.queue()
8991
return@editData
9092
}
9193
}
9294

9395
val itemName = args.subList(1, args.size).joinToString(" ").toLowerCase()
9496
if (itemName == "none") {
9597
equipment.remove(slot.internalName)
96-
event.channel.sendMessage(":white_check_mark: Removed all items from your **${slot.name}** slot.").queue()
98+
event.channel.sendMessage(":white_check_mark: Removed all items from your **${slot.name}** slot.")
99+
.queue()
97100
return@editData
98101
}
99102

100103
val item = inventory.keys.find { it.name.toLowerCase() == itemName }
101-
?: return@editData fail(event, "That is not a valid item!")
104+
?: return@editData fail(event, "That is not a valid item!")
102105

103106
equipment[slot.internalName] = item
104-
event.channel.sendMessage(":white_check_mark: Equipped **${item.name}** to your **${slot.name}** slot.").queue()
107+
event.channel.sendMessage(":white_check_mark: Equipped **${item.name}** to your **${slot.name}** slot.")
108+
.queue()
105109
}
106110
}
107111
}

0 commit comments

Comments
 (0)