Alter commmands a bit
and add a lyrics command that doesnt want to work for some reason...
This commit is contained in:
parent
a1d79e0475
commit
6b93a5dcc1
|
@ -8,6 +8,7 @@ import net.dv8tion.jda.core.JDA
|
||||||
import net.dv8tion.jda.core.JDABuilder
|
import net.dv8tion.jda.core.JDABuilder
|
||||||
import nl.voidcorp.dbot.commands.*
|
import nl.voidcorp.dbot.commands.*
|
||||||
import nl.voidcorp.dbot.music.initMusic
|
import nl.voidcorp.dbot.music.initMusic
|
||||||
|
import nl.voidcorp.dbot.music.musicExtra
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
val playerManager = DefaultAudioPlayerManager()
|
val playerManager = DefaultAudioPlayerManager()
|
||||||
|
@ -30,6 +31,7 @@ fun main(args: Array<String>) {
|
||||||
initMusic()
|
initMusic()
|
||||||
initFun()
|
initFun()
|
||||||
initAdmin()
|
initAdmin()
|
||||||
|
musicExtra()
|
||||||
|
|
||||||
|
|
||||||
val custom = UnityCommandClient("!")
|
val custom = UnityCommandClient("!")
|
||||||
|
@ -83,7 +85,7 @@ fun main(args: Array<String>) {
|
||||||
if (bod.value != null) {
|
if (bod.value != null) {
|
||||||
bod.value!!.apply {
|
bod.value!!.apply {
|
||||||
val embed = EmbedBuilder()
|
val embed = EmbedBuilder()
|
||||||
embed.setTitle(project.name, project.web_url)
|
embed.setTitle(project.title, project.web_url)
|
||||||
val builder = embed.descriptionBuilder
|
val builder = embed.descriptionBuilder
|
||||||
var url = ""
|
var url = ""
|
||||||
commits.forEach {
|
commits.forEach {
|
||||||
|
|
|
@ -80,14 +80,14 @@ object AddRoleCommand : UnityCommand(
|
||||||
exec = { ce ->
|
exec = { ce ->
|
||||||
val args = ce.args.split(",").map { it.trim() }
|
val args = ce.args.split(",").map { it.trim() }
|
||||||
if (args.size != 2) {
|
if (args.size != 2) {
|
||||||
ce.reply("Ehm, that is not how this is supposed to work, the args have to be `Rolename,rolekey`\nWith Rolename the actual name in discord and rolekey the key you want to assign.")
|
ce.reply("Ehm, that is not how this is supposed to work, the args have to be `Rolename,rolekey`\nWith Rolename the actual title in discord and rolekey the key you want to assign.")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val gs = GSM.getSettings(ce.guild)
|
val gs = GSM.getSettings(ce.guild)
|
||||||
val role = ce.guild.getRolesByName(args[0], true).firstOrNull()
|
val role = ce.guild.getRolesByName(args[0], true).firstOrNull()
|
||||||
val key = args[1]
|
val key = args[1]
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
ce.reply("Ehm, that is not how this is supposed to work, the args have to be `Rolename,rolekey`\nWith Rolename the actual name in discord and rolekey the key you want to assign.")
|
ce.reply("Ehm, that is not how this is supposed to work, the args have to be `Rolename,rolekey`\nWith Rolename the actual title in discord and rolekey the key you want to assign.")
|
||||||
ce.reply("Also, the discord role you provided is not existing?")
|
ce.reply("Also, the discord role you provided is not existing?")
|
||||||
} else {
|
} else {
|
||||||
if (gs.roleMap.containsKey(key)) {
|
if (gs.roleMap.containsKey(key)) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ open class UnityCategory(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
val test = ce.textChannel.name.contains("bot")
|
val test = ce.textChannel.title.contains("bot")
|
||||||
if (!test) {
|
if (!test) {
|
||||||
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
||||||
}
|
}
|
||||||
|
@ -52,25 +52,25 @@ open class UnityCategory(
|
||||||
object GeneralCategory : UnityCategory("general")
|
object GeneralCategory : UnityCategory("general")
|
||||||
|
|
||||||
/*val MusicCategory = Command.Category("Music Commands") { ce ->
|
/*val MusicCategory = Command.Category("Music Commands") { ce ->
|
||||||
if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true
|
if (ce.member.roles.firstOrNull { it.title.equals("admin", true) } != null) return@Category true
|
||||||
|
|
||||||
val botExists = ce.guild.getTextChannelsByName("bot", true).firstOrNull() != null
|
val botExists = ce.guild.getTextChannelsByName("bot", true).firstOrNull() != null
|
||||||
val musicExists = ce.guild.getTextChannelsByName("music", true).firstOrNull() != null
|
val musicExists = ce.guild.getTextChannelsByName("music", true).firstOrNull() != null
|
||||||
val musicBotExists = ce.guild.getTextChannelsByName("music-bot", true).firstOrNull() != null
|
val musicBotExists = ce.guild.getTextChannelsByName("music-bot", true).firstOrNull() != null
|
||||||
when {
|
when {
|
||||||
musicBotExists -> {
|
musicBotExists -> {
|
||||||
val res = ce.textChannel.name == "music-bot"
|
val res = ce.textChannel.title == "music-bot"
|
||||||
|
|
||||||
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music-bot", true).first().asMention} voiceChannel!")
|
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music-bot", true).first().asMention} voiceChannel!")
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
musicExists -> {
|
musicExists -> {
|
||||||
val res = ce.textChannel.name == "music"
|
val res = ce.textChannel.title == "music"
|
||||||
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music", true).first().asMention} voiceChannel!")
|
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music", true).first().asMention} voiceChannel!")
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
botExists -> {
|
botExists -> {
|
||||||
val res = ce.textChannel.name == "bot"
|
val res = ce.textChannel.title == "bot"
|
||||||
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel!")
|
if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel!")
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -108,9 +108,9 @@ object HiddenCategory : UnityCategory("hidden") {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
val GeneralCategory = Command.Category("General commands") { ce ->
|
val GeneralCategory = Command.Category("General commands") { ce ->
|
||||||
if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true
|
if (ce.member.roles.firstOrNull { it.title.equals("admin", true) } != null) return@Category true
|
||||||
if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true
|
if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true
|
||||||
val test = ce.textChannel.name.contains("bot")
|
val test = ce.textChannel.title.contains("bot")
|
||||||
if (!test) {
|
if (!test) {
|
||||||
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
||||||
}
|
}
|
||||||
|
@ -120,10 +120,10 @@ val GeneralCategory = Command.Category("General commands") { ce ->
|
||||||
|
|
||||||
|
|
||||||
/*val FunCategory = Command.Category("Fun Commands") { ce ->
|
/*val FunCategory = Command.Category("Fun Commands") { ce ->
|
||||||
if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true
|
if (ce.member.roles.firstOrNull { it.title.equals("admin", true) } != null) return@Category true
|
||||||
|
|
||||||
if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true
|
if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true
|
||||||
val test = ce.textChannel.name.contains("bot")
|
val test = ce.textChannel.title.contains("bot")
|
||||||
if (!test) {
|
if (!test) {
|
||||||
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ val helpCommand =
|
||||||
val prefix = GSM.getSettings(event.guild).primaryPrefix
|
val prefix = GSM.getSettings(event.guild).primaryPrefix
|
||||||
|
|
||||||
eb.setTitle(greeting)
|
eb.setTitle(greeting)
|
||||||
.appendDescription("My name is OttoBot, and I am definitely the best Discord bot around!\n\nUse `${prefix}help command` for a chance that I have more info about a command!")
|
.appendDescription("My title is OttoBot, and I am definitely the best Discord bot around!\n\nUse `${prefix}help command` for a chance that I have more info about a command!")
|
||||||
.setColor(event.selfMember.color)
|
.setColor(event.selfMember.color)
|
||||||
.setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl)
|
.setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl)
|
||||||
.setTimestamp(LocalDateTime.now())
|
.setTimestamp(LocalDateTime.now())
|
||||||
|
|
|
@ -69,7 +69,7 @@ fun initMusic() {
|
||||||
howTo = "youtube <search term or link>"
|
howTo = "youtube <search term or link>"
|
||||||
) { event, scheduler ->
|
) { event, scheduler ->
|
||||||
if (event.args.isEmpty()) {
|
if (event.args.isEmpty()) {
|
||||||
event.reply("Please supply a song name or URL!")
|
event.reply("Please supply a song title or URL!")
|
||||||
return@UnityMusicCommand
|
return@UnityMusicCommand
|
||||||
}
|
}
|
||||||
playerManager.loadItem(event.args, object : AudioLoadResultHandler {
|
playerManager.loadItem(event.args, object : AudioLoadResultHandler {
|
||||||
|
@ -103,7 +103,7 @@ fun initMusic() {
|
||||||
howTo = "sc <link or search term>"
|
howTo = "sc <link or search term>"
|
||||||
) { event, scheduler ->
|
) { event, scheduler ->
|
||||||
if (event.args.isEmpty()) {
|
if (event.args.isEmpty()) {
|
||||||
event.reply("Please supply a song name or URL!")
|
event.reply("Please supply a song title or URL!")
|
||||||
return@UnityMusicCommand
|
return@UnityMusicCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ fun initMusic() {
|
||||||
category = MusicCategoryPrivate
|
category = MusicCategoryPrivate
|
||||||
) { event, scheduler ->
|
) { event, scheduler ->
|
||||||
if (event.args.isEmpty()) {
|
if (event.args.isEmpty()) {
|
||||||
event.reply("Please supply a song name or URL!")
|
event.reply("Please supply a song title or URL!")
|
||||||
return@UnityMusicCommand
|
return@UnityMusicCommand
|
||||||
}
|
}
|
||||||
playerManager.loadItem(event.args, object : AudioLoadResultHandler {
|
playerManager.loadItem(event.args, object : AudioLoadResultHandler {
|
||||||
|
|
82
src/main/kotlin/nl/voidcorp/dbot/music/SecondaryCommands.kt
Normal file
82
src/main/kotlin/nl/voidcorp/dbot/music/SecondaryCommands.kt
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package nl.voidcorp.dbot.music
|
||||||
|
|
||||||
|
import khttp.get
|
||||||
|
import net.dv8tion.jda.core.EmbedBuilder
|
||||||
|
import nl.voidcorp.dbot.commands
|
||||||
|
import nl.voidcorp.dbot.commands.MusicCategory
|
||||||
|
import nl.voidcorp.dbot.commands.UnityCommand
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
val lyricsCommand = UnityCommand("lyrics", "Search for lyrics!", MusicCategory) { ce ->
|
||||||
|
val song =
|
||||||
|
if (!ce.hasArgs) {
|
||||||
|
val scheduler = guildMusicMap[ce.guild.idLong]
|
||||||
|
if ((scheduler != null) && scheduler.voiceChannel.members.contains(ce.member)) {
|
||||||
|
val info = scheduler.player.playingTrack.info
|
||||||
|
println(info.author)
|
||||||
|
println(info.title)
|
||||||
|
findInfo(info.title)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ce.reply("Please either provide a search term or play a song using the bot!")
|
||||||
|
return@UnityCommand
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
findInfo(ce.args)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (song != null) {
|
||||||
|
val text = findText(song)
|
||||||
|
if (text.isBlank()) {
|
||||||
|
ce.reply("Sorry, couldn't find any lyrics for this song...")
|
||||||
|
} else {
|
||||||
|
val eb = EmbedBuilder().setTimestamp(LocalDateTime.now())
|
||||||
|
.setFooter("Requested by ${ce.member.effectiveName}", ce.member.user.effectiveAvatarUrl)
|
||||||
|
.setColor(ce.selfMember.color)
|
||||||
|
eb.setTitle("Lyrics for ${song.artist} - ${song.title}")
|
||||||
|
eb.setDescription(text)
|
||||||
|
ce.reply(eb.build())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ce.reply("Sorry, couldn't find any lyrics for this song...")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun musicExtra() {
|
||||||
|
commands.add(lyricsCommand)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data class Song(val artist: String, val title: String)
|
||||||
|
|
||||||
|
fun findInfo(search: String): Song? {
|
||||||
|
val res = khttp.get(
|
||||||
|
"https://api.genius.com/search?q=${search.replace(" ", "%20")}",
|
||||||
|
headers = mapOf("Authorization" to "Bearer eqn-1xrvrAKtoIFC-pIgNiW7cRzSvaF49wjFzasEu7coSLpufVVnv_IGVnxUIT43")
|
||||||
|
)
|
||||||
|
val hits = res.jsonObject.getJSONObject("response").getJSONArray("hits")!!
|
||||||
|
return if (hits.length() == 0) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
val hit = hits.getJSONObject(0).getJSONObject("result")!!
|
||||||
|
println(hit)
|
||||||
|
Song(hit.getJSONObject("primary_artist").getString("name"), hit.getString("title"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findText(song: Song): String {
|
||||||
|
val res =
|
||||||
|
get(
|
||||||
|
"https://orion.apiseeds.com/api/music/lyric/${song.artist}/${song.title.replace(
|
||||||
|
" ",
|
||||||
|
"%20"
|
||||||
|
)}?apikey=8pLAxkCnWJNGWRaoPcbCFpUAKdKD77zmlcjs2FKYjdH00MDyNr6lXLHb3PQZsKJI"
|
||||||
|
)
|
||||||
|
return if (res.jsonObject.isNull("error")) {
|
||||||
|
res.jsonObject.getJSONObject("result").getJSONObject("track").getString("text")
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue