private static bool verifyCommand(TwitchLib.TwitchChatClient.OnCommandReceivedArgs e) { TwitchLib.ChatMessage.UType userType = e.ChatMessage.UserType; if (Common.Moderators.Contains(e.ChatMessage.Username.ToLower())) { userType = TwitchLib.ChatMessage.UType.Moderator; } if (!Common.Cooldown.chatCommandAvailable(userType, e.Command, 10)) { return(false); } if (!Common.isSub(e)) { return(false); } if (e.ArgumentsAsList.Count == 0) { return(false); } if (Common.DryRun) { return(false); } return(true); }
// Determine if sender of command is moderator public static bool isMod(TwitchLib.TwitchChatClient.OnCommandReceivedArgs e) { TwitchLib.ChatMessage.UType UType = e.ChatMessage.UserType; if (Moderators.Contains(e.ChatMessage.Username)) { return(true); } else { return(false); } }
// Determine if sender of command is a sub public static bool isSub(TwitchLib.TwitchChatClient.OnCommandReceivedArgs e) { TwitchLib.ChatMessage.UType UType = e.ChatMessage.UserType; if (UType == TwitchLib.ChatMessage.UType.Admin || UType == TwitchLib.ChatMessage.UType.GlobalModerator || UType == TwitchLib.ChatMessage.UType.Moderator || UType == TwitchLib.ChatMessage.UType.Staff || e.ChatMessage.Subscriber || Moderators.Contains(e.ChatMessage.Username.ToLower()) || e.ChatMessage.Username.ToLower() == "swiftyspiffy") { return(true); } else { return(false); } }
// Checks availability of chat command, and resets cooldown if available public bool chatCommandAvailable(TwitchLib.ChatMessage.UType userType, string command, int seconds) { if (seconds != 0 && userType != TwitchLib.ChatMessage.UType.Moderator) { foreach (CommandCooldown cooldown in cooldowns) { if (cooldown.Command.ToLower() == command.ToLower()) { return(cooldown.activate()); } } cooldowns.Add(new CommandCooldown(command, seconds)); } return(true); }
// Handles all chat commands (chat messages that have ! prefix) from event public static void handleChatCommand(TwitchLib.TwitchChatClient.OnCommandReceivedArgs command) { switch (command.Command) { case "drink": // Intentionally fall through case "drinking": HardCodedChatCommands.Drink.handleCommand(command); break; case "500": HardCodedChatCommands._500.handleCommand(command); break; case "killgiveaway": HardCodedChatCommands.Raffle.KillGiveaway.handleCommand(command); break; case "giveawaykill": HardCodedChatCommands.Raffle.KillGiveaway.handleCommand(command); break; case "games": HardCodedChatCommands.Games.handleCommand(command); break; case "pick": HardCodedChatCommands.Pick.handleCommand(command); break; case "kappa": HardCodedChatCommands.Kappa.handleCommand(command); break; case "dc": HardCodedChatCommands.DeathCount.handleCommand(command); break; case "deathcount": HardCodedChatCommands.DeathCount.handleCommand(command); break; case "hc": HardCodedChatCommands.HitCount.handleCommand(command); break; case "hitcount": HardCodedChatCommands.HitCount.handleCommand(command); break; case "notifyme": HardCodedChatCommands.OnlineNotifications.NotifyMe.handleCommand(command); break; case "removeme": HardCodedChatCommands.OnlineNotifications.RemoveMe.handleCommand(command); break; case "kraken": HardCodedChatCommands.Kraken.handleCommand(command); break; case "restart": HardCodedChatCommands.Restart.handleCommand(command); break; case "recentsub": HardCodedChatCommands.RecentSub.handleCommand(command); break; case "recentdonation": HardCodedChatCommands.RecentDonation.handleCommand(command); break; case "permit": HardCodedChatCommands.Permit.handleCommand(command); break; case "claim": HardCodedChatCommands.Raffle.Claim.handleCommand(command); break; case "enter": HardCodedChatCommands.Raffle.Enter.handleCommand(command); break; case "pass": HardCodedChatCommands.Raffle.Pass.handleCommand(command); break; case "extend": HardCodedChatCommands.Multihost.Extend.handleCommand(command); break; case "remaining": HardCodedChatCommands.Multihost.Remaining.handleCommand(command); break; case "next": HardCodedChatCommands.Multihost.Guess.handleCommand(command); break; case "follow": HardCodedChatCommands.Follow.handleCommand(command); break; case "highlight": HardCodedChatCommands.Highlight.handleCommand(command); break; case "mods": HardCodedChatCommands.Mods.handleCommand(command); break; case "quote": HardCodedChatCommands.Quote.handleCommand(command); break; case "raid": HardCodedChatCommands.Raid.handleCommand(command); break; case "raise": HardCodedChatCommands.Raise.handleCommand(command); break; case "talk": HardCodedChatCommands.Talk.handleCommand(command); break; case "time": HardCodedChatCommands.Time.handleCommand(command); break; case "uptime": HardCodedChatCommands.Uptime.handleCommand(command); break; case "w": HardCodedChatCommands.Weather.handleCommand(command); break; case "title": HardCodedChatCommands.Title.handleCommand(command); break; case "changegame": HardCodedChatCommands.changegame.handleCommand(command); break; case "gt": HardCodedChatCommands.Gamertag.handleCommand(command); break; default: if (command.Command.ToLower() == command.ChatMessage.Username.ToLower()) { //Handle personal command HardCodedChatCommands.Personal.handleCommand(command); } else { //Handle dynamically created chat commands TwitchLib.ChatMessage.UType userType = command.ChatMessage.UserType; if (Common.Moderators.Contains(command.ChatMessage.Username.ToLower())) { userType = TwitchLib.ChatMessage.UType.Moderator; } bool found = false; foreach (Objects.ChatCommand dynCommand in Common.ChatCommands) { if (dynCommand.Command.ToLower() == command.Command.ToLower()) { if (validateTiers(command, dynCommand)) { if (Common.Cooldown.chatCommandAvailable(userType, command.Command, dynCommand.Cooldown)) { Console.WriteLine(dynCommand.ReturnMessages[0]); List <string> msgs = processDynamicVariables(command, dynCommand); Console.WriteLine(dynCommand.ReturnMessages[0]); foreach (string msg in msgs) { if (msg != "") { Common.ChatClient.SendMessage(msg, Common.DryRun); } } } } found = true; } } if (!found) { foreach (Objects.ChatCommand dynCommand in Common.ChatCommands) { Console.WriteLine(dynCommand.Command); foreach (string returnMessage in dynCommand.ReturnMessages) { if (returnMessage.ToLower().Contains(" " + command.Command.ToLower() + " ") && validateTiers(command, dynCommand)) { if (Common.Cooldown.chatCommandAvailable(userType, command.Command, dynCommand.Cooldown)) { List <string> msgs = processDynamicVariables(command, dynCommand); foreach (string msg in msgs) { if (msg != "") { Common.ChatClient.SendMessage(string.Format("Did you mean !{0}? {1}", dynCommand.Command, msg), Common.DryRun); return; } } } } } } } } break; } }