Skip to content

Commit

Permalink
add debugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dkim19375 committed May 16, 2021
1 parent 06f7d27 commit 8e4fe2d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding 'UTF-8'

group 'me.dkim19375'
version '2.2.0'
version '2.2.1'

//noinspection GrUnresolvedAccess
compileKotlin.kotlinOptions.jvmTarget = '1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,29 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() {
requiredPerms: Set<Permission> = emptySet(),
removeIfNoPerms: Boolean = false,
reaction: MessageReaction.ReactionEmote? = null,
debug: Boolean = false
) {
val actionVar: (Event) -> Unit = action@{ event ->
if (debug) {
println("called ------------")
}
val jda = event.jda
when (event) {
is GuildMessageReactionAddEvent -> if (eventType != EventType.GUILD) return@action
is MessageReactionAddEvent -> if (eventType != EventType.GENERIC) return@action
is PrivateMessageReactionAddEvent -> if (eventType != EventType.PRIVATE) return@action
}
if (debug) {
println("passed EventType test")
}
val messageId: Long = event.getMessageId() ?: return@action
if (debug) {
println("passed messageId 1")
}
val userId: Long = event.getUserId() ?: return@action
if (debug) {
println("passed userId test")
}
val guild: Guild? = when (event) {
is GuildMessageReactionAddEvent -> event.guild
else -> null
Expand All @@ -67,53 +80,110 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() {
is PrivateMessageReactionAddEvent -> event.reactionEmote
else -> return@action
}
if (debug) {
println("passed emoji test")
}
val channel = when (event) {
is GuildMessageReactionAddEvent -> event.channel
is MessageReactionAddEvent -> event.channel
is PrivateMessageReactionAddEvent -> event.channel
else -> return@action
}
if (debug) {
println("passed channel test")
}
if (requiredChannel != 0L && requiredChannel != channel.idLong) {
if (debug) {
println("stopped - requiredChannel: $requiredChannel, channel: ${channel.idLong}")
}
return@action
}
if (debug) {
println("passed channel id test")
}
if (reaction != null) {
if (reaction.name != emoji.name) {
if (debug) {
println("stopped - reaction name: ${reaction.name}, emoji name: ${emoji.name}")
}
return@action
}
}
if (debug) {
println("passed reaction tests")
}
val retrievedMessage: RestAction<Message> = when (event) {
is GuildMessageReactionAddEvent -> event.retrieveMessage()
is MessageReactionAddEvent -> event.retrieveMessage()
is PrivateMessageReactionAddEvent -> event.channel.retrieveMessageById(event.messageIdLong)
else -> return@action
}
if (debug) {
println("passed message test")
}
if (requiredGuild != guild?.idLong && (requiredGuild != 0L && guild != null)) {
if (debug) {
println("stopped - requiredGuild: $requiredGuild, guild: ${guild.idLong}")
}
return@action
}
if (debug) {
println("passed requiredGuild test")
}
if (requiredMessage != messageId && requiredMessage != 0L) {
if (debug) {
println("stopped 2 - requiredMessage: $requiredMessage, messageId: $messageId")
}
return@action
}
if (debug) {
println("passed requiredMessage test")
}
retrievedMessage.queue message@{ msg ->
jda.retrieveUserById(userId).queue userQ@{ user ->
if (whitelist?.contains(userId) != false) {
if (!removeIfNoPerms) {
if (debug) {
println("no whitelist")
}
return@userQ
}
when {
emoji.isEmoji -> msg.removeReaction(emoji.emoji, user)
emoji.isEmote -> msg.removeReaction(emoji.emote, user)
emoji.isEmoji -> msg.removeReaction(emoji.emoji, user).queue()
emoji.isEmote -> msg.removeReaction(emoji.emote, user).queue()
}
return@userQ
}
guild?.retrieveMemberById(userId)?.queue memberQueue@{ member ->
if (!member.hasPermission(requiredPerms, channel as? GuildChannel)) {
if (debug) {
println("no permissions")
}
if (!removeIfNoPerms) {
return@memberQueue
}
when {
emoji.isEmoji -> msg.removeReaction(emoji.emoji, user).queue()
emoji.isEmote -> msg.removeReaction(emoji.emote, user).queue()
}
return@memberQueue
}
if (debug) {
println("called action - guild")
}
action(event, guild, emoji, channel, user, msg, member)
} ?: action(event, guild, emoji, channel, user, msg, null)
} ?: let {
action(event, guild, emoji, channel, user, msg, null)
if (debug) {
println("called action - null guild")
}
}
}
}
}
if (debug) {
println("added to variables")
}
if (permanent) {
events.add(actionVar)
return
Expand Down

0 comments on commit 8e4fe2d

Please sign in to comment.