Refactoring, Tests

This commit is contained in:
Wieland Schöbl
2021-05-29 12:16:23 +02:00
parent cc7dc8d9e4
commit 68ed19db7a
25 changed files with 302 additions and 168 deletions

143
.idea/workspace.xml generated
View File

@@ -4,16 +4,33 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="Update .gitignore">
<change afterPath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/webhook/WebhookCaller.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/dictionaries/wulkanat.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dictionaries/wulkanat.xml" afterDir="false" />
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="Bug fixes">
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/ColorTest.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt" 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/kotlin/de/wulkanat/Channels.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/Channels.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/extensions/Message.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/extensions/Message.kt" afterDir="false" />
</list>
<list id="44283a45-f406-407f-bce2-a31bb9bfc0cc" name="Changes by Valentin" comment="Changes by Valentin">
<change beforePath="$PROJECT_DIR$/src/main/java/org/hmcore/WebhookCaller.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/Inaccessibles.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/kotlin/de/wulkanat/Admin.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Admin.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/AdminCli.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/AdminCli.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/Channels.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Channels.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/DataIO.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/DataIO.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/DiscordRpc.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/DiscordRpc.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/ErrorHandler.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/ErrorHandler.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/Main.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/Main.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/OwnerCli.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/OwnerCli.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/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/de/wulkanat/extensions/Embed.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Embed.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/extensions/File.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/File.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/extensions/Jsoup.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Jsoup.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/extensions/Message.kt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/model/BlogPostPreview.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/model/JobListingPreview.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/JobListingPreview.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/web/Parser.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/web/Parser.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/web/SiteWatcher.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/web/SiteWatcher.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/de/wulkanat/webhook/WebhookCaller.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/webhook/WebhookCaller.kt" afterDir="false" />
</list>
<list id="44283a45-f406-407f-bce2-a31bb9bfc0cc" name="Changes by Valentin" comment="Changes by Valentin" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -47,10 +64,10 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Kotlin Class" />
<option value="Kotlin File" />
<option value="Class" />
<option value="Kotlin Object" />
<option value="Kotlin File" />
<option value="Kotlin Class" />
</list>
</option>
</component>
@@ -83,6 +100,10 @@
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="Downloaded.Files.Path.Enabled" value="false" />
<property name="Repository.Attach.Annotations" value="false" />
<property name="Repository.Attach.JavaDocs" value="false" />
<property name="Repository.Attach.Sources" value="false" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
@@ -108,14 +129,18 @@
<recent name="E:\Projects\Kotlin_Proj\HytaleUpdateBot\src" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="E:\Git\Orbot\src\main\kotlin\org\hmcore" />
<recent name="E:\Projects\Kotlin_Proj\HytaleUpdateBot" />
<recent name="E:\Projects\Kotlin_Proj\HytaleUpdateBot\src\main\kotlin\de\wulkanat" />
</key>
<key name="MoveKotlinTopLevelDeclarationsDialog.RECENTS_KEY">
<recent name="de.wulkanat" />
</key>
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
<recent name="org" />
</key>
</component>
<component name="RunManager" selected="Kotlin.Main">
<component name="RunManager" selected="Gradle.EmbedTest">
<configuration default="true" type="ArquillianJUnit" factoryName="" nameIsGenerated="true">
<option name="arquillianRunConfiguration">
<value>
@@ -127,6 +152,48 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ColorTest" 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 &quot;org.hmcore.extensions.ColorTest&quot;" />
<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="EmbedTest" 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 &quot;org.hmcore.extensions.EmbedTest&quot;" />
<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="HytaleUpdateBot [build]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
@@ -148,27 +215,6 @@
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
<configuration name="HytaleUpdateBot [clean]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="clean" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
<configuration name="HytaleUpdateBot [fatJar]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
@@ -190,12 +236,8 @@
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
<configuration name="HytaleUpdateBot-all-1.0-SNAPSHOT.jar" type="JarApplication" temporary="true">
<option name="JAR_PATH" value="$PROJECT_DIR$/build/libs/HytaleUpdateBot-all-1.0-SNAPSHOT.jar" />
<method v="2" />
</configuration>
<configuration name="Main" type="JetRunConfigurationType" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="de.wulkanat.Main" />
<option name="MAIN_CLASS_NAME" value="org.wulkanat.Main" />
<module name="HytaleUpdateBot.main" />
<method v="2">
<option name="Make" enabled="true" />
@@ -203,11 +245,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Gradle.EmbedTest" />
<item itemvalue="Gradle.ColorTest" />
<item itemvalue="Kotlin.Main" />
<item itemvalue="Gradle.HytaleUpdateBot [fatJar]" />
<item itemvalue="Gradle.HytaleUpdateBot [build]" />
<item itemvalue="Gradle.HytaleUpdateBot [clean]" />
<item itemvalue="JAR Application.HytaleUpdateBot-all-1.0-SNAPSHOT.jar" />
</list>
</recent_temporary>
</component>
@@ -222,7 +264,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1597322033373</updated>
<workItem from="1622225780094" duration="8575000" />
<workItem from="1622225780094" duration="9225000" />
</task>
<task id="LOCAL-00001" summary="Add auto publish feature">
<created>1597437833375</created>
@@ -315,7 +357,21 @@
<option name="project" value="LOCAL" />
<updated>1622233754088</updated>
</task>
<option name="localTasksCounter" value="14" />
<task id="LOCAL-00014" summary="Bug fixes">
<created>1622234469645</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1622234469645</updated>
</task>
<task id="LOCAL-00015" summary="Changes by Valentin">
<created>1622234477364</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1622234477364</updated>
</task>
<option name="localTasksCounter" value="16" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -343,10 +399,11 @@
<MESSAGE value="Update stuff" />
<MESSAGE value="Add shards count configuration" />
<MESSAGE value="Add Twitter integration&#10;Add Job Listening Integration&#10;Various Refactorings" />
<MESSAGE value="Changes by Valentin" />
<MESSAGE value="Add more extensive fake update capabilities" />
<MESSAGE value="Update .gitignore" />
<option name="LAST_COMMIT_MESSAGE" value="Update .gitignore" />
<MESSAGE value="Bug fixes" />
<MESSAGE value="Changes by Valentin" />
<option name="LAST_COMMIT_MESSAGE" value="Changes by Valentin" />
</component>
<component name="XDebuggerManager">
<watches-manager>

View File

@@ -3,7 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.10'
}
group 'de.wulkanat'
group 'org.wulkanat'
version '2.0.0'
repositories {
@@ -23,6 +23,9 @@ dependencies {
implementation 'com.github.redouane59.twitter:twittered:1.20'
implementation group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'
testImplementation 'io.mockk:mockk:1.11.0'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.5.10'
}
compileKotlin {
@@ -34,7 +37,7 @@ compileTestKotlin {
jar {
manifest {
attributes('Main-Class': 'de.wulkanat.MainKt')
attributes('Main-Class': 'org.wulkanat.MainKt')
}
}
@@ -45,7 +48,7 @@ task fatJar(type: Jar) {
})
with jar
manifest {
attributes 'Main-Class': 'de.wulkanat.MainKt',
attributes 'Main-Class': 'org.wulkanat.MainKt',
'Implementation-Version': version
}
}

View File

@@ -1,27 +0,0 @@
import net.dv8tion.jda.internal.requests.Method;
import net.dv8tion.jda.internal.requests.Route;
import java.lang.reflect.Constructor;
public class Inaccessibles {
/**
* This is private by default
*
* @param method look
* @param route somewhere
* @return else
*/
public static Route getRoute(Method method, String route) {
try {
Constructor<?> constructor = Route.class.getDeclaredConstructor(Method.class, String.class);
constructor.setAccessible(true);
return (Route) constructor.newInstance(method, route);
} catch (Exception e) {
return null;
}
}
public static String toUnsignedString(long num) {
return Long.toUnsignedString(num);
}
}

View File

@@ -3,8 +3,6 @@ package org.hmcore;
import com.github.redouane59.twitter.TwitterClient;
import com.github.redouane59.twitter.dto.tweet.Tweet;
import com.github.redouane59.twitter.signature.TwitterCredentials;
import de.wulkanat.Admin;
import de.wulkanat.Channels;
import net.dv8tion.jda.api.MessageBuilder;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

View File

@@ -1,28 +0,0 @@
package de.wulkanat.extensions
import Inaccessibles
import net.dv8tion.jda.api.entities.Message
import net.dv8tion.jda.api.entities.MessageChannel
import net.dv8tion.jda.api.requests.restaction.MessageAction
import net.dv8tion.jda.internal.requests.Method
import net.dv8tion.jda.internal.requests.Route
import net.dv8tion.jda.internal.requests.restaction.MessageActionImpl
import net.dv8tion.jda.internal.utils.Checks
fun MessageChannel.crosspostById(messageId: String): MessageAction {
Checks.isSnowflake(messageId, "Message ID")
val route = CROSSPOST_MESSAGE.compile(id, messageId)
return MessageActionImpl(jda, route, this).append("This is not of your interest.")
}
fun Message.crosspost(): MessageAction {
val messageId = Inaccessibles.toUnsignedString(idLong)
return channel.crosspostById(messageId)
}
val CROSSPOST_MESSAGE: Route = Inaccessibles.getRoute(
Method.POST,
"channels/{channel_id}/messages/{message_id}/crosspost"
)

View File

@@ -1,27 +0,0 @@
package de.wulkanat.model
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.entities.MessageEmbed
import de.wulkanat.extensions.hex2Rgb
import kotlinx.serialization.Serializable
@Serializable
data class BlogPostPreview(
val title: String,
val description: String,
val date: String,
val author: String,
val imgUrl: String,
val fullPostUrl: String
) {
fun toMessageEmbed(): MessageEmbed {
return EmbedBuilder()
.setTitle(this.title, this.fullPostUrl)
.setDescription(this.description)
.setAuthor(this.author)
.setThumbnail(this.imgUrl)
.setFooter(this.date, "https://www.hytale.com/static/images/logo-h.png")
.setColor(hex2Rgb("#337fb0"))
.build()
}
}

View File

@@ -1,8 +1,8 @@
@file:JvmName("Admin")
package de.wulkanat
package org.hmcore
import de.wulkanat.extensions.embed
import org.hmcore.extensions.embed
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import net.dv8tion.jda.api.entities.MessageEmbed
@@ -23,7 +23,7 @@ object Admin {
fun connectToUser() {
Main.jdas.find { jda ->
jda.retrieveUserById(userId).complete()?.also { admin = it } != null
} ?: return kotlin.io.println("Connection to de.wulkanat.Admin failed!")
} ?: return kotlin.io.println("Connection to org.hmcore.Admin failed!")
kotlin.io.println("Connected to ${admin!!.name}. No further errors will be printed here.")
}

View File

@@ -1,11 +1,10 @@
package de.wulkanat
package org.hmcore
import de.wulkanat.web.fakeUpdateBlogPost
import de.wulkanat.web.fakeUpdateJobListings
import org.hmcore.web.fakeUpdateBlogPost
import org.hmcore.web.fakeUpdateJobListings
import net.dv8tion.jda.api.hooks.ListenerAdapter
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent
import org.hmcore.TwitterJob
import java.awt.Color
import kotlin.system.exitProcess

View File

@@ -1,8 +1,8 @@
@file:JvmName("Channels")
package de.wulkanat
package org.hmcore
import de.wulkanat.webhook.WebhookCaller
import org.hmcore.webhook.WebhookCaller
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

View File

@@ -1,9 +1,7 @@
@file:JvmName("DataIO")
package de.wulkanat
package org.hmcore
import de.wulkanat.extensions.ensureExists
import de.wulkanat.model.BlogPostPreview
import de.wulkanat.model.JobListingPreview
import org.hmcore.extensions.ensureExists
import kotlinx.serialization.Required
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString

View File

@@ -1,7 +1,4 @@
package de.wulkanat
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.entities.Activity
package org.hmcore
object DiscordRpc {

View File

@@ -1,4 +1,4 @@
package de.wulkanat
package org.hmcore
import net.dv8tion.jda.api.events.ExceptionEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter

View File

@@ -1,6 +1,6 @@
package de.wulkanat
package org.hmcore
import de.wulkanat.web.getNewBlogPosts
import org.hmcore.web.getNewBlogPosts
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.JDABuilder
import net.dv8tion.jda.api.MessageBuilder
@@ -9,7 +9,6 @@ import net.dv8tion.jda.api.requests.GatewayIntent
import net.dv8tion.jda.api.utils.ChunkingFilter
import net.dv8tion.jda.api.utils.MemberCachePolicy
import net.dv8tion.jda.api.utils.cache.CacheFlag
import org.hmcore.TwitterJob
import org.quartz.CronScheduleBuilder.cronSchedule
import org.quartz.JobBuilder.newJob
import org.quartz.JobDetail

View File

@@ -1,4 +1,4 @@
package de.wulkanat
package org.hmcore
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.Permission

View File

@@ -1,4 +1,4 @@
package de.wulkanat.extensions
package org.hmcore.extensions
import java.awt.Color

View File

@@ -1,4 +1,4 @@
package de.wulkanat.extensions
package org.hmcore.extensions
import net.dv8tion.jda.api.EmbedBuilder
import java.awt.Color
@@ -23,6 +23,12 @@ class EmbedBuilderBuilder {
}
get() = Color.BLACK
var thumbnail: String?
set(value) {
_embed.setThumbnail(value)
}
get() = null
fun field(builder: FieldBuilderBuilder.() -> Unit) =
FieldBuilderBuilder().apply { builder() }.let {
_embed.addField(it.name, it.value, it.inline)
@@ -32,6 +38,16 @@ class EmbedBuilderBuilder {
AuthorBuilderBuilder().apply { builder() }.let {
_embed.setAuthor(it.name, it.url, it.icon)
}
fun title(builder: TitleBuilderBuilder.() -> Unit) =
TitleBuilderBuilder().apply { builder() }.let {
_embed.setTitle(it.title, it.url)
}
fun footer(builder: FooterBuilderBuilder.() -> Unit) =
FooterBuilderBuilder().apply { builder() }.let {
_embed.setFooter(it.value, it.iconUrl)
}
}
class FieldBuilderBuilder {
@@ -40,11 +56,21 @@ class FieldBuilderBuilder {
var inline = false
}
class TitleBuilderBuilder {
var title: String? = null
var url: String? = null
}
class AuthorBuilderBuilder {
var name: String? = null
var url: String? = null
var icon: String? = null
}
class FooterBuilderBuilder {
var value: String? = null
var iconUrl: String? = null
}
fun embed(builder: EmbedBuilderBuilder.() -> Unit) =
EmbedBuilderBuilder().apply { builder() }._embed.build()

View File

@@ -1,4 +1,4 @@
package de.wulkanat.extensions
package org.hmcore.extensions
import java.io.File

View File

@@ -1,4 +1,4 @@
package de.wulkanat.extensions
package org.hmcore.extensions
import org.jsoup.nodes.Element
import org.jsoup.select.Elements

View File

@@ -0,0 +1,33 @@
package org.hmcore.model
import org.hmcore.extensions.hex2Rgb
import kotlinx.serialization.Serializable
import org.hmcore.extensions.embed
@Serializable
data class BlogPostPreview(
val title: String,
val description: String,
val date: String,
val author: String,
val imgUrl: String,
val fullPostUrl: String
) {
fun toMessageEmbed() = embed {
title {
title = this@BlogPostPreview.title
url = fullPostUrl
}
description = this@BlogPostPreview.description
color = hex2Rgb("#337FB0")
thumbnail = imgUrl
author {
name = author
}
footer {
value = date
iconUrl = "https://www.hytale.com/static/images/logo-h.png"
}
}
}

View File

@@ -1,6 +1,6 @@
package de.wulkanat.model
package org.hmcore.model
import de.wulkanat.extensions.hex2Rgb
import org.hmcore.extensions.hex2Rgb
import kotlinx.serialization.Serializable
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.entities.MessageEmbed

View File

@@ -1,11 +1,11 @@
package de.wulkanat.web
package org.hmcore.web
import de.wulkanat.extensions.absUrl
import de.wulkanat.extensions.get
import de.wulkanat.extensions.imgSrc
import de.wulkanat.extensions.text
import de.wulkanat.model.BlogPostPreview
import de.wulkanat.model.JobListingPreview
import org.hmcore.extensions.absUrl
import org.hmcore.extensions.get
import org.hmcore.extensions.imgSrc
import org.hmcore.extensions.text
import org.hmcore.model.BlogPostPreview
import org.hmcore.model.JobListingPreview
private const val BLOG_POST_STATE_FILE_NAME = "blog_state.json"
fun fakeUpdateBlogPost(amount: Int = 1) = removeFromSiteSave<BlogPostPreview>(BLOG_POST_STATE_FILE_NAME, amount)

View File

@@ -1,4 +1,4 @@
package de.wulkanat.web
package org.hmcore.web
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString

View File

@@ -1,6 +1,6 @@
package de.wulkanat.webhook
package org.hmcore.webhook
import de.wulkanat.WEBHOOKS
import org.hmcore.WEBHOOKS
import net.dv8tion.jda.api.entities.Message
import org.hmcore.DiscordWebhook
import org.hmcore.DiscordWebhook.EmbedObject

View File

@@ -0,0 +1,16 @@
package org.hmcore.extensions
import org.junit.Assert.assertEquals
import org.junit.Test
import java.awt.Color
class ColorTest {
@Test
fun `color should parse from hex correctly`() {
assertEquals(hex2Rgb("#FFFFFF"), Color.WHITE)
assertEquals(hex2Rgb("#000000"), Color.BLACK)
assertEquals(hex2Rgb("#FF0000"), Color.RED)
assertEquals(hex2Rgb("#00FF00"), Color.GREEN)
assertEquals(hex2Rgb("#0000FF"), Color.BLUE)
}
}

View File

@@ -0,0 +1,90 @@
package org.hmcore.extensions
import java.awt.Color
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class EmbedTest {
@Test
fun `Embed Title DSL should work`() {
val dslEmbed = embed {
title {
title = "Title"
url = "https://a.b.c"
}
}
assertEquals("Title", dslEmbed.title)
assertEquals("https://a.b.c", dslEmbed.url)
}
@Test
fun `Embed Thumbnail should work`() {
val dslEmbed = embed {
thumbnail = "https://a.b.c"
}
assertNotNull(dslEmbed.thumbnail)
assertEquals("https://a.b.c", dslEmbed.thumbnail!!.url)
}
@Test
fun `Embed Footer DSL should work`() {
val dslEmbed = embed {
footer {
value = "Value"
iconUrl = "https://a.b.c"
}
}
assertNotNull(dslEmbed.footer)
assertEquals("Value", dslEmbed.footer!!.text)
assertEquals("https://a.b.c", dslEmbed.footer!!.iconUrl)
}
@Test
fun `Embed DSL should produce same result as native`() {
val dslEmbed = embed {
title = "A Title"
description = "A Description"
color = Color.YELLOW
author {
name = "An author"
icon = "https://d.e.f"
url = "https://a.b.c"
}
field {
inline = true
name = "Field1"
value = "Body1"
}
field {
inline = false
name = "Field2"
value = "Body2"
}
}
assertEquals("A Title", dslEmbed.title)
assertEquals("A Description", dslEmbed.description)
assertEquals(Color.YELLOW, dslEmbed.color)
assertNotNull(dslEmbed.author)
assertEquals("An author", dslEmbed.author!!.name)
assertEquals("https://d.e.f", dslEmbed.author!!.iconUrl)
assertEquals("https://a.b.c", dslEmbed.author!!.url)
assertEquals(2, dslEmbed.fields.size)
assertEquals("Field1", dslEmbed.fields[0].name)
assertEquals("Body1", dslEmbed.fields[0].value)
assertEquals(true, dslEmbed.fields[0].isInline)
assertEquals("Field2", dslEmbed.fields[1].name)
assertEquals("Body2", dslEmbed.fields[1].value)
assertEquals(false, dslEmbed.fields[1].isInline)
}
}