Remove shadow plugin, it's useless anyways
Make np command more organised and add lööp and stop commands make bot leave channel when it is alone
This commit is contained in:
parent
28dd85db0b
commit
35d314df39
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -124,4 +124,7 @@ gradle-app.setting
|
||||||
# gradle/wrapper/gradle-wrapper.properties
|
# gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/kotlin,gradle,intellij+all
|
# End of https://www.gitignore.io/api/kotlin,gradle,intellij+all
|
||||||
|
|
||||||
|
settings.json
|
||||||
|
/libs/
|
16
build.gradle
16
build.gradle
|
@ -1,7 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
|
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
|
||||||
id 'com.github.johnrengelman.shadow' version '4.0.1'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'nl.voidcorp.dbot'
|
group 'nl.voidcorp.dbot'
|
||||||
|
@ -36,14 +35,13 @@ compileTestKotlin {
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
task copyDependencies(type: Copy) {
|
||||||
baseName = 'UnityBot'
|
delete 'libs'
|
||||||
classifier = null
|
from configurations.compile
|
||||||
version = null
|
into 'libs'
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
|
||||||
attributes 'Main-Class': 'nl.voidcorp.dbot.UnityBotKt'
|
archiveName = "UnityBot.jar"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package nl.voidcorp.dbot
|
package nl.voidcorp.dbot
|
||||||
|
|
||||||
|
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent
|
||||||
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent
|
import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent
|
||||||
import net.dv8tion.jda.core.events.message.react.MessageReactionRemoveEvent
|
import net.dv8tion.jda.core.events.message.react.MessageReactionRemoveEvent
|
||||||
import net.dv8tion.jda.core.hooks.ListenerAdapter
|
import net.dv8tion.jda.core.hooks.ListenerAdapter
|
||||||
|
import nl.voidcorp.dbot.music.guildMusicMap
|
||||||
|
|
||||||
object Events : ListenerAdapter() {
|
object Events : ListenerAdapter() {
|
||||||
override fun onMessageReceived(event: MessageReceivedEvent) {
|
override fun onMessageReceived(event: MessageReceivedEvent) {
|
||||||
|
@ -30,7 +32,12 @@ object Events : ListenerAdapter() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
if (event.author.idLong == 168743656738521088 && event.message.mentionedMembers.contains(event.guild.getMember(event.jda.selfUser))) {
|
if (event.author.idLong == 168743656738521088 && event.message.mentionedMembers.contains(
|
||||||
|
event.guild.getMember(
|
||||||
|
event.jda.selfUser
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
/*if (event.message.contentStripped.contains("hide")) {
|
/*if (event.message.contentStripped.contains("hide")) {
|
||||||
if (event.message.mentionedChannels.isNotEmpty()) {
|
if (event.message.mentionedChannels.isNotEmpty()) {
|
||||||
val override = event.message.mentionedChannels[0].getPermissionOverride(event.guild.getRoleById(499512961103167498))
|
val override = event.message.mentionedChannels[0].getPermissionOverride(event.guild.getRoleById(499512961103167498))
|
||||||
|
@ -69,7 +76,8 @@ object Events : ListenerAdapter() {
|
||||||
|
|
||||||
override fun onMessageReactionAdd(event: MessageReactionAddEvent) {
|
override fun onMessageReactionAdd(event: MessageReactionAddEvent) {
|
||||||
if (event.channel.idLong == 499523462449201162 && event.messageIdLong == 499929881883181064) {
|
if (event.channel.idLong == 499523462449201162 && event.messageIdLong == 499929881883181064) {
|
||||||
event.guild.controller.addSingleRoleToMember(event.member, event.guild.getRoleById(
|
event.guild.controller.addSingleRoleToMember(
|
||||||
|
event.member, event.guild.getRoleById(
|
||||||
when (event.reactionEmote.name) {
|
when (event.reactionEmote.name) {
|
||||||
"\uD83C\uDFB5" -> 499925623188488192
|
"\uD83C\uDFB5" -> 499925623188488192
|
||||||
"\uD83D\uDCBE" -> 499525260912361472
|
"\uD83D\uDCBE" -> 499525260912361472
|
||||||
|
@ -77,13 +85,16 @@ object Events : ListenerAdapter() {
|
||||||
"\uD83C\uDFA8" -> 499525305405276181
|
"\uD83C\uDFA8" -> 499525305405276181
|
||||||
"\uD83D\uDD0D" -> 499525364708540416
|
"\uD83D\uDD0D" -> 499525364708540416
|
||||||
else -> 499938201444810782
|
else -> 499938201444810782
|
||||||
})).queue()
|
}
|
||||||
|
)
|
||||||
|
).queue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessageReactionRemove(event: MessageReactionRemoveEvent) {
|
override fun onMessageReactionRemove(event: MessageReactionRemoveEvent) {
|
||||||
if (event.channel.idLong == 499523462449201162 && event.messageIdLong == 499929881883181064) {
|
if (event.channel.idLong == 499523462449201162 && event.messageIdLong == 499929881883181064) {
|
||||||
event.guild.controller.removeSingleRoleFromMember(event.member, event.guild.getRoleById(
|
event.guild.controller.removeSingleRoleFromMember(
|
||||||
|
event.member, event.guild.getRoleById(
|
||||||
when (event.reactionEmote.name) {
|
when (event.reactionEmote.name) {
|
||||||
"\uD83C\uDFB5" -> 499925623188488192
|
"\uD83C\uDFB5" -> 499925623188488192
|
||||||
"\uD83D\uDCBE" -> 499525260912361472
|
"\uD83D\uDCBE" -> 499525260912361472
|
||||||
|
@ -91,7 +102,15 @@ object Events : ListenerAdapter() {
|
||||||
"\uD83C\uDFA8" -> 499525305405276181
|
"\uD83C\uDFA8" -> 499525305405276181
|
||||||
"\uD83D\uDD0D" -> 499525364708540416
|
"\uD83D\uDD0D" -> 499525364708540416
|
||||||
else -> 499938201444810782
|
else -> 499938201444810782
|
||||||
})).queue()
|
}
|
||||||
|
)
|
||||||
|
).queue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onGuildVoiceLeave(event: GuildVoiceLeaveEvent) {
|
||||||
|
if (event.channelLeft.members.size == 1) {
|
||||||
|
guildMusicMap[event.guild.idLong]?.clearQueue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ fun main(args: Array<String>) {
|
||||||
|
|
||||||
val custom = UnityCommandClient("!")
|
val custom = UnityCommandClient("!")
|
||||||
custom.addCommands(commands)
|
custom.addCommands(commands)
|
||||||
custom.version = "1.4"
|
custom.version = "1.5"
|
||||||
|
|
||||||
|
|
||||||
bot = JDABuilder(args[0]).addEventListener(custom).addEventListener(nl.voidcorp.dbot.Events)
|
bot = JDABuilder(args[0]).addEventListener(custom).addEventListener(nl.voidcorp.dbot.Events)
|
||||||
|
|
|
@ -10,10 +10,7 @@ import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame
|
||||||
import net.dv8tion.jda.core.audio.AudioSendHandler
|
import net.dv8tion.jda.core.audio.AudioSendHandler
|
||||||
import nl.voidcorp.dbot.addAll
|
import nl.voidcorp.dbot.addAll
|
||||||
import nl.voidcorp.dbot.commands
|
import nl.voidcorp.dbot.commands
|
||||||
import nl.voidcorp.dbot.commands.MusicCategoryPrivate
|
import nl.voidcorp.dbot.commands.*
|
||||||
import nl.voidcorp.dbot.commands.UnityCommand
|
|
||||||
import nl.voidcorp.dbot.commands.UnityCommandEvent
|
|
||||||
import nl.voidcorp.dbot.commands.UnityMusicCommand
|
|
||||||
import nl.voidcorp.dbot.log
|
import nl.voidcorp.dbot.log
|
||||||
import nl.voidcorp.dbot.playerManager
|
import nl.voidcorp.dbot.playerManager
|
||||||
|
|
||||||
|
@ -252,6 +249,25 @@ fun initMusic() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val loopCommand =
|
||||||
|
UnityMusicCommand("loop", "Loops the queue!\nOr disables it!", MusicCategory) { event, scheduler ->
|
||||||
|
if (scheduler.loop) {
|
||||||
|
event.reply("The queue will no longer loop!")
|
||||||
|
} else {
|
||||||
|
event.reply("The queue wil now loop")
|
||||||
|
}
|
||||||
|
scheduler.loop = !scheduler.loop
|
||||||
|
}
|
||||||
|
|
||||||
|
val stopCommand = UnityMusicCommand(
|
||||||
|
"stop",
|
||||||
|
"Stops this shit!",
|
||||||
|
MusicCategoryPrivate,
|
||||||
|
aliases = mutableListOf()
|
||||||
|
) { event, scheduler ->
|
||||||
|
scheduler.clearQueue()
|
||||||
|
event.reply("Stopped all playback!")
|
||||||
|
}
|
||||||
|
|
||||||
commands.addAll(
|
commands.addAll(
|
||||||
playCommand,
|
playCommand,
|
||||||
|
@ -261,7 +277,9 @@ fun initMusic() {
|
||||||
soundcloudCommand,
|
soundcloudCommand,
|
||||||
npCommand,
|
npCommand,
|
||||||
attachmentPlay,
|
attachmentPlay,
|
||||||
voteSkipCommand
|
voteSkipCommand,
|
||||||
|
loopCommand,
|
||||||
|
stopCommand
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,8 +301,7 @@ fun getLinkFromSearch(
|
||||||
scheduler.insertFront(track, event.member)
|
scheduler.insertFront(track, event.member)
|
||||||
if (!scheduler.isQueueEmpty())
|
if (!scheduler.isQueueEmpty())
|
||||||
scheduler.skip()
|
scheduler.skip()
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
scheduler.queue(track, event.member)
|
scheduler.queue(track, event.member)
|
||||||
/*event.reply(
|
/*event.reply(
|
||||||
EmbedBuilder().setImage(r.snippet.thumbnails.high.url).setTitle(r.snippet.title, "https://youtu.be/$id")
|
EmbedBuilder().setImage(r.snippet.thumbnails.high.url).setTitle(r.snippet.title, "https://youtu.be/$id")
|
||||||
|
|
|
@ -14,6 +14,7 @@ import nl.voidcorp.dbot.log
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.concurrent.timerTask
|
import kotlin.concurrent.timerTask
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ import kotlin.math.roundToInt
|
||||||
class TrackScheduler(val player: AudioPlayer, val guild: Guild, val voiceChannel: VoiceChannel) : AudioEventAdapter() {
|
class TrackScheduler(val player: AudioPlayer, val guild: Guild, val voiceChannel: VoiceChannel) : AudioEventAdapter() {
|
||||||
val musicChannel: TextChannel
|
val musicChannel: TextChannel
|
||||||
|
|
||||||
|
var loop = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
player.addListener(this)
|
player.addListener(this)
|
||||||
|
|
||||||
|
@ -45,10 +48,16 @@ class TrackScheduler(val player: AudioPlayer, val guild: Guild, val voiceChannel
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
override fun onTrackEnd(player: AudioPlayer, track: AudioTrack, endReason: AudioTrackEndReason) {
|
override fun onTrackEnd(player: AudioPlayer, track: AudioTrack, endReason: AudioTrackEndReason) {
|
||||||
pressedSkip++
|
pressedSkip = 0
|
||||||
if (q.isNotEmpty()) {
|
if (q.isNotEmpty()) {
|
||||||
player.playTrack(q.poll())
|
val t = q.poll()!!
|
||||||
|
if (loop) q.addLast(t.makeClone().apply { userData = t.userData })
|
||||||
|
player.playTrack(t)
|
||||||
} else {
|
} else {
|
||||||
|
if (loop) {
|
||||||
|
player.playTrack(track.makeClone().apply { userData = track.userData })
|
||||||
|
return
|
||||||
|
}
|
||||||
stopPlay(endReason)
|
stopPlay(endReason)
|
||||||
player.destroy()
|
player.destroy()
|
||||||
}
|
}
|
||||||
|
@ -135,52 +144,66 @@ class TrackScheduler(val player: AudioPlayer, val guild: Guild, val voiceChannel
|
||||||
fun getCurrentTrackInfo(): MessageEmbed = getTrackInfo(player.playingTrack)
|
fun getCurrentTrackInfo(): MessageEmbed = getTrackInfo(player.playingTrack)
|
||||||
|
|
||||||
fun getTrackInfo(track: AudioTrack): MessageEmbed {
|
fun getTrackInfo(track: AudioTrack): MessageEmbed {
|
||||||
if (track is YoutubeAudioTrack) {
|
val eb = EmbedBuilder().setTimestamp(LocalDateTime.now())
|
||||||
if (track.userData is Member)
|
if (track.userData is Member) {
|
||||||
return EmbedBuilder()
|
eb.setFooter(
|
||||||
.setFooter(
|
|
||||||
"Requested by ${(track.userData as Member).effectiveName}", (track.userData as Member)
|
|
||||||
.user.effectiveAvatarUrl
|
|
||||||
).setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
|
||||||
.setThumbnail("https://img.youtube.com/vi/${track.info.identifier}/hqdefault.jpg")
|
|
||||||
.setTimestamp(LocalDateTime.now()).setColor(Color.decode("#ff0000")).build()
|
|
||||||
} else if (track is SoundCloudAudioTrack) {
|
|
||||||
val scsm = track.sourceManager as SoundCloudAudioSourceManager
|
|
||||||
scsm.updateClientId()
|
|
||||||
val art = khttp.get(
|
|
||||||
"http://api.soundcloud.com/tracks/${track.info.identifier}?client_id=${scsm.clientId}",
|
|
||||||
headers = mapOf("Content-Type" to "application/json")
|
|
||||||
).jsonObject["artwork_url"].toString().replace("large", "t300x300")
|
|
||||||
|
|
||||||
if (track.userData is Member)
|
|
||||||
return EmbedBuilder()
|
|
||||||
.setFooter(
|
|
||||||
"Requested by ${(track.userData as Member).effectiveName}", (track.userData as Member)
|
|
||||||
.user.effectiveAvatarUrl
|
|
||||||
).setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
|
||||||
.setThumbnail(if (art == "null") null else art)
|
|
||||||
.setTimestamp(LocalDateTime.now()).setColor(Color.decode("#ff5500")).build()
|
|
||||||
|
|
||||||
} else if (track is HttpAudioTrack) {
|
|
||||||
if (track.userData is Member)
|
|
||||||
return EmbedBuilder()
|
|
||||||
.setFooter(
|
|
||||||
"Requested by ${(track.userData as Member).effectiveName}", (track.userData as Member)
|
|
||||||
.user.effectiveAvatarUrl
|
|
||||||
).setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
|
||||||
.setTimestamp(LocalDateTime.now()).setColor(Color.decode("#005A9C")).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
return EmbedBuilder()
|
|
||||||
.setFooter(
|
|
||||||
"Requested by ${(track.userData as Member).effectiveName}", (track.userData as Member)
|
"Requested by ${(track.userData as Member).effectiveName}", (track.userData as Member)
|
||||||
.user.effectiveAvatarUrl
|
.user.effectiveAvatarUrl
|
||||||
).setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
)
|
||||||
.setTimestamp(LocalDateTime.now()).setColor(musicChannel.guild.selfMember.color).build()
|
}
|
||||||
|
when (track) {
|
||||||
|
is YoutubeAudioTrack -> eb.setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
||||||
|
.setThumbnail("https://img.youtube.com/vi/${track.info.identifier}/hqdefault.jpg")
|
||||||
|
.setColor(Color.decode("#ff0000"))
|
||||||
|
|
||||||
|
is SoundCloudAudioTrack -> {
|
||||||
|
val scsm = track.sourceManager as SoundCloudAudioSourceManager
|
||||||
|
scsm.updateClientId()
|
||||||
|
val art = khttp.get(
|
||||||
|
"http://api.soundcloud.com/tracks/${track.info.identifier}?client_id=${scsm.clientId}",
|
||||||
|
headers = mapOf("Content-Type" to "application/json")
|
||||||
|
).jsonObject["artwork_url"].toString().replace("large", "t300x300")
|
||||||
|
|
||||||
|
eb
|
||||||
|
.setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
||||||
|
.setThumbnail(if (art == "null") null else art)
|
||||||
|
.setColor(Color.decode("#ff5500"))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
is HttpAudioTrack -> eb.setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
||||||
|
.setColor(Color.decode("#005A9C"))
|
||||||
|
|
||||||
|
else ->
|
||||||
|
eb.setAuthor(track.info.author).setTitle(track.info.title, track.info.uri)
|
||||||
|
.setColor(musicChannel.guild.selfMember.color)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
eb.setDescription("${millisToTime(track.position)}/${millisToTime(track.duration)}")
|
||||||
|
|
||||||
|
return eb.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun millisToTime(millis: Long): String {
|
||||||
|
var ms = millis
|
||||||
|
val days = TimeUnit.MILLISECONDS.toDays(ms)
|
||||||
|
ms -= TimeUnit.DAYS.toMillis(days)
|
||||||
|
val hours = TimeUnit.MILLISECONDS.toHours(ms)
|
||||||
|
ms -= TimeUnit.HOURS.toMillis(hours)
|
||||||
|
val minutes = TimeUnit.MILLISECONDS.toMinutes(ms)
|
||||||
|
ms -= TimeUnit.MINUTES.toMillis(minutes)
|
||||||
|
val seconds = TimeUnit.MILLISECONDS.toSeconds(ms)
|
||||||
|
val current = String.format(
|
||||||
|
"%02d:%02d:%02d:%02d",
|
||||||
|
days, hours, minutes, seconds
|
||||||
|
).removePrefix("00:").removePrefix("00:")
|
||||||
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTrackList(member: Member): MessageEmbed {
|
fun getTrackList(member: Member): MessageEmbed {
|
||||||
return EmbedBuilder().setTitle("Hey ${member.effectiveName}, here is the playlist")
|
return EmbedBuilder().setTitle("Hey ${member.effectiveName}, here is the playlist${if (loop) ", it loops!" else ""}")
|
||||||
.setTimestamp(LocalDateTime.now()).setColor(musicChannel.guild.selfMember.color)
|
.setTimestamp(LocalDateTime.now()).setColor(musicChannel.guild.selfMember.color)
|
||||||
.setFooter("Requested by ${member.effectiveName}", member.user.effectiveAvatarUrl).setDescription(
|
.setFooter("Requested by ${member.effectiveName}", member.user.effectiveAvatarUrl).setDescription(
|
||||||
"**${player.playingTrack.info.title}**, requested by ${if (player.playingTrack.userData is Member) (player.playingTrack.userData as Member).effectiveName else "someone unknown..."} (*now playing*)\n" +
|
"**${player.playingTrack.info.title}**, requested by ${if (player.playingTrack.userData is Member) (player.playingTrack.userData as Member).effectiveName else "someone unknown..."} (*now playing*)\n" +
|
||||||
|
@ -196,5 +219,11 @@ class TrackScheduler(val player: AudioPlayer, val guild: Guild, val voiceChannel
|
||||||
return press >= half
|
return press >= half
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearQueue() {
|
||||||
|
q.clear()
|
||||||
|
loop = false
|
||||||
|
player.stopTrack()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue