Skip to content

Commit 21c5f73

Browse files
authored
Merge pull request #79 from the-programmers-hangout/feat/join-leave-refactor
feat: updates for join leave refactor & migration
2 parents cbebca5 + 844c08e commit 21c5f73

25 files changed

+451
-255
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repositories {
1818

1919
dependencies {
2020
implementation("me.jakejmattson:DiscordKt:${Versions.DISCORDKT}")
21-
implementation("org.litote.kmongo:kmongo-coroutine:4.1.3")
21+
implementation("org.litote.kmongo:kmongo-coroutine:4.2.6")
2222
implementation("joda-time:joda-time:2.10.6")
2323
}
2424

commands.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
| ----------- | ------------------------------ |
66
| (Argument) | Argument is not required. |
77

8-
## Configuration
9-
| Commands | Arguments | Description |
10-
| ------------- | ------------- | -------------------------------------------------------------- |
11-
| configuration | (GuildConfig) | Update configuration parameters for this guild (conversation). |
12-
| setup | | Configure a guild to use Judgebot. |
8+
## Guild
9+
| Commands | Arguments | Description |
10+
| ----------------- | ------------- | -------------------------------------------------------------- |
11+
| activePunishments | | View active punishments for a guild. |
12+
| configuration | (GuildConfig) | Update configuration parameters for this guild (conversation). |
13+
| setup | | Configure a guild to use Judgebot. |
1314

1415
## Information
1516
| Commands | Arguments | Description |
@@ -21,8 +22,8 @@
2122
| Commands | Arguments | Description |
2223
| ---------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
2324
| badpfp | (cancel), LowerMemberArg | Notifies the user that they should change their profile pic and applies a 30 minute mute. Bans the user if they don't change picture. |
24-
| cleanse | LowerMemberArg | Use this to delete (permanently) as user's infractions. |
25-
| removeInfraction | LowerMemberArg, Infraction ID | Use this to delete (permanently) an infraction from a user. |
25+
| cleanse | LowerUserArg | Use this to delete (permanently) as user's infractions. |
26+
| removeInfraction | LowerUserArg, Infraction ID | Use this to delete (permanently) an infraction from a user. |
2627
| strike, s, S | LowerMemberArg, (Weight), Reason | Strike a user. |
2728
| warn, w, W | LowerMemberArg, Reason | Warn a user. |
2829

src/main/kotlin/me/ddivad/judgebot/Main.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import com.gitlab.kordlib.gateway.Intent
44
import com.gitlab.kordlib.gateway.PrivilegedIntent
55
import me.ddivad.judgebot.dataclasses.Configuration
66
import me.ddivad.judgebot.services.BotStatsService
7-
import me.ddivad.judgebot.services.LoggingService
87
import me.ddivad.judgebot.services.infractions.MuteService
98
import me.ddivad.judgebot.services.PermissionsService
109
import me.ddivad.judgebot.services.infractions.BanService
10+
import me.ddivad.judgebot.services.migrations.JoinLeaveMigration
1111
import me.ddivad.judgebot.services.requiredPermissionLevel
1212
import me.jakejmattson.discordkt.api.dsl.bot
1313
import me.jakejmattson.discordkt.api.extensions.addInlineField
@@ -58,7 +58,7 @@ suspend fun main(args: Array<String>) {
5858
field {
5959
name = "Build Info"
6060
value = "```" +
61-
"Version: 1.8.2\n" +
61+
"Version: 2.0.0\n" +
6262
"DiscordKt: ${versions.library}\n" +
6363
"Kotlin: $kotlinVersion" +
6464
"```"
@@ -83,9 +83,14 @@ suspend fun main(args: Array<String>) {
8383
}
8484

8585
onStart {
86-
val (muteService, banService, loggingService) = this.getInjectionObjects(MuteService::class, BanService::class, LoggingService::class)
86+
val (muteService, banService, joinLeaveMigration) = this.getInjectionObjects(
87+
MuteService::class,
88+
BanService::class,
89+
JoinLeaveMigration::class
90+
)
8791
muteService.initGuilds()
8892
banService.initialiseBanTimers()
93+
joinLeaveMigration.run()
8994
}
9095

9196
intents {

src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argume
3131

3232
suspend fun Member.isHigherRankedThan(permissions: PermissionsService, targetMember: Member) =
3333
permissions.getPermissionRank(this) < permissions.getPermissionRank(targetMember)
34-

src/main/kotlin/me/ddivad/judgebot/commands/GuildConfigCommands.kt renamed to src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import me.ddivad.judgebot.arguments.GuildConfigArg
44
import me.ddivad.judgebot.conversations.guild.GuildSetupConversation
55
import me.ddivad.judgebot.conversations.guild.EditConfigConversation
66
import me.ddivad.judgebot.dataclasses.Configuration
7+
import me.ddivad.judgebot.embeds.createActivePunishmentsEmbed
78
import me.ddivad.judgebot.services.DatabaseService
89
import me.ddivad.judgebot.services.infractions.MuteService
910
import me.ddivad.judgebot.services.PermissionLevel
@@ -12,7 +13,7 @@ import me.jakejmattson.discordkt.api.dsl.commands
1213

1314
fun guildConfigCommands(configuration: Configuration,
1415
databaseService: DatabaseService,
15-
muteService: MuteService) = commands("Configuration") {
16+
muteService: MuteService) = commands("Guild") {
1617
guildCommand("setup") {
1718
description = "Configure a guild to use Judgebot."
1819
requiredPermissionLevel = PermissionLevel.Administrator
@@ -42,4 +43,17 @@ fun guildConfigCommands(configuration: Configuration,
4243
.startPublicly(discord, author, channel)
4344
}
4445
}
46+
47+
guildCommand("activePunishments") {
48+
description = "View active punishments for a guild."
49+
requiredPermissionLevel = PermissionLevel.Staff
50+
execute {
51+
val punishments = databaseService.guilds.getActivePunishments(guild)
52+
if (punishments.isEmpty()) {
53+
respond("No active punishments found.")
54+
return@execute
55+
}
56+
respond { createActivePunishmentsEmbed(guild, punishments) }
57+
}
58+
}
4559
}

src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fun createUserCommands(databaseService: DatabaseService,
3434
}
3535
}
3636

37-
guildCommand("listAlts", "alts") {
37+
guildCommand("alts") {
3838
description = "Use this to view a user's alt accounts."
3939
requiredPermissionLevel = PermissionLevel.Moderator
4040
execute(UserArg) {

src/main/kotlin/me/ddivad/judgebot/dataclasses/Configuration.kt

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,33 @@ import com.gitlab.kordlib.core.entity.Role
55
import me.jakejmattson.discordkt.api.dsl.Data
66

77
data class Configuration(
8-
val ownerId: String = "insert-owner-id",
9-
var prefix: String = "judge!",
10-
val guildConfigurations: MutableMap<Long, GuildConfiguration> = mutableMapOf(),
11-
val dbConfiguration: DatabaseConfiguration = DatabaseConfiguration()
8+
val ownerId: String = "insert-owner-id",
9+
var prefix: String = "judge!",
10+
val guildConfigurations: MutableMap<Long, GuildConfiguration> = mutableMapOf(),
11+
val dbConfiguration: DatabaseConfiguration = DatabaseConfiguration()
1212
) : Data("config/config.json") {
1313
operator fun get(id: Long) = guildConfigurations[id]
1414
fun hasGuildConfig(guildId: Long) = guildConfigurations.containsKey(guildId)
1515

16-
fun setup(guild: Guild, prefix: String, adminRole: Role, staffRole: Role, moderatorRole: Role, mutedRole: Role, logging: LoggingConfiguration) {
16+
fun setup(
17+
guild: Guild,
18+
prefix: String,
19+
adminRole: Role,
20+
staffRole: Role,
21+
moderatorRole: Role,
22+
mutedRole: Role,
23+
logging: LoggingConfiguration
24+
) {
1725
if (guildConfigurations[guild.id.longValue] != null) return
1826

1927
val newConfiguration = GuildConfiguration(
20-
guild.id.value,
21-
prefix,
22-
mutableListOf(moderatorRole.id.value),
23-
mutableListOf(staffRole.id.value),
24-
mutableListOf(adminRole.id.value),
25-
mutedRole.id.value,
26-
logging
28+
guild.id.value,
29+
prefix,
30+
mutableListOf(moderatorRole.id.value),
31+
mutableListOf(staffRole.id.value),
32+
mutableListOf(adminRole.id.value),
33+
mutedRole.id.value,
34+
logging
2735
)
2836

2937
// Setup default punishments
@@ -41,48 +49,48 @@ data class Configuration(
4149
}
4250

4351
data class DatabaseConfiguration(
44-
val address: String = "mongodb://localhost:27017",
45-
val databaseName: String = "judgebot"
52+
val address: String = "mongodb://localhost:27017",
53+
val databaseName: String = "judgebot"
4654
)
4755

4856
data class GuildConfiguration(
49-
val id: String = "",
50-
var prefix: String = "j!",
51-
var moderatorRoles: MutableList<String> = mutableListOf(),
52-
var staffRoles: MutableList<String> = mutableListOf(),
53-
var adminRoles: MutableList<String> = mutableListOf(),
54-
var mutedRole: String = "",
55-
var loggingConfiguration: LoggingConfiguration = LoggingConfiguration(),
56-
var infractionConfiguration: InfractionConfiguration = InfractionConfiguration(),
57-
var punishments: MutableList<PunishmentLevel> = mutableListOf(),
58-
var reactions: ReactionConfiguration = ReactionConfiguration()
57+
val id: String = "",
58+
var prefix: String = "j!",
59+
var moderatorRoles: MutableList<String> = mutableListOf(),
60+
var staffRoles: MutableList<String> = mutableListOf(),
61+
var adminRoles: MutableList<String> = mutableListOf(),
62+
var mutedRole: String = "",
63+
var loggingConfiguration: LoggingConfiguration = LoggingConfiguration(),
64+
var infractionConfiguration: InfractionConfiguration = InfractionConfiguration(),
65+
var punishments: MutableList<PunishmentLevel> = mutableListOf(),
66+
var reactions: ReactionConfiguration = ReactionConfiguration()
5967
)
6068

6169
data class LoggingConfiguration(
62-
var alertChannel: String = "",
63-
var loggingChannel: String = "insert_id",
64-
var logRoles: Boolean = true,
65-
var logInfractions: Boolean = true,
66-
var logPunishments: Boolean = true
70+
var alertChannel: String = "",
71+
var loggingChannel: String = "insert_id",
72+
var logRoles: Boolean = true,
73+
var logInfractions: Boolean = true,
74+
var logPunishments: Boolean = true
6775
)
6876

6977
data class InfractionConfiguration(
70-
var pointCeiling: Int = 50,
71-
var strikePoints: Int = 10,
72-
var warnPoints: Int = 0,
73-
var pointDecayPerWeek: Int = 2,
78+
var pointCeiling: Int = 50,
79+
var strikePoints: Int = 10,
80+
var warnPoints: Int = 0,
81+
var pointDecayPerWeek: Int = 2,
7482
)
7583

7684
data class PunishmentLevel(
77-
var points: Int = 0,
78-
var punishment: PunishmentType,
79-
var duration: Long? = null
85+
var points: Int = 0,
86+
var punishment: PunishmentType,
87+
var duration: Long? = null
8088
)
8189

8290
data class ReactionConfiguration(
83-
var enabled: Boolean = true,
84-
var gagReaction: String = "",
85-
var historyReaction: String = "",
86-
var deleteMessageReaction: String = "",
87-
var flagMessageReaction: String = ""
91+
var enabled: Boolean = true,
92+
var gagReaction: String = "",
93+
var historyReaction: String = "",
94+
var deleteMessageReaction: String = "",
95+
var flagMessageReaction: String = ""
8896
)

src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildInformation.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package me.ddivad.judgebot.dataclasses
22

33
data class GuildInformation(
4-
val guildId: String,
5-
val guildName: String,
6-
val rules: MutableList<Rule> = mutableListOf(),
7-
val bans: MutableList<Ban> = mutableListOf(),
8-
val punishments: MutableList<Punishment> = mutableListOf()
4+
val guildId: String,
5+
val guildName: String,
6+
val rules: MutableList<Rule> = mutableListOf(),
7+
val bans: MutableList<Ban> = mutableListOf(),
8+
val punishments: MutableList<Punishment> = mutableListOf()
99
) {
1010
fun addRule(rule: Rule): GuildInformation = this.apply {
1111
this.rules.add(rule)
@@ -55,9 +55,9 @@ data class GuildInformation(
5555
}
5656

5757
data class Rule(
58-
val number: Int,
59-
val title: String,
60-
val description: String,
61-
val link: String,
62-
var archived: Boolean = false
58+
val number: Int,
59+
val title: String,
60+
val description: String,
61+
val link: String,
62+
var archived: Boolean = false
6363
)

src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildMember.kt

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ import com.gitlab.kordlib.core.entity.Guild
44
import org.joda.time.DateTime
55
import org.joda.time.Weeks
66

7+
data class GuildLeave(
8+
val joinDate: Long,
9+
var leaveDate: Long?
10+
)
11+
712
data class GuildMemberDetails(
8-
val guildId: String,
9-
val notes: MutableList<Note> = mutableListOf(),
10-
val infractions: MutableList<Infraction> = mutableListOf(),
11-
val info: MutableList<Info> = mutableListOf(),
12-
val leaveHistory: MutableList<GuildLeave> = mutableListOf(),
13-
val linkedAccounts: MutableList<String> = mutableListOf(),
14-
var historyCount: Int = 0,
15-
var points: Int = 0,
16-
var pointDecayTimer: Long = DateTime().millis,
17-
var lastInfraction: Long = 0,
18-
val deletedMessageCount: DeletedMessages = DeletedMessages()
13+
val guildId: String,
14+
val notes: MutableList<Note> = mutableListOf(),
15+
val infractions: MutableList<Infraction> = mutableListOf(),
16+
val info: MutableList<Info> = mutableListOf(),
17+
val linkedAccounts: MutableList<String> = mutableListOf(),
18+
var leaveHistory: MutableList<GuildLeave> = mutableListOf(),
19+
var historyCount: Int = 0,
20+
var points: Int = 0,
21+
var pointDecayTimer: Long = DateTime().millis,
22+
var lastInfraction: Long = 0,
23+
val deletedMessageCount: DeletedMessages = DeletedMessages()
1924
)
2025

2126
data class DeletedMessages(
2227
var deleteReaction: Int = 0,
2328
var total: Int = 0
2429
)
2530

26-
data class GuildLeave(
27-
val joinDate: Long?,
28-
var leaveDate: Long?
29-
)
30-
3131
data class GuildMember(
3232
val userId: String,
3333
val guilds: MutableList<GuildMemberDetails> = mutableListOf()
@@ -103,16 +103,6 @@ data class GuildMember(
103103
this.getGuildInfo(guildId).historyCount += 1
104104
}
105105

106-
fun addGuildLeave( guild: Guild, leaveDate: Long) = with(this.getGuildInfo(guild.id.value)) {
107-
this.leaveHistory.find { it.joinDate != null && it.leaveDate == null }?.let {
108-
it.leaveDate = leaveDate
109-
}
110-
}
111-
112-
fun addGuildJoinDate(guild: Guild, joinDate: Long) = with(this.getGuildInfo(guild.id.value)){
113-
this.leaveHistory.add(GuildLeave(joinDate, null))
114-
}
115-
116106
fun addMessageDeleted(guild: Guild, deleteReaction: Boolean) = with(this.getGuildInfo(guild.id.value)) {
117107
this.deletedMessageCount.total++
118108
if (deleteReaction) this.deletedMessageCount.deleteReaction++
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.ddivad.judgebot.dataclasses
2+
3+
data class JoinLeave(
4+
val guildId: String,
5+
val userId: String,
6+
val joinDate: Long,
7+
var leaveDate: Long? = null
8+
)

0 commit comments

Comments
 (0)