-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from jDiscord to JDA API library
- Loading branch information
1 parent
82e0d3e
commit 9d698f2
Showing
3 changed files
with
42 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 20 additions & 14 deletions
34
src/main/kotlin/gg/obsidian/discordbridge/DiscordListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
package gg.obsidian.discordbridge | ||
|
||
import me.itsghost.jdiscord.DiscordAPI | ||
import me.itsghost.jdiscord.event.EventListener | ||
import me.itsghost.jdiscord.events.UserChatEvent | ||
import com.neovisionaries.ws.client.WebSocket | ||
import com.neovisionaries.ws.client.WebSocketException | ||
import net.dv8tion.jda.JDA | ||
import net.dv8tion.jda.events.message.MessageReceivedEvent | ||
import net.dv8tion.jda.hooks.ListenerAdapter | ||
|
||
class DiscordListener(val plugin: Plugin, val api: DiscordAPI) : EventListener { | ||
class DiscordListener(val plugin: Plugin, val api: JDA) : ListenerAdapter() { | ||
|
||
fun userChat(e: UserChatEvent) { | ||
plugin.logDebug("Received message ${e.msg.id} from Discord") | ||
override fun onMessageReceived(event: MessageReceivedEvent) { | ||
plugin.logDebug("Received message ${event.message.id} from Discord") | ||
|
||
if (!e.server.id.equals(plugin.configuration.SERVER_ID)) { | ||
plugin.logDebug("Ignoring message ${e.msg.id} from Discord: server does not match") | ||
if (!event.guild.id.equals(plugin.configuration.SERVER_ID)) { | ||
plugin.logDebug("Ignoring message ${event.message.id} from Discord: server does not match") | ||
return | ||
} | ||
|
||
if (!e.group.name.equals(plugin.configuration.CHANNEL, true)) { | ||
plugin.logDebug("Ignoring message ${e.msg.id} from Discord: channel does not match") | ||
if (!event.textChannel.name.equals(plugin.configuration.CHANNEL, true)) { | ||
plugin.logDebug("Ignoring message ${event.message.id} from Discord: channel does not match") | ||
return | ||
} | ||
|
||
val username: String = e.user.user.username | ||
val username: String = event.author.username | ||
|
||
if (username.equals(plugin.configuration.USERNAME, true)) { | ||
plugin.logDebug("Ignoring message ${e.msg.id} from Discord: it matches the server's username") | ||
plugin.logDebug("Ignoring message ${event.message.id} from Discord: it matches the server's username") | ||
return | ||
} | ||
|
||
plugin.logDebug("Broadcasting message ${e.msg.id} from Discord as user $username") | ||
plugin.sendToMinecraft(username, e.msg.message) | ||
plugin.logDebug("Broadcasting message ${event.message.id} from Discord as user $username") | ||
plugin.sendToMinecraft(username, event.message.content) | ||
} | ||
|
||
fun onUnexpectedError(ws: WebSocket, wse: WebSocketException) { | ||
plugin.logger.severe("Unexpected error from DiscordBridge: ${wse.message}") | ||
} | ||
} |