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

Commit 9fab117

Browse files
committed
Added new typesafe requirements. Updated prototype plugin implementation. Started work on framework side requirement resolution.
1 parent 856f41a commit 9fab117

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
1-
import org.codeoverflow.chatoverflow.api.io.input.chat.TwitchChatInput
2-
import org.codeoverflow.chatoverflow.api.plugin.configuration.{ParameterRequirement, Requirements, SourceRequirement}
1+
import org.codeoverflow.chatoverflow.api.plugin.configuration.Requirements
32
import org.codeoverflow.chatoverflow.api.plugin.{Plugin, PluginManager}
43

54
class simpletestPlugin(manager: PluginManager) extends Plugin {
65

7-
// TODO: Better?
8-
// val x: Requirement[TwitchChatInput] = config.requireTwitchChatInput("inputReq", "Twitch Channel")
9-
10-
val config = new Requirements
11-
12-
// VERSION A (Objektorientiert. Vorteil: Typsicher. Nachteil: Für jeden Input/Output eigene Methode in API)
13-
private val twitchChat = config.requireTwitchChatInput("inputReq", "A Twitch channel")
14-
twitchChat.getSource.getLastMessages(1000)
15-
16-
// VERSION B (Durch Reflection aufgelöst, Vorteil: Leicht erweiterbar, Nachteil: Nicht typsicher)
17-
//private val twitchChat2 = config.require(Class[TwitchChatInput], "inputReq2", "A twitch channel")
18-
//twitchChat2.getSource.asInstanceOf[TwitchChatInput].getLastMessages(1000)
19-
20-
21-
config.addInputRequirement("Twitch Channel", new SourceRequirement[TwitchChatInput]("input"))
22-
config.addParameterRequirement("Some name", new ParameterRequirement[String]("helloReq"))
6+
private val require = new Requirements
7+
private val twitchChatInput = require.input.requireTwitchChatInput("reqTwitch", "A twitch channel", false)
8+
private val nameToSayHelloTo = require.parameter.requireString("reqHello", "Your name", true)
239

2410
override def start(): Unit = {
2511
println("Started successfully!")
2612
println(s"Dummy message is:${manager.getDummyMessage}")
2713

28-
val chatInput = config.getInputRequirement("Twitch Channel").getSource.asInstanceOf[TwitchChatInput]
29-
chatInput.registerMessageHandler(msg => println(msg))
14+
twitchChatInput.getValue.registerMessageHandler(msg => println(msg))
3015

31-
println(s"Param: ${config.getParameterRequirement("Some name").getParameter}")
16+
println(s"Hello ${nameToSayHelloTo.getValue}!")
3217

3318
while (true) {
3419
Thread.sleep(10)
3520
}
3621
}
3722

38-
override def getRequirements: Requirements = config
23+
override def getRequirements: Requirements = require
3924
}

0 commit comments

Comments
 (0)