105 lines
3.0 KiB
Kotlin
105 lines
3.0 KiB
Kotlin
package nl.voidcorp.dbot
|
|
|
|
import com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory
|
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager
|
|
import com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioSourceManager
|
|
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager
|
|
import net.dv8tion.jda.core.JDA
|
|
import net.dv8tion.jda.core.JDABuilder
|
|
import nl.voidcorp.dbot.commands.*
|
|
import nl.voidcorp.dbot.music.initMusic
|
|
import org.slf4j.LoggerFactory
|
|
|
|
val playerManager = DefaultAudioPlayerManager()
|
|
|
|
|
|
val log = LoggerFactory.getLogger("UnityBot")
|
|
|
|
val commands = mutableListOf<UnityCommand>()
|
|
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
playerManager.registerSourceManager(YoutubeAudioSourceManager(true))
|
|
playerManager.registerSourceManager(SoundCloudAudioSourceManager(true))
|
|
|
|
|
|
commands.addAll(helloCommand, pingCommand, helpCommand, joinRoleCommand, removeRoleCommand)
|
|
|
|
|
|
initMusic()
|
|
initFun()
|
|
initAdmin()
|
|
|
|
|
|
val custom = UnityCommandClient("!")
|
|
custom.addCommands(commands)
|
|
custom.version = "1.5"
|
|
|
|
|
|
bot = JDABuilder(args[0]).addEventListener(custom).addEventListener(nl.voidcorp.dbot.Events)
|
|
.setAudioSendFactory(NativeAudioSendFactory()).build()
|
|
|
|
/*Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
|
custom.shutdown()
|
|
})*/
|
|
}
|
|
|
|
|
|
/*fun tokenStuff(){
|
|
JavalinJson.apply {
|
|
toJsonMapper = object : ToJsonMapper {
|
|
override fun map(obj: Any): String = gson.toJson(obj)
|
|
}
|
|
fromJsonMapper = object : FromJsonMapper {
|
|
override fun <T> map(json: String, targetClass: Class<T>): T = gson.fromJson(json, targetClass)
|
|
}
|
|
}
|
|
|
|
if (!File(".hooks").exists()) {
|
|
log.error("The .hooks file does not exist!")
|
|
log.error("Exiting")
|
|
System.exit(1)
|
|
}
|
|
|
|
val hooks = mutableListOf<WebhookClient>()
|
|
FileReader(".hooks").forEachLine {
|
|
val wh = WebhookClientBuilder(it).build()
|
|
hooks += wh
|
|
}
|
|
|
|
log.info(hooks.toString())
|
|
|
|
val app = Javalin.create().requestLogger { ctx, timeMs ->
|
|
if (ctx.res.status >= 400) {
|
|
log.error("${ctx.method()} ${ctx.path()} -> ${ctx.status()} (${timeMs}ms)")
|
|
} else {
|
|
log.info("${ctx.method()} ${ctx.path()} -> ${ctx.status()} (${timeMs}ms)")
|
|
}
|
|
}.disableStartupBanner().start(4466)
|
|
|
|
app.post("/gitlab.json") { ctx ->
|
|
val bod = ctx.validatedBody<GitlabWebhook>()
|
|
if (bod.value != null) {
|
|
bod.value!!.apply {
|
|
val embed = EmbedBuilder()
|
|
embed.setTitle(project.name, project.web_url)
|
|
val builder = embed.descriptionBuilder
|
|
var url = ""
|
|
commits.forEach {
|
|
builder.append("${it.message} (${it.timestamp})")
|
|
url = it.url
|
|
}
|
|
embed.setAuthor("$user_name ($user_username)", url, user_avatar)
|
|
hooks.forEach { it.send(embed.build()) }
|
|
}
|
|
}
|
|
ctx.status(200).result("OK")
|
|
}
|
|
|
|
|
|
}*/
|
|
|
|
lateinit var bot: JDA
|
|
|