Commit 282f4f84 authored by garantiertnicht's avatar garantiertnicht

Update JDA

JDA (the Discord library wrapper) was too old to handle news channels.
The presence of a news channel caused the bot to crash and/or not start
properly.

JDA has been updated to the last 3.X.X release. The 4.X.X branch cannot
be used as it would break setting roles to emotes, thus rendering the
bot useless.

There also has been a minor fix for a bug which prevented errors from
being shown if there were no roles in the add/remove commands.
parent fef80d55
......@@ -8,5 +8,5 @@ resolvers += Resolver.bintrayRepo("dv8fromtheworld", "maven")
resolvers += Resolver.jcenterRepo
libraryDependencies ++= Seq(
"net.dv8tion" % "JDA" % "3.8.3_460"
"net.dv8tion" % "JDA" % "3.8.3_463"
)
......@@ -318,7 +318,8 @@ class Bot extends ListenerAdapter {
override def onReady(event: ReadyEvent): Unit = {
val user = event.getJDA.getSelfUser
event.getJDA.getPresence.setGame(Game.watching(s"@${user.getAsTag} help"))
event.getJDA.getPresence
.setGame(Game.watching(s"@${user.getAsTag} help"))
}
def helpCommandHandler(
......@@ -364,10 +365,18 @@ class Bot extends ListenerAdapter {
val emotes = rolesAndEmotes._2
val unknown = rolesAndEmotes._3
val uselessRoles = emotes
.map(_.getRoles.asScala)
.reduce(_ intersect _) intersect roles
val usefulRoles = roles diff uselessRoles
val uselessRoles =
if (emotes.isEmpty) emotes
else {
emotes
.map(_.getRoles.asScala)
.reduce(_ intersect _) intersect roles
}
val usefulRoles =
if (roles.isEmpty) roles
else {
roles diff uselessRoles
}
if (usefulRoles.nonEmpty && emotes.nonEmpty) {
emotes.foreach(
......@@ -375,7 +384,9 @@ class Bot extends ListenerAdapter {
emote.getManager
.setRoles((emote.getRoles.asScala ++ usefulRoles).toSet.asJava)
.queue(
_ => {},
x => {
channel.sendMessage(x.toString).queue()
},
(error: Throwable) => {
channel
.sendMessage(
......@@ -468,10 +479,18 @@ class Bot extends ListenerAdapter {
val emotes = rolesAndEmotes._2
val unknown = rolesAndEmotes._3
val uselessRoles = roles diff emotes
.map(_.getRoles.asScala)
.reduce(_ intersect _)
val usefulRoles = roles diff uselessRoles
val uselessRoles =
if (roles.isEmpty) roles
else {
roles diff emotes
.map(_.getRoles.asScala)
.reduce(_ intersect _)
}
val usefulRoles =
if (roles.isEmpty) roles
else {
roles diff uselessRoles
}
if (usefulRoles.nonEmpty && emotes.nonEmpty) {
emotes.foreach(
......@@ -481,11 +500,13 @@ class Bot extends ListenerAdapter {
.queue(
_ => {},
(error: Throwable) => {
channel.sendMessage(
s"Updating ${emote.getAsMention} failed: ${error.getMessage}. " +
"This means that changes on these emoji were **not** saved. Try " +
"again later. If the issue persists, please contact the developer."
)
channel
.sendMessage(
s"Updating ${emote.getAsMention} failed: ${error.getMessage}. " +
"This means that changes on these emoji were **not** saved. Try " +
"again later. If the issue persists, please contact the developer."
)
.queue()
}
)
)
......@@ -992,14 +1013,14 @@ class Bot extends ListenerAdapter {
def checkPermissions(
who: IPermissionHolder,
where: Channel,
where: TextChannel,
which: Seq[Permission]
): Seq[Permission] =
which.filterNot(checkPermission(who, where, _))
def checkPermission(
who: IPermissionHolder,
where: Channel,
where: TextChannel,
which: Permission
) =
if (which.isChannel) who.hasPermission(where, which)
......
......@@ -26,6 +26,6 @@ object Main {
new JDABuilder(AccountType.BOT)
.setToken(token)
.addEventListener(new Bot)
.buildAsync()
.build()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment