Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: KTX module #516

Merged
merged 15 commits into from May 22, 2022
Merged
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -13,6 +13,6 @@ insert_final_newline = true
trim_trailing_whitespace = false

# Java
[*.java]
[{*.java, *.kt}]
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -40,6 +40,7 @@ Project
* Chat
* PubSub
* GraphQL
* Kotlin

## Problems

Expand Down
@@ -0,0 +1,79 @@
package com.github.twitch4j.chat.events;

import com.github.twitch4j.chat.events.channel.IRCMessageEvent;
import com.github.twitch4j.chat.events.channel.ReplyableEvent;
import com.github.twitch4j.chat.flag.AutoModFlag;
import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.common.enums.CommandPermission;
import com.github.twitch4j.common.events.domain.EventChannel;
import com.github.twitch4j.common.events.domain.EventUser;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Set;

@Data
@Setter(AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false)
public abstract class AbstractChannelMessageEvent extends AbstractChannelEvent implements ReplyableEvent {

/**
* RAW Message Event
*/
private IRCMessageEvent messageEvent;

/**
* User
*/
private EventUser user;

/**
* Message
*/
private String message;

/**
* Permissions of the user
*/
private Set<CommandPermission> permissions;

/**
* The exact number of months the user has been a subscriber, or zero if not subscribed
*/
private int subscriberMonths;

/**
* The tier at which the user is subscribed (prime is treated as 1), or zero if not subscribed
*/
private int subscriptionTier;

/**
* Nonce
*/
@Unofficial
@Getter(lazy = true)
private final String nonce = getMessageEvent().getNonce().orElse(null);

public AbstractChannelMessageEvent(EventChannel channel, IRCMessageEvent messageEvent, EventUser user, String message, Set<CommandPermission> permissions) {
super(channel);
this.messageEvent = messageEvent;
this.user = user;
this.message = message;
this.permissions = permissions;
this.subscriberMonths = messageEvent.getSubscriberMonths().orElse(0);
this.subscriptionTier = messageEvent.getSubscriptionTier().orElse(0);
}

/**
* @return the regions of the message that were flagged by AutoMod.
*/
@Unofficial
public List<AutoModFlag> getFlags() {
return this.getMessageEvent().getFlags();
}

}
@@ -1,80 +1,33 @@
package com.github.twitch4j.chat.events.channel;

import com.github.twitch4j.chat.events.AbstractChannelEvent;
import com.github.twitch4j.chat.flag.AutoModFlag;
import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.chat.events.AbstractChannelMessageEvent;
import com.github.twitch4j.common.enums.CommandPermission;
import com.github.twitch4j.common.events.domain.EventChannel;
import com.github.twitch4j.common.events.domain.EventUser;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Value;

import java.util.List;
import java.util.Set;

/**
* This event gets called when a action message (/me text) is received in a channel.
* This event gets called when an action message (/me text) is received in a channel.
*/
@Value
@Getter
@EqualsAndHashCode(callSuper = false)
public class ChannelMessageActionEvent extends AbstractChannelEvent implements ReplyableEvent {
public class ChannelMessageActionEvent extends AbstractChannelMessageEvent {

/**
* RAW Message Event
*/
private final IRCMessageEvent messageEvent;

/**
* User
*/
private EventUser user;

/**
* Message
*/
private String message;

/**
* Permissions of the user
*/
private Set<CommandPermission> permissions;

/**
* The exact number of months the user has been a subscriber, or zero if not subscribed
*/
private int subscriberMonths;

/**
* The tier at which the user is subscribed (prime is treated as 1), or zero if not subscribed
*/
private int subscriptionTier;

/**
* Event Constructor
*
* @param channel The channel that this event originates from.
* Event Constructor
*
* @param channel The channel that this event originates from.
* @param messageEvent The raw message event
* @param user The user who triggered the event.
* @param message The plain text of the message.
* @param permissions The permissions of the triggering user.
*/
public ChannelMessageActionEvent(EventChannel channel, IRCMessageEvent messageEvent, EventUser user, String message, Set<CommandPermission> permissions) {
super(channel);
this.messageEvent = messageEvent;
this.user = user;
this.message = message;
this.permissions = permissions;
this.subscriberMonths = messageEvent.getSubscriberMonths().orElse(0);
this.subscriptionTier = messageEvent.getSubscriptionTier().orElse(0);
}

/**
* @return the regions of the message that were flagged by AutoMod.
* @param user The user who triggered the event.
* @param message The plain text of the message.
* @param permissions The permissions of the triggering user.
*/
@Unofficial
public List<AutoModFlag> getFlags() {
return this.messageEvent.getFlags();
public ChannelMessageActionEvent(
EventChannel channel,
IRCMessageEvent messageEvent,
EventUser user, String message,
Set<CommandPermission> permissions
) {
super(channel, messageEvent, user, message, permissions);
}

}
@@ -1,7 +1,6 @@
package com.github.twitch4j.chat.events.channel;

import com.github.twitch4j.chat.events.AbstractChannelEvent;
import com.github.twitch4j.chat.flag.AutoModFlag;
import com.github.twitch4j.chat.events.AbstractChannelMessageEvent;
import com.github.twitch4j.chat.util.ChatCrowdChant;
import com.github.twitch4j.common.annotation.Unofficial;
import com.github.twitch4j.common.enums.CommandPermission;
Expand All @@ -10,63 +9,27 @@
import com.github.twitch4j.common.util.ChatReply;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
* This event gets called when a message is received in a channel.
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class ChannelMessageEvent extends AbstractChannelEvent implements ReplyableEvent {

/**
* RAW Message Event
*/
private final IRCMessageEvent messageEvent;

/**
* User
*/
private EventUser user;

/**
* Message
*/
private String message;

/**
* Permissions of the user
*/
private Set<CommandPermission> permissions;

/**
* The exact number of months the user has been a subscriber, or zero if not subscribed
*/
private int subscriberMonths;

/**
* The tier at which the user is subscribed (prime is treated as 1), or zero if not subscribed
*/
private int subscriptionTier;

/**
* Nonce
*/
@Unofficial
@Getter(lazy = true)
private String nonce = getMessageEvent().getNonce().orElse(null);
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ChannelMessageEvent extends AbstractChannelMessageEvent {

/**
* Information regarding the parent message being replied to, if applicable.
*/
@Nullable
@Getter(lazy = true)
private ChatReply replyInfo = ChatReply.parse(getMessageEvent().getTags());
ChatReply replyInfo = ChatReply.parse(getMessageEvent().getTags());

/**
* Information regarding any associated Crowd Chant for this message, if applicable.
Expand All @@ -88,14 +51,13 @@ public class ChannelMessageEvent extends AbstractChannelEvent implements Replyab
* @param message The plain text of the message.
* @param permissions The permissions of the triggering user.
*/
public ChannelMessageEvent(EventChannel channel, IRCMessageEvent messageEvent, EventUser user, String message, Set<CommandPermission> permissions) {
super(channel);
this.messageEvent = messageEvent;
this.user = user;
this.message = message;
this.permissions = permissions;
this.subscriberMonths = messageEvent.getSubscriberMonths().orElse(0);
this.subscriptionTier = messageEvent.getSubscriptionTier().orElse(0);
public ChannelMessageEvent(
EventChannel channel,
IRCMessageEvent messageEvent,
EventUser user, String message,
Set<CommandPermission> permissions
) {
super(channel, messageEvent, user, message, permissions);
}

/**
Expand Down Expand Up @@ -142,12 +104,4 @@ public boolean isUserIntroduction() {
return "user-intro".equals(getMessageEvent().getTags().get("msg-id"));
}

/**
* @return the regions of the message that were flagged by AutoMod.
*/
@Unofficial
public List<AutoModFlag> getFlags() {
return this.messageEvent.getFlags();
}

}
@@ -1,31 +1,26 @@
package com.github.twitch4j.chat.events.channel;

import com.github.twitch4j.chat.events.TwitchEvent;
import com.github.twitch4j.chat.events.AbstractChannelEvent;
import com.github.twitch4j.common.events.domain.EventChannel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;

/**
* This event gets called when the user stops hosting someone.
*/
@Value
@Getter
@EqualsAndHashCode(callSuper = false)
public class HostOffEvent extends TwitchEvent {
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class HostOffEvent extends AbstractChannelEvent {

/**
* Event ChatChannel
*/
private EventChannel channel;

/**
* Event Constructor
*
* @param channel The channel that this event originates from.
*/
public HostOffEvent(EventChannel channel) {
this.channel = channel;
}
/**
* Event Constructor
*
* @param channel The channel that this event originates from.
*/
public HostOffEvent(EventChannel channel) {
super(channel);
}

}