Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Theaninova committed Aug 31, 2020
1 parent a78c234 commit 0877883
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 43 deletions.
16 changes: 16 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 42 additions & 36 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ I developed it under Windows, and had some trouble compiling it on Linux. You mi
| !serviceMessage | message | Send a service message to all registered channels |
| !fakeUpdate | | Cause a fake update (**WARNING**: This will show on **ALL** registered servers) |
| !refreshList | | Refresh servers and service channels from disk (if you manually edit the JSON files) |
| !removeInactive | | Remove inactive channels |
| !help | | Show a help dialog with all these commands |

These commands will only work by private messaging the bot (and will be ignored if they don't
come from the admin registered in the `admin.json`.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'de.wulkanat'
version '1.4'
version '1.4.1'

repositories {
mavenCentral()
Expand Down
43 changes: 42 additions & 1 deletion src/main/kotlin/de/wulkanat/AdminCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package de.wulkanat
import de.wulkanat.model.BlogPostPreview
import net.dv8tion.jda.api.hooks.ListenerAdapter
import de.wulkanat.web.SiteWatcher
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent
import java.awt.Color
import kotlin.system.exitProcess

class AdminCli : ListenerAdapter() {
val prefix = "!"

override fun onPrivateMessageReceived(event: PrivateMessageReceivedEvent) {
val msg = event.message.contentRaw
if (event.author.idLong != Admin.userId ||
!msg.startsWith("!")
!msg.startsWith(prefix)
) {
return
}
Expand Down Expand Up @@ -45,6 +49,43 @@ class AdminCli : ListenerAdapter() {
Channels.serviceChannels = Channels.refreshServiceChannelsFromDisk()
Admin.info()
}
"removeInactive" -> {
Channels.channels.removeAll { channel ->
Channels.testServerId(channel.id) ?: run {
Admin.println("Removed ${channel.id}")
null
} == null
}
Admin.info()
Channels.saveChannels()
}
"help" -> {
event.message.channel.sendMessage(
EmbedBuilder()
.setTitle("Help")
.setColor(Color.YELLOW)
.setAuthor(Admin.admin?.name, Admin.admin?.avatarUrl, Admin.admin?.avatarUrl)
.setDescription(
"""
**${prefix}stop**
Stop the bot
**${prefix}fakeUpdate**
Post a fake update to every registered channel (can be used if bot missed the update)
**${prefix}info**
Show an overview over all registered channels
**${prefix}serviceMessage [title] [message]**
Show a service message (update info etc) to all registered service channels
**${prefix}refreshList**
Refresh server list from disk
**${prefix}removeInactive**
Remove inactive channels
**${prefix}help**
Show this message
""".trimIndent()
)
.build()
).queue()
}
}
}
}
7 changes: 2 additions & 5 deletions src/main/kotlin/de/wulkanat/Channels.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package de.wulkanat

import de.wulkanat.extensions.crosspost
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.list
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.entities.MessageEmbed
import net.dv8tion.jda.api.entities.TextChannel
import net.dv8tion.jda.api.exceptions.ErrorResponseException
import java.awt.Color

object Channels {
Expand Down Expand Up @@ -53,8 +50,8 @@ object Channels {
it.crosspost().queue()
}
}
} catch (e: ErrorResponseException) {
Admin.error("Error in server", e.message ?: e.localizedMessage)
} catch (e: Exception) {
Admin.error("Error in server ${channel_pair.id}", e.message ?: e.localizedMessage)
}
}
}
Expand Down

0 comments on commit 0877883

Please sign in to comment.