This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
forked from twitch4j/twitch4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChannelMessageEvent.java
107 lines (95 loc) · 3.67 KB
/
ChannelMessageEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.github.twitch4j.chat.events.channel;
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;
import com.github.twitch4j.common.events.domain.EventChannel;
import com.github.twitch4j.common.events.domain.EventUser;
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.Optional;
import java.util.Set;
/**
* This event gets called when a message is received in a channel.
*/
@Value
@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)
ChatReply replyInfo = ChatReply.parse(getMessageEvent().getTags());
/**
* Information regarding any associated Crowd Chant for this message, if applicable.
*
* @deprecated <a href="https://twitter.com/TwitchSupport/status/1486036628523073539">Will be disabled on 2022-02-02</a>
*/
@Nullable
@Unofficial
@Getter(lazy = true)
@Deprecated
ChatCrowdChant chantInfo = ChatCrowdChant.parse(getMessageEvent());
/**
* 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 ChannelMessageEvent(
EventChannel channel,
IRCMessageEvent messageEvent,
EventUser user, String message,
Set<CommandPermission> permissions
) {
super(channel, messageEvent, user, message, permissions);
}
/**
* @return whether "Highlight My Message" was redeemed for this event
*/
@Unofficial
public boolean isHighlightedMessage() {
return "highlighted-message".equals(getMessageEvent().getTags().get("msg-id"));
}
/**
* @return whether "Send a Message in Sub-Only Mode" was redeemed for this event
*/
@Unofficial
public boolean isSkipSubsModeMessage() {
return "skip-subs-mode-message".equals(getMessageEvent().getTags().get("msg-id"));
}
/**
* @return the id for the custom reward that was redeemed with this associated message, in an optional wrapper
*/
@Unofficial
public Optional<String> getCustomRewardId() {
return getMessageEvent().getTagValue("custom-reward-id");
}
/**
* @return whether this is the user's first message in the channel.
* @apiNote This method is marked as unofficial since this tag does not appear in the irc guide.
* @see <a href="https://help.twitch.tv/s/article/first-time-chatter-highlight">Official documentation</a>
*/
@Unofficial
public boolean isDesignatedFirstMessage() {
return "1".equals(getMessageEvent().getTags().get("first-msg"));
}
/**
* @return whether this message constitutes the user's designated introduction.
* @apiNote This method is unofficial since the experiment is not officially documented in the irc guide.
* @see <a href="https://twitter.com/TwitchSupport/status/1481008097749573641">Twitch Announcement</a>
*/
@Unofficial
public boolean isUserIntroduction() {
return "user-intro".equals(getMessageEvent().getTags().get("msg-id"));
}
}