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

Commit f1d9d36

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents ea29aaa + 1083299 commit f1d9d36

File tree

11 files changed

+154
-78
lines changed

11 files changed

+154
-78
lines changed

bootstrap/src/main/scala/Bootstrap.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ object Bootstrap {
3838
println("Found java installation. Starting ChatOverflow...")
3939

4040
// Start chat overflow!
41-
val process = new java.lang.ProcessBuilder(javaPath.get, "-cp", s"bin/*${deps.mkString(File.pathSeparator, File.pathSeparator, "")}", chatOverflowMainClass)
41+
val command = List(javaPath.get, "-cp", s"bin/*${deps.mkString(File.pathSeparator, File.pathSeparator, "")}", chatOverflowMainClass) ++ args
42+
val process = new java.lang.ProcessBuilder(command: _*)
4243
.inheritIO().start()
4344

4445
val exitCode = process.waitFor()

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ libraryDependencies ++= Seq(
8383
libraryDependencies += "com.google.code.gson" % "gson" % "2.8.5"
8484

8585
// JDA
86-
resolvers += "jcenter-bintray" at "http://jcenter.bintray.com"
86+
resolvers += "jcenter-bintray" at "https://jcenter.bintray.com"
8787
libraryDependencies += "net.dv8tion" % "JDA" % "3.8.3_463"
8888

8989
// Serial Communication
@@ -125,7 +125,7 @@ import org.codeoverflow.chatoverflow.build.GUIUtility
125125
import org.codeoverflow.chatoverflow.build.deployment.DeploymentUtility
126126
import org.codeoverflow.chatoverflow.build.plugins.{PluginUtility, PluginCreateWizard}
127127

128-
create := new PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
128+
create := new PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value, PluginCreateWizard.getApiVersion.value)
129129
fetch := new PluginUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
130130
pluginTargetFolderNames.value, apiProjectPath.value)
131131
copy := new PluginUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)

build/src/main/scala/org/codeoverflow/chatoverflow/build/SbtFile.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
102102
}
103103

104104
if (dependencies.nonEmpty) {
105-
sbtContent append "\nresolvers += \"jcenter-bintray\" at \"http://jcenter.bintray.com\"\n"
105+
sbtContent append "\nresolvers += \"jcenter-bintray\" at \"https://jcenter.bintray.com\"\n"
106106

107-
// Note that the %% in the string are required to escape the string formatter and will turn into a single %
108107
val depString = dependencies.map(m => renderModuleID(m)).mkString(" ", ",\n ", "")
109108

110109
sbtContent append s"libraryDependencies ++= Seq(\n$depString\n)\n"
@@ -119,6 +118,7 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
119118
private def renderModuleID(m: ModuleID): String = {
120119
var formatString = ""
121120

121+
// Note that the %% in the string are required to escape the string formatter and will turn into a single %
122122
if (m.crossVersion == CrossVersion.binary)
123123
formatString += "\"%s\" %%%% \"%s\" %% \"%s\""
124124
else

build/src/main/scala/org/codeoverflow/chatoverflow/build/plugins/PluginCreateWizard.scala

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import java.io.File
55
import org.codeoverflow.chatoverflow.build.BuildUtils
66
import org.codeoverflow.chatoverflow.build.BuildUtils.withTaskInfo
77
import org.codeoverflow.chatoverflow.build.plugins.PluginCreateWizard.askForInput
8+
import sbt.Keys._
89
import sbt.internal.util.ManagedLogger
10+
import sbt.{Def, Task}
911

1012
import scala.annotation.tailrec
13+
import scala.util.Try
1114

1215
class PluginCreateWizard(logger: ManagedLogger) {
1316

@@ -16,7 +19,7 @@ class PluginCreateWizard(logger: ManagedLogger) {
1619
*
1720
* @param pluginFolderNames All folder names, containing plugin source code. Defined in build.sbt.
1821
*/
19-
def createPluginTask(pluginFolderNames: List[String]): Unit = {
22+
def createPluginTask(pluginFolderNames: List[String], apiVersion: Option[(Int, Int)]): Unit = {
2023
withTaskInfo("CREATE PLUGIN", logger) {
2124

2225
// Plugin folders have to be defined in the build.sbt file first
@@ -66,12 +69,18 @@ class PluginCreateWizard(logger: ManagedLogger) {
6669

6770
// In case we couldn't figure out the api version, maybe because the api project didn't exist, we ask the user for it.
6871
val api = {
69-
val validate = (s: String) => s.nonEmpty && s.forall(_.isDigit) // not empty and must be a valid number
70-
val major = askForInput("Please specify the current major version of the api. Check api/build.sbt for it.",
72+
// not empty and must be a valid number, can be skipped if a default is available
73+
val validate = (s: String) => s.nonEmpty && s.forall(_.isDigit) || apiVersion.isDefined
74+
val major = askForInput("Please specify the major version of the api. " +
75+
(if (apiVersion.isEmpty) "Check api/build.sbt for it."
76+
else s"Default is the current version (${apiVersion.get._1})."),
7177
"Major api version", validate, "Api version must be a number")
72-
val minor = askForInput("Please specify the current minor version of the api. Check api/build.sbt for it.",
78+
val minor = askForInput(s"Please specify the minor version of the api. " +
79+
(if (apiVersion.isEmpty) "Check api/build.sbt for it."
80+
else s"Default is the current version (${apiVersion.get._2})."),
7381
"Minor api version", validate, "Api version must be a number")
74-
(major.toInt, minor.toInt)
82+
83+
(if (major.isEmpty) apiVersion.get._1 else major.toInt, if (minor.isEmpty) apiVersion.get._2 else minor.toInt)
7584
}
7685

7786
// Plugin metadata
@@ -155,4 +164,28 @@ object PluginCreateWizard {
155164
if (input.isEmpty) default
156165
else input
157166
}
167+
168+
/**
169+
* Gets the version of the api, if loaded by sbt.
170+
*
171+
* @return a tuple with major and minor version
172+
*/
173+
def getApiVersion: Def.Initialize[Task[Option[(Int, Int)]]] = Def.task {
174+
val apiVersion: Option[String] = Def.taskDyn {
175+
val apiProject = buildStructure.value.allProjectRefs.find(_.project == "apiProject")
176+
if (apiProject.isDefined)
177+
Def.task[Option[String]] {
178+
Some((apiProject.get / version).value)
179+
}
180+
else
181+
Def.task[Option[String]] {
182+
None // Api hasn't been loaded, probably not fetched
183+
}
184+
}.value
185+
186+
apiVersion.flatMap(ver => Try {
187+
val parts = ver.split("[.-]") // Also split at '-' to get rid of suffixes like -SNAPSHOT
188+
(parts.head.toInt, parts(1).toInt)
189+
}.toOption)
190+
}
158191
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@ECHO OFF
22

3-
java -jar ChatOverflow.jar
3+
java -jar ChatOverflow.jar %*

deployment-files/end-user/ChatOverflow.command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
called_path=${0%/*}
44
cd $called_path
5-
java -jar ChatOverflow.jar
5+
java -jar ChatOverflow.jar "$@"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
java -jar ChatOverflow.jar
3+
java -jar ChatOverflow.jar "$@"

deployment-files/plugin-dev/build.sbt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
name := "ChatOverflow"
1010
version := "0.3"
1111

12+
// This task has to be overwritten, because sbt will only look in source files for main classes, but the class is in a jar.
13+
Compile / discoveredMainClasses := Seq("org.codeoverflow.chatoverflow.Launcher")
14+
1215
// One version for all sub projects. Use "retrieveManaged := true" to download and show all library dependencies.
1316
val scalaMajorVersion = "2.12"
1417
val scalaMinorVersion = ".5"
@@ -42,9 +45,10 @@ apiProjectPath := "api"
4245

4346
import org.codeoverflow.chatoverflow.build.plugins.{PluginCreateWizard, PluginUtility}
4447

45-
create := new PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
48+
create := new PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value, PluginCreateWizard.getApiVersion.value)
4649
fetch := new PluginUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
4750
pluginTargetFolderNames.value, apiProjectPath.value)
4851
copy := new PluginUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
4952

50-
packageBin / includePom := false
53+
packageBin / includePom := false
54+
fork in run := true // Start ChatOverflow in it's own java process when starting it with 'sbt run'

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/tipeeestream/TipeeestreamConnector.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class TipeeestreamConnector(override val sourceIdentifier: String) extends Event
3535
private def startSocket(): Boolean = {
3636
@volatile var connected: Option[Boolean] = None
3737
val thread = Thread.currentThread
38-
socket = Some(IO.socket(SOCKET_URL).connect())
38+
val url = s"$SOCKET_URL?access_token=${credentials.get.getValue("apiKey").get}"
39+
socket = Some(IO.socket(url).connect())
3940
socket.get.on(Socket.EVENT_CONNECT, (_: Any) => {
4041
logger info "Connected to TipeeeStream Socket.io"
4142
socket.get.emit("join-room", AUTH_OBJECT)
@@ -93,4 +94,7 @@ object TipeeestreamConnector {
9394
private[tipeeestream] case class SubscriptionEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
9495
private[tipeeestream] case class DonationEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
9596
private[tipeeestream] case class FollowEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
97+
private[tipeeestream] case class CheerEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
98+
private[tipeeestream] case class RaidEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
99+
private[tipeeestream] case class HostEventJSON(json: JSONObject) extends TipeeestreamEventJSON(json)
96100
}

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/tipeeestream/TipeeestreamListener.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ class TipeeestreamListener extends EventManager {
1111
val event: JSONObject = json.getJSONObject("event")
1212
val eventType: String = event.getString("type")
1313

14-
val eventOption: Option[TipeeestreamEventJSON] = Option(eventType match {
15-
case "subscription" => SubscriptionEventJSON(event)
16-
case "donation" => DonationEventJSON(event)
17-
case "follow" => FollowEventJSON(event)
18-
case _ => null // gets None if converted to an option
14+
// Fire events for connector if we are looking for that type of event
15+
Option(eventType match {
16+
case "subscription" => call(SubscriptionEventJSON(event))
17+
case "donation" => call(DonationEventJSON(event))
18+
case "superchat" => call(DonationEventJSON(event))
19+
case "follow" => call(FollowEventJSON(event))
20+
case "cheer" => call(CheerEventJSON(event))
21+
case "raid" => call(RaidEventJSON(event))
22+
case "hosting" => call(HostEventJSON(event))
23+
case _ =>
1924
})
20-
21-
if (eventOption.isDefined)
22-
call(eventOption.get) // send event to connector
2325
}
2426
}

0 commit comments

Comments
 (0)