Compare commits
No commits in common. "master" and "feat/what" have entirely different histories.
17
build.gradle
17
build.gradle
|
@ -1,11 +1,11 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
|
||||
id 'org.springframework.boot' version '2.3.1.RELEASE'
|
||||
id "io.spring.dependency-management" version "1.0.9.RELEASE"
|
||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.72'
|
||||
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.72'
|
||||
id "org.jetbrains.kotlin.kapt" version "1.3.72"
|
||||
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"
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,8 @@ dependencies {
|
|||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter:5.4.2"
|
||||
|
||||
implementation 'net.dv8tion:JDA:4.2.0_179'
|
||||
implementation 'net.dv8tion:JDA:4.ALPHA.0_88'
|
||||
implementation 'com.sedmelluq:lavaplayer:1.3.17'
|
||||
|
||||
runtimeOnly "com.h2database:h2"
|
||||
|
||||
|
@ -48,6 +49,8 @@ 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 {
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
|
|||
class Loader(listeners: List<ListenerAdapter>, store: ConfigStore) {
|
||||
init {
|
||||
val token = System.getenv("DISCORD_TOKEN") ?: throw RuntimeException("'DISCORD_TOKEN' not set!")
|
||||
val builder = DefaultShardManagerBuilder.createDefault(token)
|
||||
val builder = DefaultShardManagerBuilder(token)
|
||||
|
||||
|
||||
builder.addEventListeners(listeners)
|
||||
|
|
|
@ -14,11 +14,11 @@ class Flex : Command(
|
|||
) {
|
||||
override fun handle(event: CommandMessage): CommandResult {
|
||||
event.message.delete().queue()
|
||||
val control = event.guild!!
|
||||
val control = event.guild!!.controller
|
||||
|
||||
control.createRole().setColor(Color.RED).setName("no idea?").setPermissions(event.guild.selfMember.permissions)
|
||||
.queue {
|
||||
control.addRoleToMember(event.member!!, it).queue()
|
||||
control.addRolesToMember(event.member!!, it).queue()
|
||||
}
|
||||
return CommandResult.SUCCESS
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
}
|
||||
}
|
|
@ -40,9 +40,7 @@ class JoinRoleCommand :
|
|||
}
|
||||
}
|
||||
}
|
||||
roles.forEach {
|
||||
event.guild.addRoleToMember(event.member!!, it).queue()
|
||||
}
|
||||
event.guild.controller.addRolesToMember(event.member!!, roles).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`" }}")
|
||||
}
|
||||
|
|
|
@ -23,10 +23,7 @@ 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
|
||||
remove.forEach {
|
||||
if (it != null)
|
||||
event.guild.removeRoleFromMember(event.member, it).queue()
|
||||
}
|
||||
event.guild.controller.removeRolesFromMember(event.member, remove).queue()
|
||||
event.reply("Removed the roles ${remmed.joinToString { "`$it`" }}")
|
||||
return CommandResult.SUCCESS
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ class MoveRoleCommand : Command(
|
|||
val who = event.guild.members.filter { it.roles.contains(r1) }
|
||||
who.forEach {
|
||||
if (r1 != null)
|
||||
event.guild.removeRoleFromMember(it, r1).reason("Swap roles").queue()
|
||||
event.guild.controller.removeSingleRoleFromMember(it, r1).reason("Swap roles").queue()
|
||||
if (r2 != null) {
|
||||
event.guild.addRoleToMember(it, r2).reason("Swap roles").queue()
|
||||
event.guild.controller.addSingleRoleToMember(it, r2).reason("Swap roles").queue()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,14 @@ import nl.voidcorp.discord.command.CommandResult
|
|||
import nl.voidcorp.discord.command.CommandSettings
|
||||
import nl.voidcorp.discord.creator
|
||||
import nl.voidcorp.discord.logger
|
||||
import nl.voidcorp.discord.storage.GuildRepo
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class CommandListener(
|
||||
@Autowired val commands: Set<Command>,
|
||||
@Autowired val guildRepo: GuildRepo,
|
||||
@Autowired final val commands: Set<Command>,
|
||||
@Autowired val commandSettings: CommandSettings
|
||||
) : ListenerAdapter() {
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
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}")
|
||||
}
|
||||
}
|
70
src/main/kotlin/nl/voidcorp/discord/events/LogListener.kt
Normal file
70
src/main/kotlin/nl/voidcorp/discord/events/LogListener.kt
Normal file
|
@ -0,0 +1,70 @@
|
|||
package nl.voidcorp.discord.events
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||
import nl.voidcorp.discord.jda
|
||||
import nl.voidcorp.discord.storage.GuildRepo
|
||||
import nl.voidcorp.discord.storage.GuildStore
|
||||
import nl.voidcorp.discord.storage.MessageRepo
|
||||
import nl.voidcorp.discord.storage.MessageStore
|
||||
import org.springframework.stereotype.Service
|
||||
import java.awt.Color
|
||||
import java.time.Clock
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Service
|
||||
class LogListener(val repo: GuildRepo, val msg: MessageRepo) : ListenerAdapter() {
|
||||
|
||||
private enum class EventType {
|
||||
EDIT,
|
||||
DELET
|
||||
}
|
||||
|
||||
override fun onGuildMessageReceived(event: GuildMessageReceivedEvent) {
|
||||
msg.save(MessageStore(event.messageIdLong, event.message.contentRaw, event.guild.idLong, event.author.idLong))
|
||||
}
|
||||
|
||||
override fun onGuildMessageUpdate(event: GuildMessageUpdateEvent) {
|
||||
val past = msg.findByMsgId(event.messageIdLong) ?: MessageStore(
|
||||
event.messageIdLong,
|
||||
event.message.contentRaw,
|
||||
event.guild.idLong,
|
||||
event.author.idLong
|
||||
)
|
||||
if (event.message.contentRaw != past.text) {
|
||||
past.past.add(past.text)
|
||||
past.text = event.message.contentRaw
|
||||
}
|
||||
msg.save(past)
|
||||
sendMessageModification(past, EventType.EDIT)
|
||||
}
|
||||
|
||||
override fun onGuildMessageDelete(event: GuildMessageDeleteEvent) {
|
||||
val past =
|
||||
msg.findByMsgId(event.messageIdLong) ?: MessageStore(
|
||||
event.messageIdLong,
|
||||
"~~deleted~~",
|
||||
event.guild.idLong,
|
||||
-1
|
||||
)
|
||||
past.deleted = true
|
||||
msg.save(past)
|
||||
sendMessageModification(past, EventType.DELET)
|
||||
}
|
||||
|
||||
private fun sendMessageModification(st: MessageStore, type: EventType) {
|
||||
val store = repo.findByGuildId(st.guildId) ?: GuildStore(st.guildId)
|
||||
if (store.loggingChannel != null) {
|
||||
val embedBuilder = EmbedBuilder().addField("Message", st.text, false)
|
||||
.addField("Past", st.past.joinToString("\n"), true)
|
||||
.addField("Sender", jda.getUserById(st.authorId)?.asTag ?: "someone#-1", true)
|
||||
.setTitle(type.toString()).setTimestamp(LocalDateTime.now(Clock.systemUTC()))
|
||||
.setColor(if (type == EventType.EDIT) Color.GREEN.brighter() else Color.RED.darker())
|
||||
jda.getTextChannelById(store.loggingChannel ?: -1)?.sendMessage(embedBuilder.build())?.queue()
|
||||
}
|
||||
msg.deleteInBatch(msg.findByNowBefore(LocalDateTime.now().minusDays(2)))
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ class OttoListener(val configStore: ConfigStore) : ListenerAdapter() {
|
|||
}
|
||||
|
||||
override fun onReconnect(event: ReconnectedEvent) {
|
||||
val id = event.jda.shardInfo.shardId
|
||||
val id = event.jda.shardInfo!!.shardId
|
||||
val reconn = event.responseNumber
|
||||
val version = configStore.version
|
||||
if(reconn >=10) exitProcess(0)
|
||||
|
|
Loading…
Reference in a new issue