private void UpdateCooldowns(string userName, string command, string TwitchID = null) { UserCoolDown userCoolDown = new UserCoolDown(); userCoolDown = userCoolDowns.Find(u => u.username == userName); if (userCoolDown != null) { userCoolDown.coolDownBegan = DateTime.Now; } else { userCoolDown.coolDownBegan = DateTime.Now; userCoolDown.username = userName; userCoolDown.twichID = TwitchID; } }
//Commands are to be formatted as !command target action public string DoChatCommand(TwitchLib.Client.Events.OnMessageReceivedArgs e) { UserCoolDown userCoolDown = userCoolDowns.Find(v => v.username == e.ChatMessage.Username); if (userCoolDown != null) { if ((DateTime.Now - userCoolDown.coolDownBegan).TotalSeconds > userCoolDownSeconds) { UpdateCooldowns(e.ChatMessage.Username, e.ChatMessage.Message, e.ChatMessage.UserId); } else { return(null); } } else { userCoolDown = new UserCoolDown(); userCoolDown.username = e.ChatMessage.Username; userCoolDown.twichID = e.ChatMessage.UserId; userCoolDown.coolDownBegan = DateTime.Now; userCoolDowns.Add(userCoolDown); } string[] splitmessage = e.ChatMessage.Message.Split(' '); if (splitmessage.Count() > 1) { if (splitmessage[1].Contains('@') == true) { splitmessage[1] = splitmessage[1].Trim('@'); } } if (e.ChatMessage.IsModerator || e.ChatMessage.IsBroadcaster) { if (IsHelpModCommand(e.ChatMessage.Message)) { return(HelpModCommand()); } if (IsGivePoints(splitmessage[0])) { if (splitmessage.Count() < 3) { return("Command format is: command name amount"); } if (IsDigitsOnly(splitmessage[2]) == false) { return("The points were not formatted correctly"); } int points = Convert.ToInt32(splitmessage[2]); if (GivePoints(TwitchHelpers.GetUserId(splitmessage[1]), points)) { return("Points get!"); } else { return("The name provided doesn't exist in my records..."); } } if (IsPraise(splitmessage[0])) { return(TwitchHelpers.PraiseMessage(splitmessage[1])); } else if (IsRecentFollowers(e.ChatMessage.Message)) { return(GetRecentFollowers()); } else if (IsSpecialThanks(e.ChatMessage.Message)) { return(SpecialThanks()); } if (IsTakePoints(splitmessage[0])) { if (splitmessage.Count() < 3) { return("Command format is: command name amount"); } if (IsDigitsOnly(splitmessage[2]) == false) { return("The points were not formatted correctly"); } int points = Convert.ToInt32(splitmessage[2]); if (TakePoints(TwitchHelpers.GetUserId(splitmessage[1]), points)) { return("Points un-get!"); } else { return("The name provided doesn't exist in my records..."); } } } // all commands not exclusive to channel moderators if (IsHelpCommand(e.ChatMessage.Message)) { return(HelpCommand()); } else if (IsGetRandomClipCommand(splitmessage[0])) { Random random = new Random((int)DateTime.Now.Ticks); int max = 20; string sUser = string.Empty; if (e.ChatMessage.Message.Contains(" ")) { sUser = splitmessage[1]; } TwitchLib.Api.Helix.Models.Users.GetUsers.User user = TwitchHelpers.GetUser(sUser); if (user != null) { var clips = twitchAPI.Helix.Clips.GetClipsAsync(null, null, user.Id, null, null, null, null, max).Result.Clips; if (clips.Count() > 0) { int userId = Convert.ToInt32(e.ChatMessage.UserId); DatabaseContext context = new DatabaseContext(); var requestor = context.ViewerStats.Where(v => v.TwitchID == userId).FirstOrDefault(); requestor.Points -= costOfClip; context.SaveChanges(); return(string.Format("{0} points deducted. {1}", costOfClip, clips[random.Next(clips.Count() - 1)].Url)); //clips index starts at 0 } else { return("That user has no clips of their streams!"); } } else { return("A valid Twitch name must be provided..."); } } else if (IsFunThingsCardCommand(e.ChatMessage.Message)) { return(_funThings.IsThisYourCard()); } else if (IsFunThingsDiceCommand(e.ChatMessage.Message)) { int[] rolls; rolls = _funThings.RollDice(); return(string.Format("The dice were cast. As they come to a stop, two numbers appear: {0}, {1}", rolls[0].ToString(), rolls[1].ToString())); } else if (IsPointsCommand(e.ChatMessage.Message)) { return(string.Format("Points: {0}", GetPoints(e.ChatMessage.Username))); } else { return("Numerous conditions and not one match!"); } }