Alter commmands a bit

and add a lyrics command that doesnt want to work for some reason...
This commit is contained in:
Julius de Jeu 2018-11-07 23:25:56 +01:00
parent a1d79e0475
commit 6b93a5dcc1
6 changed files with 100 additions and 16 deletions

View file

@ -8,6 +8,7 @@ import net.dv8tion.jda.core.JDA
import net.dv8tion.jda.core.JDABuilder
import nl.voidcorp.dbot.commands.*
import nl.voidcorp.dbot.music.initMusic
import nl.voidcorp.dbot.music.musicExtra
import org.slf4j.LoggerFactory
val playerManager = DefaultAudioPlayerManager()
@ -30,6 +31,7 @@ fun main(args: Array<String>) {
initMusic()
initFun()
initAdmin()
musicExtra()
val custom = UnityCommandClient("!")
@ -83,7 +85,7 @@ fun main(args: Array<String>) {
if (bod.value != null) {
bod.value!!.apply {
val embed = EmbedBuilder()
embed.setTitle(project.name, project.web_url)
embed.setTitle(project.title, project.web_url)
val builder = embed.descriptionBuilder
var url = ""
commits.forEach {

View file

@ -80,14 +80,14 @@ object AddRoleCommand : UnityCommand(
exec = { ce ->
val args = ce.args.split(",").map { it.trim() }
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 {
val gs = GSM.getSettings(ce.guild)
val role = ce.guild.getRolesByName(args[0], true).firstOrNull()
val key = args[1]
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?")
} else {
if (gs.roleMap.containsKey(key)) {

View file

@ -40,7 +40,7 @@ open class UnityCategory(
}
}
/*
val test = ce.textChannel.name.contains("bot")
val test = ce.textChannel.title.contains("bot")
if (!test) {
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")
/*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 musicExists = ce.guild.getTextChannelsByName("music", true).firstOrNull() != null
val musicBotExists = ce.guild.getTextChannelsByName("music-bot", true).firstOrNull() != null
when {
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!")
res
}
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!")
res
}
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!")
res
}
@ -108,9 +108,9 @@ object HiddenCategory : UnityCategory("hidden") {
/*
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
val test = ce.textChannel.name.contains("bot")
val test = ce.textChannel.title.contains("bot")
if (!test) {
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 ->
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
val test = ce.textChannel.name.contains("bot")
val test = ce.textChannel.title.contains("bot")
if (!test) {
ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} voiceChannel")
}

View file

@ -59,7 +59,7 @@ val helpCommand =
val prefix = GSM.getSettings(event.guild).primaryPrefix
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)
.setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl)
.setTimestamp(LocalDateTime.now())

View file

@ -69,7 +69,7 @@ fun initMusic() {
howTo = "youtube <search term or link>"
) { event, scheduler ->
if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!")
event.reply("Please supply a song title or URL!")
return@UnityMusicCommand
}
playerManager.loadItem(event.args, object : AudioLoadResultHandler {
@ -103,7 +103,7 @@ fun initMusic() {
howTo = "sc <link or search term>"
) { event, scheduler ->
if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!")
event.reply("Please supply a song title or URL!")
return@UnityMusicCommand
}
@ -139,7 +139,7 @@ fun initMusic() {
category = MusicCategoryPrivate
) { event, scheduler ->
if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!")
event.reply("Please supply a song title or URL!")
return@UnityMusicCommand
}
playerManager.loadItem(event.args, object : AudioLoadResultHandler {

View 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 {
""
}
}