Skip to content

Commit

Permalink
Add service announcement channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Theaninova committed Aug 19, 2020
1 parent 490a5dc commit a78c234
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
servers.json
admin.json
test.json
service_channels.json
*.hprof
/build
/.gradle
61 changes: 41 additions & 20 deletions .idea/workspace.xml

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

110 changes: 43 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,61 @@ the bot to your server. Please note that only people with *Administrator* permis
configure it.

You can type `%!info` to get an overview over all available commands.
## Commands

| **Command** | **Arguments** | **Info** |
|------------------|--------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| %!add | | Add current channel to the notified list |
| %!remove | | Remove current channel to the notified list |
| %!publish | on | off | [Community|Partner|Verified only] Auto publish the message if in an announcement channel |
| %!ping | none | everyone | roleName | What role to ping |
| %!setMessage | message | Set a custom message when a blogpost arrives |
| %!resetMessage | | Reset the custom message to none |
| %!serviceChannel | add | remove | Add/remove channel from service notification list |
| %!publishMessage | on | off | [Community|Partner|Verified only] Auto publish the custom message if in an announcement channel |
| %!info | | Show an overview about all channels registered on this server |
| %!report | Your message | Report an issue to the Bot Admin (this will share your user name so they can contact you) |
| %!help | | Show a help dialog with all these commands |

## Self Hosting
Okay, this isn't really meant for you to setup, but if you *really* want to set it up yourself, fine.
* first go to the release tab, download the jar, and put it in a folder
* Add two files in the root of the repo, an `admin.json` and a `servers.json`.
Add your Discord ID (not name), Bot token, and update frequency to the `admin.json`:
```json
{
"adminId": 12345678910,
"token": "AOGH@(AKnjsfjiJijaig3ijgG92jaij",
"updateMs": 30000,
"watchingMessage": "for new Blogposts"
}
```
* add your servers to `servers.json`
```json
[
{
"id": 15050067772322222,
"mentionedRole": "everyone",
"autoPublish": true,
"message": null
},
{
"id": 74050067772325222,
"mentionedRole": null,
"autoPublish":false,
"message": null
},
{
"id": 74050067772325222,
"mentionedRole": "74036067771625222",
"autoPublish":false,
"message": null
}
]
```
* add a `test.json` with the same schema as the `server.json`. When
you enable test mode, the servers from there will be used instead allowing
you to test if it works.
Go to the release tab, download the jar, and put it in a folder.

Start the server with `java -jar [server-file-name]` If you put in everything correctly,
the bot should message you on Discord.

*Note:* You need to invite the bot into a server before it can message you.

Run it once (it should crash or print an error), so `admin.json`, `servers.json` and `service_channels.json`
are being created.
Add your Discord ID `adminId` (not name), Bot token `token`, and update frequency `updateMs` to the `admin.json`,
optionally you can add your own messages for when the bot is looking and when it can't reach Hytale Servers.

If you verified that everything works correctly, you can start the server in the background, on Linux that is
`nohup java -jar [server-file-name]`. To stop it you can either type `!stop` in the Admin Console (Discord PM) or
if the bot is unresponsive the the PID of it through `ps -ef` and `kill [pid]`


## Compiling yourself
I developed it under Windows, and had some trouble compiling it on Linux. You mileage may vary.

## Admin commands

Start the server with `java -jar [server-file-name]` If you put in everything correctly, the bot should message you on Discord.
### Adding Servers
Please edit the JSON file.
You can force an update by calling
```
%!refreshList
```
### Testing
Switching between test and production files
```
%!testMode
%!fakeUpdate
```
```
%!productionMode
```
**WARNING**: Initiating a fake update is not being cancelled by switching
to production.
### Stop the server from within Discord
```
%!stop
```
### Show servers, channels and roles
```
%!info
```

These commands will work in every channel, but will be ignored if they don't come from you, however the bot will always respond in a private message.
It will also print errors directly in a Discord private message.
| **Command** | **Arguments** | **Info** |
|------------------|-------|---------------------|
| !info | | Show all registered channels and servers. |
| !stop | | Stop the server (useful when running in `nohup`) |
| !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) |

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`.

## TODO

Mainly reaction roles for convenience, self setup on invite to server, Twitter integration.
Mainly reaction roles for convenience, Twitter integration to either be even faster or to brag how much faster
we were over the official Hytale Twitter.

## Other

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.3'
version '1.4'

repositories {
mavenCentral()
Expand Down
28 changes: 9 additions & 19 deletions src/main/kotlin/de/wulkanat/Admin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,15 @@ object Admin {
val token: String
val updateMs: Long
val message: String

var testModeEnabled: Boolean = false
set(value) {
if (field == value)
return

field = value

if (value) {
jda?.presence?.setPresence(Activity.of(Activity.ActivityType.DEFAULT, "Testing mode, hold on..."), true)
} else {
jda?.presence?.setPresence(Activity.watching("for new Blogposts"), false)
}

Channels.channels = Channels.refreshFromDisk()
Admin.info()
}
val offlineMessage: String

init {
val admin = Json(JsonConfiguration.Stable).parse(AdminFile.serializer(), ADMIN_FILE.readText())
userId = admin.adminId
token = admin.token
updateMs = admin.updateMs
message = admin.watchingMessage
offlineMessage = admin.offlineMessage
}

var jda: JDA? = null
Expand Down Expand Up @@ -116,7 +101,12 @@ object Admin {
sendDevMessage(
EmbedBuilder()
.setTitle("Now watching for new Hytale Blogposts every ${updateMs / 1000}s")
.setDescription(Channels.getServerNames().joinToString("\n"))
.setDescription("""
${Channels.getServerNames().joinToString("\n")}
**_Service Channels_**
${Channels.getServiceChannelServers().joinToString("\n")}
""".trimIndent())
.setColor(Color.GREEN)
.build(),
"Now watching for new Hytale BlogPosts"
Expand All @@ -138,7 +128,7 @@ object Admin {
.sendMessage(messageEmbed).complete()
}

private fun sendDevMessage(messageEmbed: MessageEmbed, fallback: String) {
fun sendDevMessage(messageEmbed: MessageEmbed, fallback: String) {
val devChannel = admin?.openPrivateChannel() ?: kotlin.run {
kotlin.io.println(fallback)
return
Expand Down
Loading

0 comments on commit a78c234

Please sign in to comment.