Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 16ca799

Browse files
committed
Add test bot for discord
1 parent fb2f0ac commit 16ca799

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import org.codeoverflow.chatoverflow.api.plugin.{Pluggable, Plugin, PluginManager}
2+
3+
class discordTest extends Pluggable {
4+
/**
5+
* Returns the name of the plugin.
6+
*
7+
* @return the display name of the plugin
8+
*/
9+
override def getName: String = "discordTest"
10+
11+
/**
12+
* Returns the author name of the plugin.
13+
*
14+
* @return the real name or a alias of the author
15+
*/
16+
override def getAuthor: String = "joblo2213"
17+
18+
/**
19+
* Returns a description of the plugin.
20+
*
21+
* @return a simple description of the service
22+
*/
23+
override def getDescription: String = "Plugin for testing the discord implementation"
24+
25+
/**
26+
* Returns the newest major version of the api, where the plugin was successfully tested!
27+
*
28+
* @return a version number
29+
*/
30+
override def getMajorAPIVersion: Int = 1
31+
32+
/**
33+
* Returns the newest minor version of the api, where the plugin was successfully tested!
34+
*
35+
* @return a version number
36+
*/
37+
override def getMinorAPIVersion: Int = 0
38+
39+
/**
40+
* Returns the real chat overflow plugin. Should only be used after testing the api version number!
41+
* If the plugin is not up-to-date, it might not be loaded due to possible reflection errors. Please
42+
* do ONLY use the Plugin class to define your own chat overflow plugin logic!
43+
* Create a new instance HERE every time!
44+
*
45+
* @param manager the manager implementation of the framework
46+
* @return the plugin implementation of the plugin project, ready to get started!
47+
*/
48+
override def createNewPluginInstance(manager: PluginManager): Plugin = new discordTestPlugin(manager)
49+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import org.codeoverflow.chatoverflow.api.io.dto.chat.discord.DiscordChatMessage
2+
import org.codeoverflow.chatoverflow.api.plugin.{PluginImpl, PluginManager}
3+
import scala.collection.JavaConverters._
4+
5+
class discordTestPlugin(manager: PluginManager) extends PluginImpl(manager) {
6+
7+
private val discordInputReq = require.input.discordChat("reqDiscordIn", "Discord input", false)
8+
private val discordOutputReq = require.output.discordChat("reqDiscordOut", "Discord output", false)
9+
10+
override def setup(): Unit = {
11+
println(s"Input connected to channel ${discordInputReq.get().getChannelId}")
12+
println(s"Output connected to channel ${discordOutputReq.get().getChannelId}")
13+
discordInputReq.get.registerMessageHandler(onMessage)
14+
discordInputReq.get.registerMessageEditHandler(onMessageEdit)
15+
discordInputReq.get.registerMessageDeleteHandler(onMessageDelete)
16+
discordOutputReq.get.sendChatMessage("Hey I'm working! \uD83C\uDF89")
17+
println("Startet succesfully")
18+
}
19+
20+
override def loop(): Unit = {}
21+
22+
23+
override def shutdown(): Unit = println("Plugin stopped")
24+
25+
def onMessage(message: DiscordChatMessage): Unit = {
26+
if (message.getMessage == "/messages") {
27+
var s = "**Recent messages:**\n"
28+
s += discordInputReq.get.getLastMessages(1000*60).asScala.filter(_.getAuthor.getId != discordTestPlugin.BOT_ID).mkString("\n")
29+
s += "\n\n**Recent private messages:**\n"
30+
s += discordInputReq.get().getLastPrivateMessages(1000*60).asScala.mkString("\n")
31+
discordOutputReq.get. sendChatMessage(s)
32+
}
33+
}
34+
35+
def onMessageEdit(oldMessage: DiscordChatMessage, newMessage: DiscordChatMessage): Unit = {
36+
println(s"Message #${oldMessage.getId} was edited from '$oldMessage' to '$newMessage'")
37+
}
38+
39+
def onMessageDelete(message: DiscordChatMessage): Unit = {
40+
println(s"Message #${message.getId} was deleted (content: $message)")
41+
}
42+
}
43+
object discordTestPlugin {
44+
val BOT_ID = "572870096356376576"
45+
}

0 commit comments

Comments
 (0)