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

Commit 35d8dbe

Browse files
committed
Add initial StreamElements implementation
1 parent e8ad9bb commit 35d8dbe

File tree

10 files changed

+221
-0
lines changed

10 files changed

+221
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.User;
4+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.Donation;
5+
6+
import java.time.OffsetDateTime;
7+
import java.util.Currency;
8+
9+
/**
10+
* A donation for the streamer at StreamElements
11+
*/
12+
public class StreamElementsDonation extends Donation<User> {
13+
private final String donationMessage;
14+
15+
public StreamElementsDonation(User donor, float amount, Currency currency, OffsetDateTime time, String donationMessage) {
16+
super(donor, amount, currency, time);
17+
this.donationMessage = donationMessage;
18+
}
19+
20+
/**
21+
* Get the message that a user included in his donation
22+
*
23+
* @return the donation message
24+
*/
25+
public String getDonationMessage() {
26+
return donationMessage;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.User;
4+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.Follow;
5+
6+
import java.time.OffsetDateTime;
7+
8+
/**
9+
* A follow that is reported by StreamElements.
10+
*/
11+
public class StreamElementsFollow extends Follow<User> {
12+
13+
private final StreamElementsProvider provider;
14+
15+
public StreamElementsFollow(User follower, OffsetDateTime time, StreamElementsProvider provider) {
16+
super(follower, time);
17+
this.provider = provider;
18+
}
19+
20+
public StreamElementsProvider getProvider() {
21+
return provider;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements;
2+
3+
4+
import java.util.Arrays;
5+
6+
/**
7+
* The streaming provider from which a StreamElements event is originated. Either Twitch or Youtube.
8+
*/
9+
public enum StreamElementsProvider {
10+
// StreamElements only supports Twitch and Youtube
11+
TWITCH,
12+
YOUTUBE;
13+
14+
@Override
15+
public String toString() {
16+
return name().toLowerCase();
17+
}
18+
19+
/**
20+
* Parse the provider from a string
21+
* @param provider string with the providers name
22+
* @return the provider for that string or null, if it doesn't exists.
23+
*/
24+
public static StreamElementsProvider parse(String provider) {
25+
return Arrays.stream(values()).filter(p -> p.toString().equals(provider.trim().toLowerCase())).findAny().orElse(null);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.User;
4+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.Subscription;
5+
6+
import java.time.OffsetDateTime;
7+
8+
/**
9+
* A subscription to the channel of the streamer that is reported by StreamElements.
10+
*/
11+
public class StreamElementsSubscription extends Subscription<User> {
12+
13+
private final StreamElementsProvider provider;
14+
private final boolean gifted;
15+
16+
public StreamElementsSubscription(User subscriber, int resub, OffsetDateTime time, StreamElementsProvider provider, boolean gifted) {
17+
super(subscriber, resub, time);
18+
this.provider = provider;
19+
this.gifted = gifted;
20+
}
21+
22+
public StreamElementsProvider getProvider() {
23+
return provider;
24+
}
25+
26+
public boolean isGifted() {
27+
return gifted;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.codeoverflow.chatoverflow.api.io.event.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements.StreamElementsDonation;
4+
import org.codeoverflow.chatoverflow.api.io.event.stream.DonationEvent;
5+
6+
/**
7+
* A event that is triggered if a user donates on StreamElements.
8+
*/
9+
public class StreamElementsDonationEvent extends DonationEvent<StreamElementsDonation> implements StreamElementsEvent {
10+
public StreamElementsDonationEvent(StreamElementsDonation donationInfo) {
11+
super(donationInfo);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.codeoverflow.chatoverflow.api.io.event.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.event.Event;
4+
5+
/**
6+
* Common interface between all StreamElements events.
7+
*/
8+
public interface StreamElementsEvent extends Event {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.codeoverflow.chatoverflow.api.io.event.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements.StreamElementsFollow;
4+
import org.codeoverflow.chatoverflow.api.io.event.stream.FollowEvent;
5+
6+
/**
7+
* Event that is triggered by StreamElements if a user starts following your channel.
8+
*/
9+
public class StreamElementsFollowEvent extends FollowEvent<StreamElementsFollow> implements StreamElementsEvent {
10+
public StreamElementsFollowEvent(StreamElementsFollow info) {
11+
super(info);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.codeoverflow.chatoverflow.api.io.event.stream.streamelements;
2+
3+
import org.codeoverflow.chatoverflow.api.io.dto.stat.stream.streamelements.StreamElementsSubscription;
4+
import org.codeoverflow.chatoverflow.api.io.event.stream.SubscriptionEvent;
5+
6+
/**
7+
* A event that is triggered by StreamElements if a users subscribes your channel.
8+
*/
9+
public class StreamElementsSubscriptionEvent extends SubscriptionEvent<StreamElementsSubscription> implements StreamElementsEvent {
10+
public StreamElementsSubscriptionEvent(StreamElementsSubscription info) {
11+
super(info);
12+
}
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.codeoverflow.chatoverflow.api.io.input.event;
2+
3+
import org.codeoverflow.chatoverflow.api.IsRequirement;
4+
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.StreamElementsDonationEvent;
5+
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.StreamElementsEvent;
6+
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.StreamElementsFollowEvent;
7+
import org.codeoverflow.chatoverflow.api.io.event.stream.streamelements.StreamElementsSubscriptionEvent;
8+
9+
import java.util.function.Consumer;
10+
11+
/**
12+
* A Input which allows you to add event handlers for various StreamElements related events like donations.
13+
*/
14+
@IsRequirement(requires = "access to the StreamElements api", methodName = "streamElements")
15+
public interface StreamElementsEventInput extends EventInput<StreamElementsEvent> {
16+
17+
/**
18+
* Register an event handler that listens to all {@link StreamElementsSubscriptionEvent}
19+
*
20+
* @param eventHandler consumer that receives the Events
21+
*/
22+
default void registerSubscriptionEventHandler(Consumer<StreamElementsSubscriptionEvent> eventHandler) {
23+
registerEventHandler(eventHandler, StreamElementsSubscriptionEvent.class);
24+
}
25+
26+
/**
27+
* Register an event handler that listens to all {@link StreamElementsFollowEvent}
28+
*
29+
* @param eventHandler consumer that receives the Events
30+
*/
31+
default void registerFollowEventHandler(Consumer<StreamElementsFollowEvent> eventHandler) {
32+
registerEventHandler(eventHandler, StreamElementsFollowEvent.class);
33+
}
34+
35+
/**
36+
* Register an event handler that listens to all {@link StreamElementsDonationEvent}
37+
*
38+
* @param eventHandler consumer that receives the Events
39+
*/
40+
default void registerDonationEventHandler(Consumer<StreamElementsDonationEvent> eventHandler) {
41+
registerEventHandler(eventHandler, StreamElementsDonationEvent.class);
42+
}
43+
}

src/main/java/org/codeoverflow/chatoverflow/api/plugin/configuration/Input.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.codeoverflow.chatoverflow.api.io.input.SerialInput;
88
import org.codeoverflow.chatoverflow.api.io.input.chat.DiscordChatInput;
99
import org.codeoverflow.chatoverflow.api.io.input.chat.TwitchChatInput;
10+
import org.codeoverflow.chatoverflow.api.io.input.event.StreamElementsEventInput;
1011
import org.codeoverflow.chatoverflow.api.io.input.event.TipeeestreamEventInput;
1112

1213
// THIS FILE IS GENERATED WHILE COMPILING. DO NOT CHANGE ANYTHING HERE!
@@ -132,6 +133,28 @@ public Requirement<TwitchChatInput> twitchChat(String uniqueRequirementId) {
132133
return requirements.requireInput(uniqueRequirementId, "Twitch Chat", false, TwitchChatInput.class);
133134
}
134135

136+
/**
137+
* Requires a access to the StreamElements api which has to be specified by the user.
138+
*
139+
* @param uniqueRequirementId a plugin unique identifier which is stored for your plugin
140+
* @param displayName a string to display to the user while setting your requirement
141+
* @param isOptional true if this requirement is optional, false if mandatory
142+
* @return the requirement object. Use the get() method only at runtime!
143+
*/
144+
public Requirement<StreamElementsEventInput> streamElements(String uniqueRequirementId, String displayName, boolean isOptional) {
145+
return requirements.requireInput(uniqueRequirementId, displayName, isOptional, StreamElementsEventInput.class);
146+
}
147+
148+
/**
149+
* Requires a access to the StreamElements api which has to be specified by the user.
150+
*
151+
* @param uniqueRequirementId a plugin unique identifier which is stored for your plugin
152+
* @return the requirement object. Use the get() method only at runtime!
153+
*/
154+
public Requirement<StreamElementsEventInput> streamElements(String uniqueRequirementId) {
155+
return requirements.requireInput(uniqueRequirementId, "Stream Elements Event", false, StreamElementsEventInput.class);
156+
}
157+
135158
/**
136159
* Requires a login for the TipeeeStream api which has to be specified by the user.
137160
*

0 commit comments

Comments
 (0)