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: fire chat event for hosts of own channel #357

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public IRCEventHandler(TwitchChat twitchChat) {
eventManager.onEvent("twitch4j-chat-notice-trigger", IRCMessageEvent.class, this::onNoticeEvent);
eventManager.onEvent("twitch4j-chat-host-on-trigger", IRCMessageEvent.class, this::onHostOnEvent);
eventManager.onEvent("twitch4j-chat-host-off-trigger", IRCMessageEvent.class, this::onHostOffEvent);
eventManager.onEvent("twitch4j-chat-inbound-host-trigger", IRCMessageEvent.class, this::onInboundHostEvent);
eventManager.onEvent("twitch4j-chat-list-mods-trigger", IRCMessageEvent.class, this::onListModsEvent);
eventManager.onEvent("twitch4j-chat-list-vips-trigger", IRCMessageEvent.class, this::onListVipsEvent);
eventManager.onEvent("twitch4j-chat-roomstate-trigger", IRCMessageEvent.class, this::onChannelState);
Expand Down Expand Up @@ -510,6 +511,17 @@ public void onHostOffEvent(IRCMessageEvent event) {
}
}

public void onInboundHostEvent(IRCMessageEvent event) {
if ("PRIVMSG".equals(event.getCommandType()) && "jtv".equals(event.getClientName().orElse(null)) && event.getChannelName().isPresent() && event.getRawTags().isEmpty()) {
final String hostMessageSuffix = " is now hosting you.";
event.getMessage()
.map(String::trim)
.filter(msg -> msg.endsWith(hostMessageSuffix))
.map(msg -> msg.substring(0, msg.length() - hostMessageSuffix.length()))
.ifPresent(hostName -> eventManager.publish(new InboundHostEvent(event.getChannelName().get(), hostName)));
}
}

public void onListModsEvent(IRCMessageEvent event) {
if ("NOTICE".equals(event.getCommandType()) && event.getTagValue("msg-id").filter(s -> s.equals("room_mods") || s.equals("no_mods")).isPresent()) {
List<String> names = extractItemsFromDelimitedList(event.getMessage(), "The moderators of this channel are: ", ", ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.twitch4j.chat.events.channel;

import com.github.twitch4j.chat.events.TwitchEvent;
import com.github.twitch4j.common.annotation.Unofficial;
import lombok.EqualsAndHashCode;
import lombok.Value;

/**
* Fired when the authenticated channel to the TwitchChat instance was hosted by another user.
* <p>
* Not officially documented by Twitch so this could stop working at any time.
*/
@Value
@EqualsAndHashCode(callSuper = true)
@Unofficial
public class InboundHostEvent extends TwitchEvent {

/**
* Login name of the channel that was hosted (i.e., the user passed in chatAccount).
*/
String hostTarget;

/**
* Display name of the user that just hosted your channel.
*/
String hosterName;

}