Skip to content

Commit 408afe6

Browse files
committed
Set us up
1 parent 05a26c2 commit 408afe6

File tree

12 files changed

+226
-132
lines changed

12 files changed

+226
-132
lines changed

build.gradle.kts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
33
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44

55
plugins {
6-
id("fabric-loom") version "1.8-SNAPSHOT"
6+
id("fabric-loom") version "1.10-SNAPSHOT"
77
id("maven-publish")
8-
id("org.jetbrains.kotlin.jvm") version "2.0.21"
9-
id("dev.kordex.gradle.kordex") version "1.4.2"
8+
id("org.jetbrains.kotlin.jvm") version "2.1.21"
9+
id("dev.kordex.gradle.kordex") version "1.6.1"
1010
}
1111

1212
version = property("mod_version").toString()
@@ -47,16 +47,15 @@ dependencies {
4747
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}")
4848
modImplementation("net.fabricmc:fabric-language-kotlin:${property("fabric_kotlin_version")}")
4949

50-
modImplementation("xd.arkosammy:monkeyconfig:${property("monkey_config_version")}")
51-
50+
// Monkey Config
51+
include(implementation("io.github.arkosammy12:monkey-config:${property("monkey_config_version")}")!!)
5252
}
5353

5454
kordEx {
5555
jvmTarget = 21
5656
bot {
5757
dataCollection(DataCollection.Standard)
58-
59-
mainClass = "xd.arkosammy.compsmpdiscordbot.CompSMPDiscordBot"
58+
mainClass = "io.github.arkosammy12.compsmpdiscordbot.CompSMPDiscordBot"
6059
}
6160
}
6261

gradle.properties

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.1
8-
yarn_mappings=1.21.1+build.3
9-
loader_version=0.16.7
10-
fabric_kotlin_version=1.12.3+kotlin.2.0.21
7+
minecraft_version=1.21.5
8+
yarn_mappings=1.21.5+build.1
9+
loader_version=0.16.14
10+
loom_version=1.10-SNAPSHOT
11+
fabric_kotlin_version=1.13.3+kotlin.2.1.21
12+
13+
# Fabric API
14+
fabric_version=0.126.0+1.21.5
1115

1216
# Mod Properties
1317
mod_version=1.0.0
14-
maven_group=xd.arkosammy
15-
archives_base_name=compsmp-discord-bot
18+
maven_group=io.github.arkosammy12
19+
archives_base_name=compsmpdiscordbot
1620

1721
# Dependencies
18-
fabric_version=0.106.0+1.21.1
19-
20-
# Monkey Config
21-
monkey_config_version=0.1.2+1.21
22+
monkey_config_version=1.0.5

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ pluginManagement {
33
mavenCentral()
44
gradlePluginPortal()
55
maven("https://maven.fabricmc.net/") { name = "Fabric" }
6+
maven("https://snapshots-repo.kordex.dev")
7+
maven("https://releases-repo.kordex.dev")
68
}
79
}

src/main/java/xd/arkosammy/compsmpdiscordbot/mixin/ExampleMixin.java renamed to src/main/java/io/github/arkosammy12/compsmpdiscordbot/mixin/ExampleMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package xd.arkosammy.compsmpdiscordbot.mixin;
1+
package io.github.arkosammy12.compsmpdiscordbot.mixin;
22

33
import net.minecraft.server.MinecraftServer;
44
import org.spongepowered.asm.mixin.Mixin;
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package io.github.arkosammy12.compsmpdiscordbot
2+
3+
import dev.kord.common.entity.Snowflake
4+
import dev.kord.core.entity.Member
5+
import dev.kord.core.entity.ReactionEmoji
6+
import dev.kord.core.event.message.MessageCreateEvent
7+
import dev.kord.core.event.message.ReactionAddEvent
8+
import dev.kord.core.event.message.ReactionRemoveEvent
9+
import dev.kordex.core.ExtensibleBot
10+
import kotlinx.coroutines.flow.filter
11+
import kotlinx.coroutines.runBlocking
12+
import net.fabricmc.api.ModInitializer
13+
import org.slf4j.LoggerFactory
14+
15+
object CompSMPDiscordBot : ModInitializer {
16+
17+
const val MOD_ID: String = "compsmpdiscordbot"
18+
val LOGGER = LoggerFactory.getLogger(MOD_ID)
19+
20+
override fun onInitialize() {
21+
22+
runBlocking {
23+
24+
setupBot()
25+
26+
}
27+
28+
29+
}
30+
suspend fun setupBot() {
31+
/*
32+
val guildIdNum: Long = CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.GUILD_ID.settingLocation)
33+
val guildSnowFlake: Snowflake = Snowflake(guildIdNum)
34+
val token: String = CONFIG_MANAGER.getSettingValue<String, StringSetting>(ConfigSettings.BOT_TOKEN.settingLocation)
35+
val bot: ExtensibleBot = ExtensibleBot(token) {
36+
chatCommands {
37+
defaultPrefix = "?"
38+
enabled = true
39+
40+
prefix { default ->
41+
42+
if (guildId == guildSnowFlake) {
43+
// For the test server, we use ! as the command prefix
44+
"!"
45+
} else {
46+
// For other servers, we use the configured default prefix
47+
default
48+
}
49+
}
50+
}
51+
52+
extensions {
53+
add(::TestExtension)
54+
}
55+
56+
}
57+
bot.on<MessageCreateEvent> {
58+
// ignore other bots, even ourselves. We only serve humans here!
59+
if (message.author?.isBot != false) return@on
60+
61+
// check if our command is being invoked
62+
if (message.content != "!ping") return@on
63+
64+
// all clear, give them the pong!
65+
message.channel.createMessage("pong!")
66+
67+
}
68+
69+
bot.on<ReactionAddEvent> {
70+
71+
println("Testing reacting add event")
72+
73+
val reactionEmoji: ReactionEmoji = this.emoji
74+
if (reactionEmoji !is ReactionEmoji.Custom) {
75+
return@on
76+
}
77+
78+
// Check if the reactor is an admin
79+
val reactor: Member = this.user.asMember(guildSnowFlake)
80+
val roles: Set<Snowflake> = reactor.roleIds
81+
val adminRoleId: Long =
82+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.ADMIN_ROLE_ID.settingLocation)
83+
if (!roles.any { roleId -> roleId.value.toLong() == adminRoleId }) {
84+
return@on
85+
}
86+
87+
// Check if the message is in the applications channel
88+
val applicationChannelId: Long =
89+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_CHANNEL_ID.settingLocation)
90+
if (this.message.channelId.value.toLong() != applicationChannelId) {
91+
return@on
92+
}
93+
94+
// Check if the reacted emoji is the approved emoji
95+
val approvedEmojiId: Long =
96+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_EMOJI_ID.settingLocation)
97+
if (reactionEmoji.id.value.toLong() != approvedEmojiId) {
98+
return@on
99+
}
100+
101+
val applicant: Member = this.messageAuthor?.asMember(guildSnowFlake) ?: return@on
102+
val approvalRoleId: Long = CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_ROLE_ID.settingLocation)
103+
104+
CompSMPDiscordBot.LOGGER.info("Giving approval role to user: ${applicant.nickname}")
105+
applicant.addRole(Snowflake(approvalRoleId))
106+
}
107+
108+
bot.on<ReactionRemoveEvent> {
109+
println("Testing reaction remove event")
110+
111+
val reactionEmoji: ReactionEmoji = this.emoji
112+
if (reactionEmoji !is ReactionEmoji.Custom) {
113+
return@on
114+
}
115+
116+
val reactor: Member = this.user.asMember(guildSnowFlake)
117+
val roles: Set<Snowflake> = reactor.roleIds
118+
val adminRoleId: Long =
119+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.ADMIN_ROLE_ID.settingLocation)
120+
if (!roles.any { roleId -> roleId.value.toLong() == adminRoleId }) {
121+
return@on
122+
}
123+
124+
val applicationChannelId: Long =
125+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_CHANNEL_ID.settingLocation)
126+
if (this.message.channelId.value.toLong() != applicationChannelId) {
127+
return@on
128+
}
129+
130+
val approvedEmojiId: Long =
131+
CompSMPDiscordBot.CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_EMOJI_ID.settingLocation)
132+
if (reactionEmoji.id.value.toLong() != approvedEmojiId) {
133+
return@on
134+
}
135+
136+
val applicant = this.message.asMessage().author?.asMember(guildSnowFlake) ?: return@on
137+
val applicantRoles: Set<Snowflake> = applicant.roleIds
138+
val approvalRoleId: Long = CONFIG_MANAGER.getSettingValue<Long, NumberSetting<Long>>(ConfigSettings.APPROVAL_ROLE_ID.settingLocation)
139+
val hasApprovedRole: Boolean = applicantRoles.any { role -> role.value.toLong() == approvalRoleId }
140+
141+
if (!hasApprovedRole) return@on
142+
143+
var hasApprovedRoleByOtherAdmin = false
144+
145+
runBlocking<Unit> {
146+
this@on.message.getReactors(ReactionEmoji.Custom(Snowflake(approvedEmojiId), "Approved", false))
147+
.filter { user ->
148+
user.id != this@on.userId
149+
}.collect { user ->
150+
val member = user.asMember(guildSnowFlake)
151+
if (member.roleIds.any { roleId -> roleId.value.toLong() == adminRoleId }) {
152+
hasApprovedRoleByOtherAdmin = true
153+
return@collect
154+
}
155+
}
156+
}
157+
158+
if (!hasApprovedRoleByOtherAdmin) {
159+
applicant.removeRole(Snowflake(approvalRoleId))
160+
}
161+
}
162+
163+
bot.startAsync()
164+
165+
*/
166+
167+
}
168+
}

src/main/kotlin/xd/arkosammy/compsmpdiscordbot/config/ConfigSettings.kt renamed to src/main/kotlin/io/github/arkosammy12/compsmpdiscordbot/config/Reference.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package xd.arkosammy.compsmpdiscordbot.config
1+
package io.github.arkosammy12.compsmpdiscordbot.config
2+
3+
class Reference {
4+
5+
/*
26
3-
import xd.arkosammy.monkeyconfig.settings.ConfigSetting
4-
import xd.arkosammy.monkeyconfig.settings.NumberSetting
5-
import xd.arkosammy.monkeyconfig.settings.StringSetting
6-
import xd.arkosammy.monkeyconfig.util.SettingLocation
77
88
enum class ConfigSettings(private val builder: ConfigSetting.Builder<*, *, *>) {
99
BOT_TOKEN(StringSetting.Builder(SettingLocation(SettingGroups.BOT_SETTINGS.groupName, "token"), defaultValue = "")),
@@ -23,4 +23,24 @@ enum class ConfigSettings(private val builder: ConfigSetting.Builder<*, *, *>) {
2323
2424
}
2525
26+
}
27+
28+
enum class SettingGroups(private val settingGroup: MutableSettingGroup) {
29+
BOT_SETTINGS(DefaultMutableSettingGroup("bot_settings", registerSettingsAsCommands = false)),
30+
AUTO_APPROVAL_SETTINGS(DefaultMutableSettingGroup("auto_approval_settings", registerSettingsAsCommands = false));
31+
32+
val groupName: String
33+
get() = this.settingGroup.name
34+
35+
companion object {
36+
37+
val settingGroups: List<MutableSettingGroup>
38+
get() = entries.map { e -> e.settingGroup }.toList()
39+
40+
}
41+
42+
}
43+
44+
*/
45+
2646
}

src/main/kotlin/xd/arkosammy/compsmpdiscordbot/extensions/TestExtension.kt renamed to src/main/kotlin/io/github/arkosammy12/compsmpdiscordbot/extensions/TestExtension.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package xd.arkosammy.compsmpdiscordbot.extensions
1+
package io.github.arkosammy12.compsmpdiscordbot.extensions
22

33
import dev.kord.common.entity.Snowflake
44
import dev.kordex.core.commands.Arguments
@@ -11,15 +11,14 @@ import dev.kordex.core.extensions.Extension
1111
import dev.kordex.core.extensions.chatCommand
1212
import dev.kordex.core.extensions.publicSlashCommand
1313
import dev.kordex.core.utils.respond
14-
import xd.arkosammy.compsmpdiscordbot.CompSMPDiscordBot
15-
import xd.arkosammy.compsmpdiscordbot.config.ConfigSettings
16-
import xd.arkosammy.monkeyconfig.managers.getSettingValue
17-
import xd.arkosammy.monkeyconfig.settings.NumberSetting
1814

1915
class TestExtension : Extension() {
2016
override val name = "test"
17+
override suspend fun setup() {
18+
TODO("Not yet implemented")
19+
}
2120

22-
21+
/*
2322
override suspend fun setup() {
2423
chatCommand(::SlapArgs) {
2524
name = "slap"
@@ -135,4 +134,6 @@ class TestExtension : Extension() {
135134
description = "What you want to slap with"
136135
}
137136
}
137+
138+
*/
138139
}

0 commit comments

Comments
 (0)