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

Commit 6ee105c

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 0cdbf49 + b0bb721 commit 6ee105c

26 files changed

+477
-448
lines changed

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ libraryDependencies += "net.dv8tion" % "JDA" % "3.8.3_463"
6464
//Serial Communication
6565
libraryDependencies += "com.fazecast" % "jSerialComm" % "[2.0.0,3.0.0)"
6666

67+
// Socket.io
68+
libraryDependencies += "io.socket" % "socket.io-client"% "1.0.0"
6769
// ---------------------------------------------------------------------------------------------------------------------
6870
// PLUGIN FRAMEWORK DEFINITIONS
6971
// ---------------------------------------------------------------------------------------------------------------------
@@ -84,7 +86,7 @@ lazy val deploy = TaskKey[Unit]("deploy", "Prepares the environment for deployme
8486
lazy val gui = TaskKey[Unit]("gui", "Installs GUI dependencies and builds it using npm.")
8587

8688
pluginBuildFileName := "plugins.sbt"
87-
pluginFolderNames := List("plugins-public")
89+
pluginFolderNames := List("plugins-public", "plugins-private")
8890
pluginTargetFolderNames := List("plugins", s"target/scala-$scalaMajorVersion/plugins")
8991
apiProjectPath := "api"
9092
guiProjectPath := "gui"

src/main/scala/org/codeoverflow/chatoverflow/configuration/CryptoUtil.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.codeoverflow.chatoverflow.configuration
22

33
import java.nio.charset.StandardCharsets
4-
import java.security.{DigestException, MessageDigest, SecureRandom}
4+
import java.security.{DigestException, InvalidKeyException, MessageDigest, SecureRandom}
55
import java.util
66
import java.util.Base64
77

88
import javax.crypto.spec.{IvParameterSpec, PBEKeySpec, SecretKeySpec}
99
import javax.crypto.{Cipher, SecretKeyFactory}
10+
import org.codeoverflow.chatoverflow.WithLogger
1011

1112
/**
1213
* Provides methods to de- and encrypt using the AES-CBC algorithm.
@@ -15,7 +16,7 @@ import javax.crypto.{Cipher, SecretKeyFactory}
1516
* The SSL compliant / crypto-js compliant code is based on
1617
* https://stackoverflow.com/questions/41432896/cryptojs-aes-encryption-and-java-aes-decryption
1718
*/
18-
object CryptoUtil {
19+
object CryptoUtil extends WithLogger {
1920

2021
// Used for the run-unique auth key
2122
private val runSpecificRandom = generateIV
@@ -65,6 +66,9 @@ object CryptoUtil {
6566
Some(decrString.substring(5))
6667
}
6768
} catch {
69+
case e: InvalidKeyException => logger.error("Your environment does not work with AES256." +
70+
"Please update your java runtime version to at least: 1.8.0_161", e)
71+
None
6872
case _: Exception => None
6973
}
7074
}
@@ -143,6 +147,13 @@ object CryptoUtil {
143147
new String(Base64.getEncoder.encode(message), StandardCharsets.UTF_8)
144148
}
145149

150+
private def generateSalt: Array[Byte] = {
151+
val random = new SecureRandom()
152+
val salt = new Array[Byte](8)
153+
random.nextBytes(salt)
154+
salt
155+
}
156+
146157
/**
147158
* Encrypts the provided plaintext using AES.
148159
*
@@ -173,13 +184,6 @@ object CryptoUtil {
173184
ciphertext.toString
174185
}
175186

176-
private def generateSalt: Array[Byte] = {
177-
val random = new SecureRandom()
178-
val salt = new Array[Byte](8)
179-
random.nextBytes(salt)
180-
salt
181-
}
182-
183187
private def generateIV: Array[Byte] = {
184188
val random = new SecureRandom()
185189
val iv = new Array[Byte](16)

src/main/scala/org/codeoverflow/chatoverflow/instance/PluginInstance.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ class PluginInstance(val instanceName: String, pluginType: PluginType) extends W
182182

183183
// If the plugin ended or crashed, try to shut down the connectors
184184
val inputRequirements = getRequirements.getInputRequirements.toArray
185-
inputRequirements.foreach(requirement => {
185+
inputRequirements.filter(_.asInstanceOf[Requirement[_]].isSet).foreach(requirement => {
186186
requirement.asInstanceOf[Requirement[Input]].get().shutdown()
187187
})
188188

189189
val outputRequirements = getRequirements.getOutputRequirements.toArray
190-
outputRequirements.foreach(requirement => {
190+
outputRequirements.filter(_.asInstanceOf[Requirement[_]].isSet).foreach(requirement => {
191191
requirement.asInstanceOf[Requirement[Output]].get().shutdown()
192192
})
193193

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.codeoverflow.chatoverflow.requirement.impl
2+
3+
import java.util.function.Consumer
4+
5+
import org.codeoverflow.chatoverflow.api.io.event.Event
6+
7+
private[impl] case class EventHandler[T <: Event](consumer: Consumer[T], clazz: Class[T])
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.codeoverflow.chatoverflow.requirement.impl
2+
3+
import java.util.function.Consumer
4+
5+
import org.codeoverflow.chatoverflow.api.io.event.Event
6+
import org.codeoverflow.chatoverflow.api.io.input.event.EventInput
7+
import org.codeoverflow.chatoverflow.connector.Connector
8+
9+
import scala.collection.mutable.ListBuffer
10+
import scala.reflect.ClassTag
11+
12+
/**
13+
* Default implementation for all inputs that provide events.
14+
*
15+
* The integrated event registry allows registering new Event handlers at any time.
16+
* @tparam T the event interface that all events for this EventInput share
17+
* @tparam C the connector to which this input belongs
18+
*/
19+
abstract class EventInputImpl[T <: Event, C <: Connector](implicit ctc: ClassTag[C]) extends InputImpl[C] with EventInput[T] {
20+
21+
protected val handlers: ListBuffer[EventHandler[_ <: T]] = ListBuffer[EventHandler[_ <: T]]()
22+
23+
/**
24+
* Register a new event handler that listens for a specific event
25+
*
26+
* @param eventHandler consumer for which `accept()` is called if the event is fired
27+
* @param eventClass class of the events for which this listener should listen
28+
*/
29+
override def registerEventHandler[S <: T](eventHandler: Consumer[S], eventClass: Class[S]): Unit = {
30+
handlers += EventHandler[S](eventHandler, eventClass)
31+
}
32+
33+
/**
34+
* Use this methods to fire an event.
35+
* All eventHandlers listening for that event will be triggered.
36+
* @param event the event that should be fired
37+
*/
38+
protected def call[S <: T](event: S)(implicit cts: ClassTag[S]): Unit = {
39+
handlers.filter(handler => handler.clazz == cts.runtimeClass)
40+
.foreach(handler => handler.consumer.asInstanceOf[Consumer[S]].accept(event))
41+
}
42+
}

src/main/scala/org/codeoverflow/chatoverflow/requirement/InputImpl.scala renamed to src/main/scala/org/codeoverflow/chatoverflow/requirement/impl/InputImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package org.codeoverflow.chatoverflow.requirement
1+
package org.codeoverflow.chatoverflow.requirement.impl
22

33
import org.codeoverflow.chatoverflow.WithLogger
44
import org.codeoverflow.chatoverflow.api.io.input.Input
55
import org.codeoverflow.chatoverflow.connector.Connector
6+
import org.codeoverflow.chatoverflow.requirement.Connection
67

78
import scala.reflect.ClassTag
89

src/main/scala/org/codeoverflow/chatoverflow/requirement/OutputImpl.scala renamed to src/main/scala/org/codeoverflow/chatoverflow/requirement/impl/OutputImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package org.codeoverflow.chatoverflow.requirement
1+
package org.codeoverflow.chatoverflow.requirement.impl
22

33
import org.codeoverflow.chatoverflow.WithLogger
44
import org.codeoverflow.chatoverflow.api.io.output.Output
55
import org.codeoverflow.chatoverflow.connector.Connector
6+
import org.codeoverflow.chatoverflow.requirement.Connection
67

78
import scala.reflect.ClassTag
89

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/discord/DiscordChatConnector.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class DiscordChatConnector(override val sourceIdentifier: String) extends Connec
101101
case None =>
102102
Option(validJDA.getPrivateChannelById(channelId)) match {
103103
case Some(channel) => channel.getMessageById(messageId)
104-
case None => throw new IllegalArgumentException(s"Channel with id $channelId not found")
104+
case None => throw new IllegalArgumentException(s"TextChannel with id $channelId not found")
105105
}
106106
}
107107
}
@@ -123,7 +123,7 @@ class DiscordChatConnector(override val sourceIdentifier: String) extends Connec
123123
def sendChatMessage(channelId: String, chatMessage: String): Unit = {
124124
Option(validJDA.getTextChannelById(channelId)) match {
125125
case Some(channel) => channel.sendMessage(chatMessage).queue(null, defaultFailureHandler)
126-
case None => throw new IllegalArgumentException(s"Channel with id $channelId not found")
126+
case None => throw new IllegalArgumentException(s"TextChannel with id $channelId not found")
127127
}
128128
}
129129

@@ -136,7 +136,7 @@ class DiscordChatConnector(override val sourceIdentifier: String) extends Connec
136136
def sendChatMessage(channelId: String, embed: MessageEmbed): Unit = {
137137
Option(validJDA.getTextChannelById(channelId)) match {
138138
case Some(channel) => channel.sendMessage(embed).queue(null, defaultFailureHandler)
139-
case None => throw new IllegalArgumentException(s"Channel with id $channelId not found")
139+
case None => throw new IllegalArgumentException(s"TextChannel with id $channelId not found")
140140
}
141141
}
142142

@@ -157,7 +157,7 @@ class DiscordChatConnector(override val sourceIdentifier: String) extends Connec
157157
case Some(m) => channel.sendFile(fileIn.get.get, fileName, new MessageBuilder(m).build()).queue(null, defaultFailureHandler)
158158
case None => channel.sendFile(fileIn.get.get, fileName).queue(null, defaultFailureHandler)
159159
}
160-
case None => throw new IllegalArgumentException(s"Channel with id $channelId not found")
160+
case None => throw new IllegalArgumentException(s"TextChannel with id $channelId not found")
161161
}
162162
} else {
163163
logger warn s"Could not load file '$file'"

0 commit comments

Comments
 (0)