Merge branch 'fix/updates-and-disconnect-log' into 'master'

Update some dependencies, add logging for disconnects

See merge request jdejeu/ottobotv2!18
This commit is contained in:
Julius 2020-03-15 10:27:24 +00:00
commit 5040a2ff73
7 changed files with 31 additions and 56 deletions

View file

@ -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 {

View file

@ -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
}

View file

@ -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
}
}

View file

@ -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`" }}")
}

View file

@ -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
}

View file

@ -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()
}
}

View file

@ -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}")
}
}