public void RemoveCommand(WinterBot sender, TwitchUser user, string c, string a) { Args args = a.ParseArguments(m_bot); string cmd = args.GetOneWord(); if (cmd == null) { sender.SendResponse(Importance.Med, m_removeCommandUsage); return; } if (cmd[0] == '!') { cmd = cmd.Substring(1); } lock (m_sync) { cmd = cmd.ToLower(); if (m_commands.ContainsKey(cmd)) { m_commands.Remove(cmd); m_remove.Add(cmd); m_dirty = true; sender.SendResponse(Importance.Low, string.Format("Removed command {0}.", cmd)); WinterBotSource.Log.RemoveCommand(user.Name, cmd); } else { sender.SendResponse(Importance.Med, string.Format("Command {0} not found.", cmd)); } } }
public void AddCommand(WinterBot sender, TwitchUser user, string c, string v) { Args args = v.ParseArguments(m_bot); AccessLevel level = args.GetAccessFlag("ul", AccessLevel.Mod); string cmdName = args.GetOneWord(); string cmdText = args.GetString(); if (string.IsNullOrWhiteSpace(cmdName) || string.IsNullOrWhiteSpace(cmdText) || args.Error != null) { sender.SendResponse(Importance.Med, m_addCommandUsage); return; } if (cmdName[0] != '!') { sender.SendResponse(Importance.Med, string.Format("User commands must start with a '!'. {0}", m_addCommandUsage)); return; } else { cmdName = cmdName.Substring(1); } if (cmdText[0] == '.' || cmdText[0] == '/') { sender.SendResponse(Importance.Med, string.Format("Cannot create a command which starts with a '{0}'.", cmdText[0])); return; } cmdName = cmdName.ToLower(); Command userCommand = new Command(level, cmdText); bool exists; lock (m_sync) { exists = m_commands.ContainsKey(cmdName); m_commands[cmdName] = userCommand; m_dirty = true; } if (exists) { sender.SendResponse(Importance.Med, string.Format("Updated command: !{0}.", cmdName)); WinterBotSource.Log.AddCommand(user.Name, cmdName, cmdText); } else { sender.SendResponse(Importance.Med, string.Format("Successfully added command: !{0}.", cmdName)); WinterBotSource.Log.UpdateCommand(user.Name, cmdName, cmdText); } }
void bot_Tick(WinterBot sender, TimeSpan timeSinceLastUpdate) { if (m_enabled) { if (!sender.IsStreamLive) { if (!m_streamDead) { m_streamDead = true; m_lastOffline = DateTime.Now; } else if (m_lastOffline.Elapsed().TotalMinutes >= 10) { m_enabled = false; m_streamDead = false; sender.SendResponse(Importance.Med, "Disabling jukebox mode."); } } else { m_streamDead = false; } } if (m_enabled && m_lastMessage.Elapsed().TotalMinutes >= 7) { SendMessage(sender); } }
public void OpenBetting(WinterBot sender, TwitchUser user, string cmd, string value) { if (!Enabled) { return; } if (IsBettingOpen || WaitingResult) { sender.SendResponse(Importance.Low, "Betting is currently ongoing. Use !result to award points, use !cancelbet to cancel the current bet."); return; } HashSet <string> betting = new HashSet <string>(); Args args = value.ToLower().ParseArguments(sender); int time = args.GetIntFlag("time", 120, false); string val; while ((val = args.GetOneWord()) != null) { betting.Add(val); } if (betting.Count < 2) { sender.SendResponse(Importance.High, "Need at least two people to bet on!"); return; } m_betting = betting; m_bets = new Dictionary <TwitchUser, Tuple <string, int> >(); m_state = State.Open; m_time = time; m_bettingStarted = DateTime.Now; GetCallback(); sender.SendResponse(Importance.High, "Betting is now OPEN. Use '!bet [player] [amount]' to bet. Minimum bet is 1, maximum bet is 500. You start with 3000 points, you can bet even if you have no points."); }
void UnknownCommandReceived(WinterBot sender, TwitchUser user, string cmd, string value) { cmd = cmd.ToLower(); Command command; lock (m_sync) if (!m_commands.TryGetValue(cmd, out command)) { return; } if (!sender.CanUseCommand(user, command.AccessLevel)) { WinterBotSource.Log.DenyCommand(user.Name, cmd, "access"); return; } if (CanSendCommand(user, cmd)) { sender.SendResponse(Importance.Low, command.Text); m_sent.AddLast(new Tuple <string, DateTime>(cmd, DateTime.Now)); } }
public void JukeBoxCommand(WinterBot sender, TwitchUser user, string cmd, string value) { if (!m_enabled) { if (!sender.CanUseCommand(user, AccessLevel.Mod)) { if (m_lastMessage.Elapsed().TotalSeconds <= 30) { return; } m_lastMessage = DateTime.Now; sender.SendResponse(Importance.Low, "The jukebox is CLOSED. No additional requests are being accepted."); return; } value = value.Trim().ToLower(); if (value == "on") { m_enabled = true; m_lastMessage = DateTime.Now; sender.SendResponse(Importance.Med, "Jukebox activated. Use '!JukeboxMode off' to deactivate."); } else if (value == "off") { sender.SendResponse(Importance.Med, "Jukebox mode is off."); } else { sender.SendResponse(Importance.Low, "Usage: '!jukebox on' and '!jukebox off'. Mod only."); } } else { if (sender.CanUseCommand(user, AccessLevel.Mod)) { if (value == "on") { sender.SendResponse(Importance.Low, "Jukebox mode is already enabled."); } else if (value == "off") { sender.SendResponse(Importance.High, "The jukebox is shutting down for the night. Please hold your song requests for next time."); m_enabled = false; } else { SendMessage(sender); } } else { if (m_lastMessage.Elapsed().TotalSeconds <= 10) { return; } m_lastMessage = DateTime.Now; SendMessage(sender); } } }
private void SendMessage(WinterBot bot) { m_lastMessage = DateTime.Now; bot.SendResponse(Importance.Low, m_message); }