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
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,68 @@
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.Getter;
import lombok.experimental.FieldDefaults;

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

@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public abstract class AbstractChannelMessageEvent 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;


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,55 +1,16 @@
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 {

/**
* 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;
public class ChannelMessageActionEvent extends AbstractChannelMessageEvent {

/**
* Event Constructor
Expand All @@ -60,21 +21,12 @@ public class ChannelMessageActionEvent extends AbstractChannelEvent implements R
* @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);
public ChannelMessageActionEvent(
EventChannel channel,
IRCMessageEvent messageEvent,
EventUser user, String message,
Set<CommandPermission> permissions
) {
super(channel, messageEvent, user, message, permissions);
}

/**
* @return the regions of the message that were flagged by AutoMod.
*/
@Unofficial
public List<AutoModFlag> getFlags() {
return this.messageEvent.getFlags();
}
}
@@ -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 @@ -13,7 +12,6 @@
import lombok.Value;
import org.jetbrains.annotations.Nullable;

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

Expand All @@ -22,37 +20,7 @@
*/
@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;
public class ChannelMessageEvent extends AbstractChannelMessageEvent {

/**
* Nonce
Expand Down Expand Up @@ -85,14 +53,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 @@ -138,13 +105,4 @@ public boolean isDesignatedFirstMessage() {
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();
}

}
31 changes: 31 additions & 0 deletions kotlin/build.gradle.kts
@@ -0,0 +1,31 @@
// In this section you declare the dependencies for your production and test code
dependencies {
val versionKotlin = "1.6.0"
PhilippHeuer marked this conversation as resolved.
Show resolved Hide resolved

// Twitch4J Modules
// We use compileOnly so using this library does not require all modules.
// This does mean that using code that references modules not available will crash.
// This shouldn't be an issue as most, if not all, code are extension functions.
compileOnly(project(":twitch4j"))

// Kotlin coroutines
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = versionKotlin)
testImplementation(group = "org.jetbrains.kotlinx", name="kotlinx-coroutines-test", version = versionKotlin)
testImplementation(project(":twitch4j"))
}

tasks.javadoc {
options {
title = "Twitch4J (v${version}) - Kotlin extension functions"
windowTitle = "Twitch4J (v${version}) - Kotlin extension functions"
}
}

publishing.publications.withType<MavenPublication> {
pom {
name.set("Twitch4J API - Kotlin extension functions")
description.set("Twitch4J Kotlin extension functions")
}
}