public static Command GetSetVillageCommand(Bot bot) { return new Command("!setvillage #{village code}", "Set your village code, so you can call targets using the !call command (Still under development).", "!setvillage #00000000", bot, (message) => { var validate = Regex.Match(message.text.ToUpper(), "^!SETVILLAGE #([0-Z])+$", RegexOptions.IgnoreCase); return validate.Success; }, (message) => { var villageCode = message.text.ToUpper().Substring("!SETVILLAGE ".Length); var member = Members.GetMemberByGroupMeID(message.sender_id); if (member == null) { member = new Model.Member { GroupMeID = message.sender_id, Name = message.name, Banned = false }; } member.VillageCode = villageCode; Members.UpdateMember(member); bot.SendMessage($"Village code set to {villageCode}"); }); }
public static Command GetGetVillageCommand(Bot bot) { return new Command("!getvillage", "Get your current village code.", "", bot, (message) => { return message.text.ToUpper() == "!GETVILLAGE"; }, (message) => { try { var member = Members.GetMemberByGroupMeID(message.sender_id); if (member == null || String.IsNullOrEmpty(member.VillageCode)) { bot.SendMessage("Your village is not set."); } else { bot.SendMessage($"Your village code is {member.VillageCode}"); } } catch (Exception ex) { Bots.TestChatBot.SendMessage(ex.ToString()); } }); }
public static Command SaveQuoteCommand(Bot bot) { return new Command("!savequote <tag> <quote>", "Save a quote for eternity.", "!savequote @Logan AlckieBot is amazing!", bot, (message) => { var isSaveQuoteCommand = (message.text.ToUpper().StartsWith("!SAVEQUOTE ")); if (!isSaveQuoteCommand) { //Return earlier return false; } var containsAttachment = message.attachments?.Length == 1; var isAMention = message.attachments[0]?.Type == "mentions"; var containsOnlyOneMention = message.attachments[0]?.User_ids?.Length == 1; return isSaveQuoteCommand && containsAttachment && isAMention && containsOnlyOneMention; }, (message) => { var mention = message.attachments[0]; var quote = message.text.Substring(mention.Loci[0][0] + mention.Loci[0][1] + 1); var userName = message.text.Substring(mention.Loci[0][0] + 1, mention.Loci[0][1] - 1); var userID = mention.User_ids[0]; if (mention.Loci[0][0] != "!SAVEQUOTE ".Length || quote.Length == 0) { var randomNumber = RandomHelper.GetRandomNumber(5); switch (randomNumber) { case 1: bot.SendMessage("Ask someone who knows his shit to do this for you."); break; case 2: bot.SendMessage("The command is all wrong!"); break; case 3: bot.SendMessage("Try again, but try it right this time."); break; case 4: bot.SendMessage("\"!savequote <tag> <quote>\", ffs."); break; default: bot.SendMessage("That's not how it works."); break; } } else { Quote.AddQuote(new Model.Quote { Member = userName, SavedAt = DateTime.UtcNow, Message = quote }); bot.SendMessage("This quote has been saved for eternity!"); } }); }
public static List<Command> GetAllDebugCommands(Bot bot) { var commands = new List<Command> { BeADoucheCommand(bot), StopBeingADoucheCommand(bot) }; return commands; }
public Command(string name, string description, string example, CommandType type, Bot bot, Func<ReceivedMessage, bool> condition, Action<ReceivedMessage> response, bool canBeMuted = true) { this.Name = name; this.Description = description; this.Example = example; this.Type = type; this.Bot = bot; this.Condition = condition; this.Response = response; this.CanBeMuted = canBeMuted; }
public static List<Command> GetAllGeneralCommands(Bot bot) { var commands = new List<Command> { WelcomeMessageCommand(bot), RandomQuoteCommand(bot), SaveQuoteCommand(bot), RandomQuoteByMemberCommand(bot) }; return commands; }
public static List<Command> GetAllWarCommands(Bot bot) { var commands = new List<Command> { ClashCallerCommand(bot), GetWarMatchUsCommand(bot), GetSetVillageCommand(bot), GetGetVillageCommand(bot) }; return commands; }
public static Command BanCommand(Bot bot) { return new Command("!ban {groupme id}", "Ban someone from all chats. Use !members to get an user ID.", "!ban 24156270", CommandType.ModsOnly, bot, (message) => { return message.text.ToUpper().StartsWith("!BAN "); }, (message) => { var param = message.text.Substring(5); BanOrUnbanMember(bot, param, true); }); }
public AntiSpamCommand(string name, string description, string example, Bot bot, Func<ReceivedMessage, bool> condition, Action<ReceivedMessage> response, SpamCounter.SpamType spamCounterType, Action<ReceivedMessage> antiSpamResponse, bool canBeMuted = true) { this.Name = name; this.Description = description; this.Example = example; this.Type = CommandType.Public; this.Bot = bot; this.Condition = condition; this.Response = response; this.CanBeMuted = canBeMuted; this.SpamCounterType = spamCounterType; this.AntiSpamResponse = antiSpamResponse; }
public static Command RandomQuoteCommand(Bot bot) { return new Command("!randomquote", "Return a random quote from someone", "", bot, (message) => { return (message.text.ToUpper() == "!RANDOMQUOTE"); }, (message) => { var quotes = Quote.GetQuotes(); var randomNumber = RandomHelper.GetRandomNumber(quotes.Count); var selectedQuote = quotes[randomNumber - 1]; bot.SendMessage($"\"{selectedQuote.Message.Trim()}\" - {selectedQuote.Member}, {selectedQuote.SavedAt.Year} "); }); }
public static Command GetGroupIDsCommand(Bot bot) { return new Command("", "", "", CommandType.GodOnly, bot, (message) => { return message.text.ToUpper().StartsWith("!GROUPIDS"); }, (message) => { var groups = Chat.GetAllGroups(ConfigurationManager.AppSettings["GROUPME_TOKEN"]); var sb = new StringBuilder(); foreach(var group in groups) { sb.AppendLine($"- Name: {group.Name} - ID: {group.ID}"); } bot.SendMessage(sb.ToString()); }); }
public static AntiSpamCommand AvoidNukeCommand(Bot bot) { return new AntiSpamCommand("", "", "", bot, (message) => { return (message.system && ( message.text.ToUpper().Contains("REMOVED") || message.text.ToUpper().Contains("REMOVEU") )); }, (message) => { }, SpamCounter.SpamType.SPAM, (message) => { bot.KickUser(ConfigurationManager.AppSettings["GROUPME_TOKEN"], message.sender_id); }); }
private static Command BeADoucheCommand(Bot bot) { return new Command("", "", "", CommandType.GodOnly,bot, (message) => { return message.sender_id == Mods.Alckie && message.text.ToUpper() == "!BEADOUCHE"; }, (message) => { if (bot.IsBeingADouche) { bot.SendMessage("I'M DOING IT ALREADY, DAMNIT."); } else { bot.IsBeingADouche = true; bot.SendMessage("Douche mode on."); } }); }
private static Command StopBeingADoucheCommand(Bot bot) { return new Command("", "", "", CommandType.GodOnly, bot, (message) => { return message.sender_id == Mods.Alckie && message.text.ToUpper() == "!STOPBEINGADOUCHE"; }, (message) => { if (bot.IsBeingADouche) { bot.IsBeingADouche = false; bot.SendMessage("Douche mode off."); } else { bot.SendMessage("But I'm not. ;_;"); } }); }
public static Command ClashCallerCommand(Bot bot) { return new Command("!clashcaller, !cc", "Get the url for ClashCaller.", "", bot, (message) => { return message.text.ToUpper() == "!CLASHCALLER" || message.text.ToUpper() == "!CC"; }, (message) => { if (ClashCaller.Code != "") { bot.SendMessage("http://www.clashcaller.com/war/" + ClashCaller.Code); } else { bot.SendMessage("I don't have the code atm."); } }); }
public static Command BabyComeBackCommand(Bot bot) { return new Command("!babycomeback, !starttheparty", "AlckieBot will go back to his usual self.", "", CommandType.ModsOnly, bot, (message) => { return (message.text.ToUpper() == "!BABYCOMEBACK" || message.text.ToUpper() == "!STARTTHEPARTY"); }, (message) => { if (Mods.IsUserAMod(message.sender_id)) { var attachments = new List<dynamic>(); attachments.Add(new { loci = new int[][] { new int[] { 17, message.name.Length + 1 } }, type = "mentions", user_ids = new string[] { message.sender_id } }); bot.SendMessage("Thank you Master @" + message.name + " for letting me be free!", attachments); bot.CanSpeak = true; } else { bot.SendMessage("No can do."); } }, false); }
public static void Init() { var bots = Bot.GetRegisteredBots(ConfigurationManager.AppSettings["GROUPME_TOKEN"]); var botName = ConfigurationManager.AppSettings["BOT_NAME"]; LeadershipChatBot = bots.FirstOrDefault(b => b.GroupID == ConfigurationManager.AppSettings["LEADERSHIPCHAT_ID"] && b.Name == botName); if (LeadershipChatBot != null) { LeadershipChatBot.GroupName = "leadership"; LeadershipChatBot.CanCallMods = true; } GeneralChatBot = bots.FirstOrDefault(b => b.GroupID == ConfigurationManager.AppSettings["GENERALCHAT_ID"] && b.Name == botName); if (GeneralChatBot != null) { GeneralChatBot.GroupName = "general"; } WarChatBot = bots.FirstOrDefault(b => b.GroupID == ConfigurationManager.AppSettings["WARCHAT_ID"] && b.Name == botName); if (WarChatBot != null) { WarChatBot.CanCallMods = true; WarChatBot.GroupName = "war"; } TestChatBot = bots.FirstOrDefault(b => b.GroupID == ConfigurationManager.AppSettings["TESTCHAT_ID"] && b.Name == botName); if (TestChatBot != null) { TestChatBot.GroupName = "test"; } WhenInRomeChatBot = bots.FirstOrDefault(b => b.GroupID == ConfigurationManager.AppSettings["WIRCHAT_ID"] && b.Name == botName); if (WhenInRomeChatBot != null) { WhenInRomeChatBot.GroupName = "wheninrome"; } }
public static Command RandomQuoteByMemberCommand(Bot bot) { return new Command("!randomquote <search parameters>", "Return a random quote from someone who matches the search parameters.", "!randomquote Alckie", bot, (message) => { return message.text.ToUpper().StartsWith("!RANDOMQUOTE "); }, (message) => { var searchParams = message.text.Substring("!RANDOMQUOTE ".Length).Trim(); var quotes = Quote.GetQuotes().Where(q => q.Member.ToUpper().Contains(searchParams.ToUpper())).ToList(); if (quotes.Count > 0) { var randomNumber = RandomHelper.GetRandomNumber(quotes.Count); var selectedQuote = quotes[randomNumber - 1]; bot.SendMessage($"\"{selectedQuote.Message.Trim()}\" - {selectedQuote.Member}, {selectedQuote.SavedAt.Year} "); } else { var randomNumber = RandomHelper.GetRandomNumber(3); switch (randomNumber) { case 1: bot.SendMessage("\"I can't find shit with that filter.\" - AlckieBot, 2015"); break; case 2: bot.SendMessage("Nothing to see here."); break; default: bot.SendMessage("Search for something else."); break; } } }); }
public static Command CallModsCommand(Bot bot) { return new Command("@mods", "Tag all Mist mods.", "", bot, (message) => { return message.text.ToUpper() == "@MODS"; }, (message) => { if (bot.CanCallMods) { var leadershipGroup = Chat.GetGroup(ConfigurationManager.AppSettings["GROUPME_TOKEN"], ConfigurationManager.AppSettings["LEADERSHIPCHAT_ID"]); if (leadershipGroup != null) { var callMessage = "Masters, one of your minions needs your attention."; if (bot.GroupID == ConfigurationManager.AppSettings["LEADERSHIPCHAT_ID"]) { callMessage = "Listen up, ya cunts!"; } if (callMessage.Length < leadershipGroup.Members.Count) { var charactersToFill = leadershipGroup.Members.Count - callMessage.Length; callMessage = callMessage.PadRight(charactersToFill); } var userIDs = leadershipGroup.Members.Select(g => g.UserID).ToArray(); var locis = new int[leadershipGroup.Members.Count][]; for (var i = 0; i < leadershipGroup.Members.Count; i++) { if (i < leadershipGroup.Members.Count - 1) { locis[i] = new int[] { i, 1 }; } else { //fill out the mention with the rest of the message locis[i] = new int[] { i, callMessage.Length - i }; } } var attachments = new List<dynamic>(); attachments.Add(new { loci = locis, type = "mentions", user_ids = userIDs }); bot.SendMessage(callMessage, attachments); } } else { bot.SendMessage("Plebs are not allowed to call the Masters right now."); } }); }
public static Command MembersListCommand(Bot bot) { return new Command("!members", "Get a url with all the GM members.", "", bot, (message) => { return (message.text.ToUpper() == "!MEMBERS"); }, (message) => { bot.SendMessage("http://alckiebot.azurewebsites.net/Members"); }); }
public static Command WelcomeMessageCommand(Bot bot) { return new Command("", "", "", CommandType.Automatic, bot, (message) => { return (message.system && ( message.text.ToUpper().Contains("JOINED") || message.text.ToUpper().Contains("ENTROU") || message.text.ToUpper().Contains("ADICIONOU") || message.text.ToUpper().Contains("ADDED") )); }, (message) => { bot.SendMessage("Welcome to Reddit Mist! Please change your name to match your IGN and, if you haven't already, make sure to read our rules available at www.reddit.com/r/RedditMist"); }); }
public static Command ModTagCommand(Bot bot) { return new Command("!modtag", "Set whether plebs can tag the mods or not.", "", CommandType.ModsOnly, bot, (message) => { return (Mods.IsUserAMod(message.sender_id) && message.text.ToUpper() == "!MODTAG"); }, (message) => { bot.CanCallMods = !bot.CanCallMods; if (bot.CanCallMods) { bot.SendMessage("Plebs are now allowed to call the Masters"); } else { bot.SendMessage("Plebs lost the right to call upon the Masters. Now stop messing around before we take away your other rights."); } }); }
public static Command RandomHandsUpCommand(Bot bot) { return new Command("", "", "", bot, (message) => { return (message.text.Contains(@"\o/")); }, (message) => { var randomNumber = RandomHelper.GetRandomNumber(10); //Only 10% chance of this command being executed. if (randomNumber == 1) { bot.SendMessage(@"\o/"); } }); }
public static Command RollDiceCommand(Bot bot) { return new Command("!roll {X}d{Y}", "Roll X dices with Y faces.", "!roll 1d6", bot, (message) => { return (message.text.ToUpper().StartsWith("!ROLL ")); }, (message) => { var diceParams = message.text.Substring(6); const string diceValidatorRegex = @"^(\d+)?d(\d+)$"; var validate = Regex.Match(diceParams, diceValidatorRegex, RegexOptions.IgnoreCase); if (validate.Success) { var diceArray = diceParams.ToUpper().Split('D'); var numberOfDices = Int32.Parse(diceArray[0]); var diceSides = Int32.Parse(diceArray[1]); if (numberOfDices == 0 || diceSides < 2) { bot.SendMessage("Are you dumb or something?"); } else if (numberOfDices > 10) { bot.SendMessage("Nah. Too tired to roll that many dice..."); } else if (diceSides > 100) { bot.SendMessage("That's not a dice. That's a f*****g ball."); } else { var rollResults = new string[numberOfDices]; for (var i = 0; i < numberOfDices; i++) { var rollResult = RandomHelper.RollDice(diceSides); rollResults[i] = rollResult.ToString(); } bot.SendMessage($"The results for your roll are: {String.Join(",", rollResults)}"); } } else { var randomNumber = RandomHelper.GetRandomNumber(5); switch (randomNumber) { case 1: bot.SendMessage("Gotta roll it right..."); break; case 2: bot.SendMessage("Nope."); break; case 3: bot.SendMessage("Try again!"); break; case 4: bot.SendMessage("Omg, you can't even roll a dice."); break; default: bot.SendMessage("That's not how it works."); break; } } }); }
public static void UpdateMembersByGroupAndKickIfBanned(string groupMeToken, string groupID, Bot bot) { var dbMembers = GetMembers(); var chat = Model.GroupMe.Chat.GetGroup(groupMeToken, groupID); if (chat != null) { foreach (var member in chat.Members) { var dbMember = dbMembers.FirstOrDefault(m => m.GroupMeID == member.UserID); if (dbMember == null) { UpdateMember(new Model.Member { GroupMeID = member.UserID, Name = member.Name, VillageCode = "", Banned = false }); } else if (dbMember.Banned) { bot.KickUser(groupMeToken, member.UserID); bot.SendMessage("GTFO!"); } } } }
public static Command ShutupCommand(Bot bot) { return new Command("!shutup", "AlckieBot won't reply to commands anymore. Use !backcomebacy to restart him.", "", CommandType.ModsOnly, bot, (message) => { return (message.text.ToUpper() == "!SHUTUP"); }, (message) => { if (Mods.IsUserAMod(message.sender_id)) { bot.SendMessage("Sure thing, master. I will shut up for now."); bot.CanSpeak = false; } else { var attachments = new List<dynamic>(); attachments.Add(new { loci = new int[][] { new int[] { 17, message.name.Length + 1 } }, type = "mentions", user_ids = new string[] { message.sender_id } }); bot.SendMessage("No, you shut up, @" + message.name + "!", attachments); } }); }
public static Command TagMeInWithReasonCommand(Bot bot) { return new Command("!tagmein {X}h{Y}m {reminder}", "AlckieBot will tag you after some time, and remind you of something.", "!tagmein 0h10m Call my dad.", bot, (message) => { var validate = Regex.Match(message.text.ToUpper(), @"^!TAGMEIN ((\d+)h)?((\d+)m) ", RegexOptions.IgnoreCase); return validate.Success; }, (message) => { var validate = Regex.Match(message.text, @"^!TAGMEIN ((\d+)h)?((\d+)m) ", RegexOptions.IgnoreCase); var timeParameter = validate.Value.Substring("!TAGMEIN ".Length); var reasonParameter = message.text.Substring(validate.Value.Length); var hours = 0; var minutes = 0; if (timeParameter.Contains("h")) { hours = Int32.Parse(timeParameter.Split('h')[0]); minutes = Int32.Parse(timeParameter.Replace("m", "").Split('h')[1]); } else { minutes = Int32.Parse(timeParameter.Replace("m", "")); } var time = new TimeSpan(hours, minutes, 0); bot.SendMessage("Sure thing. I will tag you in " + timeParameter); TimerHelper.ExecuteDelayedActionAsync(() => { var attachments = new List<dynamic>(); attachments.Add(new { loci = new int[][] { new int[] { 0, message.name.Length + 1 } }, type = "mentions", user_ids = new string[] { message.sender_id } }); bot.SendMessage($"@{message.name}! You told me to remind you: {reasonParameter}.", attachments); }, time); }); }
public GroupCommands(string groupName, Bot bot) { this.Bot = bot; this.GroupName = groupName; this.Commands = new List<ICommand>(); }
public static Command UnixTimeCommand(Bot bot) { return new Command("!time", "Gets the current date and time in Unix time.", "", bot, (message) => { return (message.text.ToUpper() == "!TIME"); }, (message) => { var unixTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; bot.SendMessage($"{unixTime} UTC."); }); }
private static void BanOrUnbanMember(Bot bot, string userId, bool ban) { var member = Members.GetMembers().Where(m => m.GroupMeID == userId).FirstOrDefault(); if (member == null) { bot.SendMessage("Can't find anyone. Use !members and get the right ID."); } else { member.Banned = ban; Members.UpdateMember(member); bot.SendMessage($"{member.Name} is now " + (ban ? "banned" : "unbanned")); } }