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

Commit d5c2816

Browse files
committed
Add hosts, raids and cheer events to StreamElements
1 parent b75cbf2 commit d5c2816

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/streamelements/StreamElementsConnector.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@ object StreamElementsConnector {
9797
private[streamelements] case class SubscriptionEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
9898
private[streamelements] case class DonationEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
9999
private[streamelements] case class FollowEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
100+
private[streamelements] case class CheerEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
101+
private[streamelements] case class HostEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
102+
private[streamelements] case class RaidEventJSON(json: JSONObject) extends StreamElementsEventJSON(json)
100103
}

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/streamelements/StreamElementsListener.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class StreamElementsListener extends EventManager {
3131
case "subscription" => call(SubscriptionEventJSON(json))
3232
case "tip" => call(DonationEventJSON(json))
3333
case "follow" => call(FollowEventJSON(json))
34+
case "cheer" => call(CheerEventJSON(json))
35+
case "host" => call(HostEventJSON(json))
36+
case "raid" => call(RaidEventJSON(json))
3437
case _ =>
3538
}
3639
}

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/streamelements/impl/StreamElementsEventInputImpl.scala

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import java.util.Currency
66

77
import org.codeoverflow.chatoverflow.api.io.dto.User
88
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.SubscriptionTier
9-
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements.{StreamElementsDonation, StreamElementsFollow, StreamElementsProvider, StreamElementsSubscription}
10-
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.{StreamElementsDonationEvent, StreamElementsEvent, StreamElementsFollowEvent, StreamElementsSubscriptionEvent}
9+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements._
10+
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements._
1111
import org.codeoverflow.chatoverflow.api.io.input.event.StreamElementsEventInput
1212
import org.codeoverflow.chatoverflow.registry.Impl
1313
import org.codeoverflow.chatoverflow.requirement.impl.EventInputImpl
@@ -24,6 +24,9 @@ class StreamElementsEventInputImpl extends EventInputImpl[StreamElementsEvent, S
2424
sourceConnector.get.registerEventHandler(handleExceptions(onFollow))
2525
sourceConnector.get.registerEventHandler(handleExceptions(onSubscription))
2626
sourceConnector.get.registerEventHandler(handleExceptions(onDonation))
27+
sourceConnector.get.registerEventHandler(handleExceptions(onCheer))
28+
sourceConnector.get.registerEventHandler(handleExceptions(onRaid))
29+
sourceConnector.get.registerEventHandler(handleExceptions(onHost))
2730
true
2831
}
2932

@@ -84,19 +87,58 @@ class StreamElementsEventInputImpl extends EventInputImpl[StreamElementsEvent, S
8487
data.getDouble("amount").toFloat,
8588
Currency.getInstance(data.getString("currency")),
8689
parseTime(json),
87-
data.getString("message")
90+
data.optString("message")
8891
)
8992
call(new StreamElementsDonationEvent(donation))
9093
}
9194

95+
private def onCheer(event: CheerEventJSON): Unit = {
96+
val json = event.json
97+
val data = json.getJSONObject("data")
98+
99+
val cheer = new StreamElementsCheer(
100+
parseUser(data),
101+
data.getInt("amount"),
102+
data.optString("message"),
103+
parseTime(json)
104+
)
105+
call(new StreamElementsCheerEvent(cheer))
106+
}
107+
108+
private def onRaid(event: RaidEventJSON): Unit = {
109+
val json = event.json
110+
val data = json.getJSONObject("data")
111+
112+
val raid = new StreamElementsRaid(
113+
parseUser(data),
114+
data.optString("message"),
115+
data.getInt("amount"),
116+
parseTime(json)
117+
)
118+
call(new StreamElementsRaidEvent(raid))
119+
}
120+
121+
private def onHost(event: HostEventJSON): Unit = {
122+
val json = event.json
123+
val data = json.getJSONObject("data")
124+
125+
val host = new StreamElementsHost(
126+
parseUser(data),
127+
data.optString("message"),
128+
data.getInt("amount"),
129+
parseTime(json)
130+
)
131+
call(new StreamElementsHostEvent(host))
132+
}
133+
92134
override def stop(): Boolean = {
93135
sourceConnector.get.unregisterAllEventListeners
94136
true
95137
}
96138

97139
// Common methods for JSON processing:
98140

99-
private def parseProvider(json: JSONObject): StreamElementsProvider = StreamElementsProvider.parse(json.getString("provider"))
141+
private def parseProvider(json: JSONObject): StreamElementsProvider = StreamElementsProvider.parse(json.optString("provider"))
100142

101143
private def parseUser(json: JSONObject): User = {
102144
val username = json.getString("username")

0 commit comments

Comments
 (0)