mirror of
https://github.com/HMCore/Orbot.git
synced 2025-12-12 13:56:18 +00:00
added multiple alert types:
new aler types: - twitter - job
This commit is contained in:
81
.idea/workspace.xml
generated
81
.idea/workspace.xml
generated
@@ -4,17 +4,15 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="Add file tests">
|
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="twitter gods dont cancel me pls">
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Message.kt" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/org/hmcore/MessageType.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/webhook/DiscordWebhookEmbed.kt" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/serialization/EnumTest.kt" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/webhook/DiscordWebhookEmbed.kt" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/org/hmcore/DiscordWebhook.java" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/org/hmcore/TwitterJob.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/hmcore/TwitterJob.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/org/hmcore/TwitterJob.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/hmcore/TwitterJob.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Channels.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Channels.kt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Channels.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Channels.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Color.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Color.kt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/DataIO.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/DataIO.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/webhook/WebhookCaller.kt" beforeDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Main.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Main.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/ColorTest.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/ColorTest.kt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/OwnerCli.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/OwnerCli.kt" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<list id="44283a45-f406-407f-bce2-a31bb9bfc0cc" name="Changes by Valentin" comment="Changes by Valentin" />
|
<list id="44283a45-f406-407f-bce2-a31bb9bfc0cc" name="Changes by Valentin" comment="Changes by Valentin" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@@ -101,9 +99,10 @@
|
|||||||
<component name="FileTemplateManagerImpl">
|
<component name="FileTemplateManagerImpl">
|
||||||
<option name="RECENT_TEMPLATES">
|
<option name="RECENT_TEMPLATES">
|
||||||
<list>
|
<list>
|
||||||
<option value="Class" />
|
|
||||||
<option value="Kotlin Object" />
|
<option value="Kotlin Object" />
|
||||||
<option value="Kotlin File" />
|
<option value="Kotlin File" />
|
||||||
|
<option value="Enum" />
|
||||||
|
<option value="Class" />
|
||||||
<option value="Kotlin Class" />
|
<option value="Kotlin Class" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
@@ -125,15 +124,15 @@
|
|||||||
</file-type-list>
|
</file-type-list>
|
||||||
</component>
|
</component>
|
||||||
<component name="HighlightingSettingsPerFile">
|
<component name="HighlightingSettingsPerFile">
|
||||||
<setting file="file://$PROJECT_DIR$/build.gradle" root0="SKIP_INSPECTION" />
|
<setting file="file://$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Embed.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/ColorTest.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/File.kt" root0="FORCE_HIGHLIGHTING" />
|
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Jsoup.kt" root0="FORCE_HIGHLIGHTING" />
|
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/JobListingPreview.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/JobListingPreview.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/ColorTest.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/build.gradle" root0="SKIP_INSPECTION" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Color.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Color.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt" root0="FORCE_HIGHLIGHTING" />
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/File.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Embed.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
|
<setting file="file://$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Jsoup.kt" root0="FORCE_HIGHLIGHTING" />
|
||||||
</component>
|
</component>
|
||||||
<component name="MacroExpansionManager">
|
<component name="MacroExpansionManager">
|
||||||
<option name="directoryName" value="o7p0t8es" />
|
<option name="directoryName" value="o7p0t8es" />
|
||||||
@@ -186,7 +185,7 @@
|
|||||||
<recent name="org" />
|
<recent name="org" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="Gradle.DiscordWebhookEmbed.Webhook should not throw and return false if supplied invalid URL">
|
<component name="RunManager" selected="Kotlin.Main">
|
||||||
<configuration default="true" type="ArquillianJUnit" factoryName="" nameIsGenerated="true">
|
<configuration default="true" type="ArquillianJUnit" factoryName="" nameIsGenerated="true">
|
||||||
<option name="arquillianRunConfiguration">
|
<option name="arquillianRunConfiguration">
|
||||||
<value>
|
<value>
|
||||||
@@ -198,12 +197,12 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="ColorTest" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
<configuration name="BlogPostPreviewTest" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
<option name="scriptParameters" value="--tests "org.hmcore.extensions.ColorTest"" />
|
<option name="scriptParameters" value="--tests "org.hmcore.model.BlogPostPreviewTest"" />
|
||||||
<option name="taskDescriptions">
|
<option name="taskDescriptions">
|
||||||
<list />
|
<list />
|
||||||
</option>
|
</option>
|
||||||
@@ -240,33 +239,12 @@
|
|||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="EmbedTest" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
<configuration name="EnumTest.Enum serialization" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
<option name="scriptParameters" value="--tests "org.hmcore.extensions.EmbedTest"" />
|
<option name="scriptParameters" value="--tests "org.hmcore.serialization.EnumTest.Enum serialization"" />
|
||||||
<option name="taskDescriptions">
|
|
||||||
<list />
|
|
||||||
</option>
|
|
||||||
<option name="taskNames">
|
|
||||||
<list>
|
|
||||||
<option value=":test" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
<option name="vmOptions" />
|
|
||||||
</ExternalSystemSettings>
|
|
||||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
|
||||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
|
||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="FileTest" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
|
||||||
<ExternalSystemSettings>
|
|
||||||
<option name="executionName" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
|
||||||
<option name="scriptParameters" value="--tests "org.hmcore.extensions.FileTest"" />
|
|
||||||
<option name="taskDescriptions">
|
<option name="taskDescriptions">
|
||||||
<list />
|
<list />
|
||||||
</option>
|
</option>
|
||||||
@@ -313,21 +291,28 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Main" type="JetRunConfigurationType" temporary="true" nameIsGenerated="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="org.hmcore.Main" />
|
||||||
|
<module name="HytaleUpdateBot.main" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="Gradle.ColorTest" />
|
|
||||||
<item itemvalue="Gradle.EmbedTest" />
|
|
||||||
<item itemvalue="Gradle.FileTest" />
|
|
||||||
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
||||||
<item itemvalue="JUnit.All Tests" />
|
|
||||||
<item itemvalue="Gradle.DiscordWebhookEmbed.Webhook should not throw and return false if supplied invalid URL" />
|
<item itemvalue="Gradle.DiscordWebhookEmbed.Webhook should not throw and return false if supplied invalid URL" />
|
||||||
|
<item itemvalue="Gradle.EnumTest.Enum serialization" />
|
||||||
|
<item itemvalue="Gradle.BlogPostPreviewTest" />
|
||||||
|
<item itemvalue="JUnit.All Tests" />
|
||||||
|
<item itemvalue="Kotlin.Main" />
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Kotlin.Main" />
|
||||||
|
<item itemvalue="Gradle.BlogPostPreviewTest" />
|
||||||
|
<item itemvalue="Gradle.EnumTest.Enum serialization" />
|
||||||
<item itemvalue="Gradle.DiscordWebhookEmbed.Webhook should not throw and return false if supplied invalid URL" />
|
<item itemvalue="Gradle.DiscordWebhookEmbed.Webhook should not throw and return false if supplied invalid URL" />
|
||||||
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
||||||
<item itemvalue="Gradle.FileTest" />
|
|
||||||
<item itemvalue="Gradle.EmbedTest" />
|
|
||||||
<item itemvalue="Gradle.ColorTest" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
15
src/main/java/org/hmcore/MessageType.java
Normal file
15
src/main/java/org/hmcore/MessageType.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package org.hmcore;
|
||||||
|
|
||||||
|
public enum MessageType {
|
||||||
|
|
||||||
|
INVALID (-1),
|
||||||
|
BLOGPOST(0),
|
||||||
|
TWITTER(1),
|
||||||
|
JOB_LISTING(2),
|
||||||
|
WEBSITE_CHANGED(3);
|
||||||
|
|
||||||
|
MessageType(int i) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ public class TwitterJob implements Job {
|
|||||||
if (!lastTweetID.equalsIgnoreCase(tweetID)) {
|
if (!lastTweetID.equalsIgnoreCase(tweetID)) {
|
||||||
lastTweetID = tweetID;
|
lastTweetID = tweetID;
|
||||||
|
|
||||||
Channels.INSTANCE.sentToAll(new MessageBuilder().append("https://twitter.com/Hytale/status/").append(tweetID).build());
|
Channels.INSTANCE.sentToAll(new MessageBuilder().append("https://twitter.com/Hytale/status/").append(tweetID).build(), MessageType.TWITTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import kotlinx.serialization.json.Json
|
|||||||
import net.dv8tion.jda.api.EmbedBuilder
|
import net.dv8tion.jda.api.EmbedBuilder
|
||||||
import net.dv8tion.jda.api.Permission
|
import net.dv8tion.jda.api.Permission
|
||||||
import net.dv8tion.jda.api.entities.Message
|
import net.dv8tion.jda.api.entities.Message
|
||||||
|
import org.hmcore.extensions.embed
|
||||||
import org.hmcore.extensions.toWebhook
|
import org.hmcore.extensions.toWebhook
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
|
|
||||||
@@ -18,12 +19,22 @@ object Channels {
|
|||||||
var channels: MutableList<DiscordChannel> = refreshChannelsFromDisk()
|
var channels: MutableList<DiscordChannel> = refreshChannelsFromDisk()
|
||||||
var serviceChannels: MutableList<ServiceChannel> = refreshServiceChannelsFromDisk()
|
var serviceChannels: MutableList<ServiceChannel> = refreshServiceChannelsFromDisk()
|
||||||
|
|
||||||
fun sentToAll(messageEmbed: Message) {
|
fun sentToAll(messageEmbed: Message, msgType: MessageType) {
|
||||||
messageEmbed.toWebhook().send(WEBHOOKS.blogPostsWebhookUrl)
|
try {
|
||||||
|
messageEmbed.toWebhook().send(WEBHOOKS.blogPostsWebhookUrl)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
Admin.sendDevMessage(embed {
|
||||||
|
title = "Error"
|
||||||
|
description = e.stackTraceToString()
|
||||||
|
color = Color.red
|
||||||
|
}, e.stackTrace.toString())
|
||||||
|
}
|
||||||
|
|
||||||
Main.jdas.forEach { jda ->
|
Main.jdas.forEach { jda ->
|
||||||
for (channel_pair in channels) {
|
for (channel_pair in channels) {
|
||||||
try {
|
try {
|
||||||
|
if(!channel_pair.type.equals(msgType)) continue
|
||||||
val channel = jda.getTextChannelById(channel_pair.id) ?: continue
|
val channel = jda.getTextChannelById(channel_pair.id) ?: continue
|
||||||
val customMessage = channel_pair.message?.message ?: ""
|
val customMessage = channel_pair.message?.message ?: ""
|
||||||
|
|
||||||
@@ -126,7 +137,9 @@ object Channels {
|
|||||||
else -> " @${channel.guild.getRoleById(it.mentionedRole ?: "")?.name}"
|
else -> " @${channel.guild.getRoleById(it.mentionedRole ?: "")?.name}"
|
||||||
}
|
}
|
||||||
val publish = if (it.autoPublish) " (publish)" else ""
|
val publish = if (it.autoPublish) " (publish)" else ""
|
||||||
"**${channel.guild.name}** #${channel.name}${role}${publish}${
|
val type = " " + it.type.toString()
|
||||||
|
|
||||||
|
"**${channel.guild.name}** #${channel.name}${role}${publish}${type}${
|
||||||
if (it.message == null) {
|
if (it.message == null) {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
@@ -150,11 +163,11 @@ object Channels {
|
|||||||
fun testServerId(id: Long) =
|
fun testServerId(id: Long) =
|
||||||
Main.jdas.map { it.getTextChannelById(id) }.firstOrNull()
|
Main.jdas.map { it.getTextChannelById(id) }.firstOrNull()
|
||||||
|
|
||||||
fun addChannel(id: Long, role: String?): DiscordChannel? {
|
fun addChannel(id: Long, msgType: MessageType): DiscordChannel? {
|
||||||
if (channels.find { it.id == id } != null) {
|
if (channels.find { it.id == id && it.type == msgType } != null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val out = DiscordChannel(id, role)
|
val out = DiscordChannel(id, msgType)
|
||||||
channels.add(out)
|
channels.add(out)
|
||||||
saveChannels()
|
saveChannels()
|
||||||
return out
|
return out
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ import kotlinx.serialization.encodeToString
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
const val channelVersion = 2.0
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DiscordChannel(
|
data class DiscordChannel(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
|
var type: MessageType,
|
||||||
var mentionedRole: String? = null,
|
var mentionedRole: String? = null,
|
||||||
var autoPublish: Boolean = false,
|
var autoPublish: Boolean = false,
|
||||||
var message: CustomMessage? = null
|
var message: CustomMessage? = null,
|
||||||
|
var version: Double? = channelVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.hmcore
|
package org.hmcore
|
||||||
|
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import org.hmcore.web.getNewBlogPosts
|
import org.hmcore.web.getNewBlogPosts
|
||||||
import net.dv8tion.jda.api.JDA
|
import net.dv8tion.jda.api.JDA
|
||||||
import net.dv8tion.jda.api.JDABuilder
|
import net.dv8tion.jda.api.JDABuilder
|
||||||
@@ -9,12 +11,14 @@ import net.dv8tion.jda.api.requests.GatewayIntent
|
|||||||
import net.dv8tion.jda.api.utils.ChunkingFilter
|
import net.dv8tion.jda.api.utils.ChunkingFilter
|
||||||
import net.dv8tion.jda.api.utils.MemberCachePolicy
|
import net.dv8tion.jda.api.utils.MemberCachePolicy
|
||||||
import net.dv8tion.jda.api.utils.cache.CacheFlag
|
import net.dv8tion.jda.api.utils.cache.CacheFlag
|
||||||
|
import org.hmcore.web.getNewJobListings
|
||||||
import org.quartz.CronScheduleBuilder.cronSchedule
|
import org.quartz.CronScheduleBuilder.cronSchedule
|
||||||
import org.quartz.JobBuilder.newJob
|
import org.quartz.JobBuilder.newJob
|
||||||
import org.quartz.JobDetail
|
import org.quartz.JobDetail
|
||||||
import org.quartz.Trigger
|
import org.quartz.Trigger
|
||||||
import org.quartz.TriggerBuilder.newTrigger
|
import org.quartz.TriggerBuilder.newTrigger
|
||||||
import org.quartz.impl.StdSchedulerFactory
|
import org.quartz.impl.StdSchedulerFactory
|
||||||
|
import java.io.File
|
||||||
import javax.security.auth.login.LoginException
|
import javax.security.auth.login.LoginException
|
||||||
import kotlin.concurrent.timer
|
import kotlin.concurrent.timer
|
||||||
|
|
||||||
@@ -24,6 +28,27 @@ object Main {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
if(args.isEmpty()) startBot() else
|
||||||
|
when(args[0]) {
|
||||||
|
"serverDataConvert1" -> serverDataConvert1()
|
||||||
|
else -> startBot()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun serverDataConvert1() {
|
||||||
|
var file = File("servers.json")
|
||||||
|
if(!file.exists()) return
|
||||||
|
var content = ""
|
||||||
|
file.bufferedReader().readLines().forEach {
|
||||||
|
content += it
|
||||||
|
.replace(",\"mentionedRole\":", ",\"type\":\"BLOGPOST\",\"mentionedRole\":")
|
||||||
|
}
|
||||||
|
file.writeBytes(content.encodeToByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startBot() {
|
||||||
val builder = JDABuilder.createLight(
|
val builder = JDABuilder.createLight(
|
||||||
Admin.token,
|
Admin.token,
|
||||||
GatewayIntent.GUILD_MESSAGES,
|
GatewayIntent.GUILD_MESSAGES,
|
||||||
@@ -57,9 +82,15 @@ object Main {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
timer("Updater", daemon = true, initialDelay = 0L, period = Admin.updateMs) {
|
timer("UpdaterBlogpost", daemon = true, initialDelay = 0L, period = Admin.updateMs) {
|
||||||
getNewBlogPosts()?.forEach {
|
getNewBlogPosts()?.forEach {
|
||||||
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build())
|
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build(), MessageType.BLOGPOST)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timer("UpdaterJob", daemon = true, initialDelay = 0L, period = Admin.updateMs) {
|
||||||
|
getNewJobListings()?.forEach {
|
||||||
|
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build(), MessageType.JOB_LISTING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +108,7 @@ object Main {
|
|||||||
.withSchedule(cronSchedule("0 0/5 * 1/1 * ? *"))
|
.withSchedule(cronSchedule("0 0/5 * 1/1 * ? *"))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
scheduler.scheduleJob(job, trigger);
|
scheduler.scheduleJob(job, trigger)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureMemoryUsage(builder: JDABuilder) {
|
private fun configureMemoryUsage(builder: JDABuilder) {
|
||||||
|
|||||||
@@ -18,10 +18,38 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
|
|
||||||
val command = msg.removePrefix(prefix).split(Regex("\\s+"))
|
val command = msg.removePrefix(prefix).split(Regex("\\s+"))
|
||||||
val channelId = event.message.channel.idLong
|
val channelId = event.message.channel.idLong
|
||||||
|
val msgType: MessageType
|
||||||
|
|
||||||
|
if(command.size < 2)
|
||||||
|
msgType = MessageType.INVALID
|
||||||
|
else msgType = when (command[1].lowercase()) {
|
||||||
|
"blogpost" -> MessageType.BLOGPOST
|
||||||
|
"twitter" -> MessageType.TWITTER
|
||||||
|
"job" -> MessageType.JOB_LISTING
|
||||||
|
"website" -> MessageType.WEBSITE_CHANGED
|
||||||
|
else -> MessageType.INVALID
|
||||||
|
}
|
||||||
|
|
||||||
when (command.first()) {
|
when (command.first()) {
|
||||||
|
"categories" -> {
|
||||||
|
event.message.channel.sendMessage(EmbedBuilder()
|
||||||
|
.setTitle("Categories")
|
||||||
|
.setColor(Color.YELLOW)
|
||||||
|
.setAuthor(Admin.admin?.name, Admin.admin?.avatarUrl, Admin.admin?.avatarUrl)
|
||||||
|
.setDescription("Valid Categories:\n" +
|
||||||
|
" Blogpost\n" +
|
||||||
|
" Twitter\n" +
|
||||||
|
" Job - (changes of Job listings)\n" +
|
||||||
|
" Website - (if the content of some website or subdomain thats owned by hypixel studios gets changed) - soon\n")
|
||||||
|
.build()).queue()
|
||||||
|
return
|
||||||
|
}
|
||||||
"add" -> {
|
"add" -> {
|
||||||
val result = Channels.addChannel(channelId, null)
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val result = Channels.addChannel(channelId, msgType)
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
event.message.channel.sendMessage("Already added.").queue()
|
event.message.channel.sendMessage("Already added.").queue()
|
||||||
} else {
|
} else {
|
||||||
@@ -30,7 +58,10 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"remove" -> {
|
"remove" -> {
|
||||||
val result = Channels.channels.removeAll { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.removeAll { it.id == channelId && (it.type == msgType || it.type == MessageType.INVALID) }
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
if (result) {
|
if (result) {
|
||||||
event.message.channel.sendMessage("Removed.").queue()
|
event.message.channel.sendMessage("Removed.").queue()
|
||||||
@@ -39,31 +70,37 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"publish" -> {
|
"publish" -> {
|
||||||
val result = Channels.channels.find { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.find { it.id == channelId && it.type == msgType}
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (command.size > 1 && listOf("on", "off").contains(command[1])) {
|
if (command.size > 2 && listOf("on", "off").contains(command[2])) {
|
||||||
result.autoPublish = command[1] == "on"
|
result.autoPublish = command[2] == "on"
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
|
|
||||||
event.message.channel.sendMessage("Auto publish is now ${command[1]}").queue()
|
event.message.channel.sendMessage("Auto publish is now ${command[1]}").queue()
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Usage: `${prefix}publish [on|off]`")
|
event.message.channel.sendMessage("Usage: `${prefix}publish [type] [on|off]`")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Channel not registered.").queue()
|
event.message.channel.sendMessage("Channel not registered.").queue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"ping" -> {
|
"ping" -> {
|
||||||
val result = Channels.channels.find { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.find { it.id == channelId && it.type == msgType}
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (command.size > 1) {
|
if (command.size > 2) {
|
||||||
val roles = event.message.guild.getRolesByName(command[1], false)
|
val roles = event.message.guild.getRolesByName(command[2], false)
|
||||||
result.mentionedRole = when {
|
result.mentionedRole = when {
|
||||||
command[1] == "everyone" -> {
|
command[2] == "everyone" -> {
|
||||||
event.message.channel.sendMessage("Now pinging everyone.").queue()
|
event.message.channel.sendMessage("Now pinging everyone.").queue()
|
||||||
"everyone"
|
"everyone"
|
||||||
}
|
}
|
||||||
command[1] == "none" -> {
|
command[2] == "none" -> {
|
||||||
event.message.channel.sendMessage("Now pinging none.").queue()
|
event.message.channel.sendMessage("Now pinging none.").queue()
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -78,29 +115,35 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
}
|
}
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Usage: `${prefix}ping [everyone|none|roleName]`")
|
event.message.channel.sendMessage("Usage: `${prefix}ping [type] [everyone|none|roleName]`")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Channel is not registered.").queue()
|
event.message.channel.sendMessage("Channel is not registered.").queue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"setMessage" -> {
|
"setMessage" -> {
|
||||||
val result = Channels.channels.find { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.find { it.id == channelId && it.type == msgType }
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (command.size > 1) {
|
if (command.size > 2) {
|
||||||
val message = event.message.contentRaw.removePrefix("${prefix}setMessage").trim()
|
val message = command.subList(2, command.size).toString().trim()
|
||||||
result.message = CustomMessage(message)
|
result.message = CustomMessage(message)
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
event.message.channel.sendMessage("Set `$message` as message.").queue()
|
event.message.channel.sendMessage("Set `$message` as message.").queue()
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Usage: `${prefix}setMessage [message]`")
|
event.message.channel.sendMessage("Usage: `${prefix}setMessage [type] [message]`")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Channel is not registered.").queue()
|
event.message.channel.sendMessage("Channel is not registered.").queue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"resetMessage" -> {
|
"resetMessage" -> {
|
||||||
val result = Channels.channels.find { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.find { it.id == channelId && it.type == msgType }
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
result.message = null
|
result.message = null
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
@@ -132,16 +175,19 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
"publishMessage" -> {
|
"publishMessage" -> {
|
||||||
val result = Channels.channels.find { it.id == channelId }
|
if (msgType == MessageType.INVALID) {
|
||||||
|
event.message.channel.sendMessage("Please choose a valid category. List valid categories with ${prefix}categories").queue()
|
||||||
|
}
|
||||||
|
val result = Channels.channels.find { it.id == channelId && it.type == msgType }
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (result.message != null) {
|
if (result.message != null) {
|
||||||
if (command.size > 1 && listOf("on", "off").contains(command[1])) {
|
if (command.size > 2 && listOf("on", "off").contains(command[2])) {
|
||||||
result.message?.pushAnnouncement = command[1] == "on"
|
result.message?.pushAnnouncement = command[2] == "on"
|
||||||
Channels.saveChannels()
|
Channels.saveChannels()
|
||||||
|
|
||||||
event.message.channel.sendMessage("Auto publish (message) is now ${command[1]}").queue()
|
event.message.channel.sendMessage("Auto publish (message) is now ${command[1]}").queue()
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Usage: `${prefix}publishMessage [on|off]`")
|
event.message.channel.sendMessage("Usage: `${prefix}publishMessage [type] [on|off]`")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.message.channel.sendMessage("Channel has no custom message.").queue()
|
event.message.channel.sendMessage("Channel has no custom message.").queue()
|
||||||
@@ -185,22 +231,24 @@ class OwnerCli : ListenerAdapter() {
|
|||||||
.setAuthor(Admin.admin?.name, Admin.admin?.avatarUrl, Admin.admin?.avatarUrl)
|
.setAuthor(Admin.admin?.name, Admin.admin?.avatarUrl, Admin.admin?.avatarUrl)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
"""
|
"""
|
||||||
**${prefix}add**
|
**${prefix}add [type]**
|
||||||
Add this channel to the notified list
|
Add this channel to the notified list
|
||||||
**${prefix}serviceChannel [add|remove]**
|
**${prefix}serviceChannel [add|remove]**
|
||||||
Add or remove this channel to receive service message from the bot developer (recommended)
|
Add or remove this channel to receive service message from the bot developer (recommended)
|
||||||
**${prefix}remove**
|
**${prefix}remove [type]**
|
||||||
Remove this channel to the notified list
|
Remove this channel to the notified list
|
||||||
**${prefix}publish [on|off]**
|
**${prefix}publish [type] [on|off]**
|
||||||
[Community|Partner|Verified only] Auto publish the message if in an announcement channel
|
[Community|Partner|Verified only] Auto publish the message if in an announcement channel
|
||||||
**${prefix}ping [none|everyone|roleName]**
|
**${prefix}ping [type] [none|everyone|roleName]**
|
||||||
What role to ping
|
What role to ping
|
||||||
**${prefix}setMessage [message]**
|
**${prefix}setMessage [type] [message]**
|
||||||
Set a custom message to show
|
Set a custom message to show
|
||||||
**${prefix}resetMessage**
|
**${prefix}resetMessag [type]e**
|
||||||
Reset the message
|
Reset the message
|
||||||
**${prefix}info**
|
**${prefix}info**
|
||||||
Show an overview about all channels registered on this server
|
Show an overview about all channels registered on this server
|
||||||
|
**${prefix}categories**
|
||||||
|
Show a list of categories available for alert types
|
||||||
**${prefix}report**
|
**${prefix}report**
|
||||||
Report an issue to the Bot Admin (this will share your user name so they can contact you)
|
Report an issue to the Bot Admin (this will share your user name so they can contact you)
|
||||||
**${prefix}help**
|
**${prefix}help**
|
||||||
|
|||||||
17
src/test/kotlin/org/hmcore/serialization/EnumTest.kt
Normal file
17
src/test/kotlin/org/hmcore/serialization/EnumTest.kt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package org.hmcore.serialization
|
||||||
|
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.hmcore.MessageType
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
|
class EnumTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Enum serialization`() {
|
||||||
|
println(Json.encodeToString(MessageType.BLOGPOST))
|
||||||
|
assertNotNull(MessageType.INVALID)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user