use of me.gloriouseggroll.quorrabot.event.irc.channel.IrcChannelUserModeEvent in project quorrabot by GloriousEggroll.
the class IRCParser method privMsg.
/*
* ----------------------------------------------------------------------
* Event Handling Methods. The below methods are all referenced from the
* parserMap object.
* ----------------------------------------------------------------------
*/
/*
* Handles the PRIVMSG event from IRC.
*
* @param String message
* @param String username
* @param Map<String, String> tagsMap
*/
private void privMsg(String message, String username, Map<String, String> tagsMap) {
/* Check to see if the user is using a ACTION in the channel. (/me) */
if (message.startsWith("\001ACTION")) {
message = message.replaceAll("\001", "").replace("ACTION", "/me");
}
/* Print the IRCv3 tags if debug mode is on*/
com.gmt2001.Console.debug.println("IRCv3 Tags: " + tagsMap);
//Check for JTV notices
if (username.equalsIgnoreCase("jtv")) {
com.gmt2001.Console.debug.println("jtv");
//Check for hosts
if (message.indexOf("host") != -1) {
//com.gmt2001.Console.out.println("host");
String hoster = message.split(" ")[0].toString();
eventBus.post(new TwitchHostedEvent(hoster, this.channel, message));
com.gmt2001.Console.debug.println("Hoster::" + hoster + "::true");
return;
}
//Check for moderators on .mods notice
if (message.indexOf("The moderators of this room are: ") != -1) {
try {
Thread.sleep(2000);
Quorrabot.instance().channelUsersCache.updateCache();
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, this.ownerName.toLowerCase(), "O", true));
String[] moderators = message.substring(33).split(", ");
for (String moderator : moderators) {
if (moderator.equalsIgnoreCase(this.session.getNick())) {
this.session.setAllowSendMessages(true);
}
if (Quorrabot.instance().channelUsersCache.getCache().toString().contains(moderator.toLowerCase() + "=mod")) {
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, moderator.toLowerCase(), "O", true));
}
}
} catch (Exception e) {
//
com.gmt2001.Console.out.println("Error::" + e.toString());
}
return;
}
}
/* Print the parsed message in the console. */
com.gmt2001.Console.out.println(username + ": " + message);
/* Check to see if the users disaplay name. Used in the scripts. */
if (tagsMap.containsKey("display-name")) {
usernameCache.addUser(username, tagsMap.get("display-name"));
com.gmt2001.Console.debug.println("Username::" + username + "::Display-Name::" + tagsMap.get("display-name"));
}
/* Check to see if the user is subscribing to the channel */
if (message.endsWith("subscribed!") || message.endsWith("Prime!")) {
if (username.equalsIgnoreCase("twitchnotify")) {
message = message.split(" ")[0] + " just subscribed!";
com.gmt2001.Console.debug.println(message.split(" ")[0] + " just subscribed!");
}
}
/* Check to see if the user is donating/cheering bits */
if (tagsMap.containsKey("bits")) {
scriptEventManager.runDirect(new NewBits(this.session, this.channel, username, tagsMap.get("bits")));
com.gmt2001.Console.debug.println("Bits::" + username + "::amount::" + tagsMap.get("bits"));
}
/* Check to see if the user is a channel subscriber */
if (tagsMap.containsKey("subscriber")) {
if (tagsMap.get("subscriber").equals("1")) {
eventBus.post(new IrcPrivateMessageEvent(this.session, "jtv", "SPECIALUSER " + username + " subscriber", tagsMap));
com.gmt2001.Console.debug.println("Subscriber::" + username + "::true");
}
}
/* Check to see if the user is a moderator */
if (tagsMap.containsKey("user-type")) {
if (tagsMap.get("user-type").length() > 0) {
if (!moderators.contains(username.toLowerCase())) {
moderators.add(username.toLowerCase());
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, username, "O", true));
com.gmt2001.Console.debug.println("Moderator::" + username + "::true");
}
} else if (this.channelName.equalsIgnoreCase(username)) {
if (!moderators.contains(username.toLowerCase())) {
moderators.add(username.toLowerCase());
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, username, "O", true));
com.gmt2001.Console.debug.println("Broadcaster::" + username + "::true");
}
}
}
if (!username.equalsIgnoreCase("jtv") && !username.equalsIgnoreCase("twitchnotify") && !this.session.getNick().equalsIgnoreCase(this.session.getOwner())) {
if (message.startsWith("!")) {
String command;
String argsString;
if (message.indexOf(" ") == -1) {
command = message.substring(1, message.length());
argsString = "";
} else {
command = message.substring(1, message.indexOf(" "));
argsString = message.substring(message.indexOf(" ") + 1);
}
Quorrabot.handleCommand(username, message.substring(1), tagsMap, this.channel, this.ownerName);
//EventBus.instance().post(new CommandEvent(username, command, argsString, tagsMap, this.channel));
return;
}
}
/* Moderate the incoming message. Have it run in the background on a thread. */
if (!this.session.getNick().equalsIgnoreCase(this.ownerName)) {
try {
ModerationRunnable moderationRunnable = new ModerationRunnable(this.session, username, message, this.channel, tagsMap);
new Thread(moderationRunnable).start();
} catch (Exception ex) {
scriptEventManager.runDirect(new IrcModerationEvent(this.session, username, message, this.channel, tagsMap));
}
/* Send the message to the scripts. */
eventBus.post(new IrcChannelMessageEvent(this.session, username, message, this.channel, tagsMap));
}
/* Incrememnt the chat lines, this should be the last operation of this function. */
this.session.chatLinesIncr();
}
use of me.gloriouseggroll.quorrabot.event.irc.channel.IrcChannelUserModeEvent in project quorrabot by GloriousEggroll.
the class IRCParser method userState.
/*
* Handles the USERSTATE event from IRC.
*
* @param Map<String, String> tagsMap
*/
private void userState(Map<String, String> tagMaps) {
if (tagMaps.containsKey("user-type")) {
if (tagMaps.get("user-type").length() > 0) {
if (!moderators.contains(this.session.getNick())) {
moderators.add(this.session.getNick());
com.gmt2001.Console.debug.println("Bot::" + this.session.getNick() + "::Moderator::true");
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, this.session.getNick(), "O", true));
}
} else if (this.channelName.equalsIgnoreCase(this.session.getNick())) {
if (!moderators.contains(this.session.getNick())) {
moderators.add(this.session.getNick());
com.gmt2001.Console.debug.println("Caster::Bot::" + this.session.getNick() + "::Moderator::true");
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, this.session.getNick(), "O", true));
}
} else {
com.gmt2001.Console.out.println();
com.gmt2001.Console.out.println("[ERROR] " + this.session.getNick() + " is not detected as a moderator!");
com.gmt2001.Console.out.println("[ERROR] You must add " + this.session.getNick() + " as a channel moderator for it to chat.");
com.gmt2001.Console.out.println("[ERROR] Type /mod " + this.session.getNick() + " to add " + this.session.getNick() + " as a channel moderator.");
com.gmt2001.Console.out.println();
//session.setAllowSendMessages(false);
if (moderators.contains(this.session.getNick())) {
moderators.remove(this.session.getNick());
com.gmt2001.Console.debug.println("Bot::" + this.session.getNick() + "::Moderator::false");
eventBus.post(new IrcChannelUserModeEvent(this.session, this.channel, this.session.getNick(), "O", false));
}
}
}
}
Aggregations