private void commandsList_MouseDoubleClick(object sender, MouseEventArgs e) { if (commandList.SelectedIndices.Count > 0) { ListViewItem i = commandList.SelectedItems[0]; TBotCommand cd = (TBotCommand)i.Tag; using (AddCommandForm acf = new AddCommandForm(cd, i.Text)) { if (acf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { i.Text = acf.Command.Flag; i.Tag = acf.Command; i.SubItems[1].Text = acf.Command.Data.Type; if (acf.Command.FlagIsRegex) { i.SubItems[1].Text += " [R]"; } if (acf.Command.FlagCaseSensitive) { i.SubItems[1].Text += " [C]"; } if (acf.Command.RequiresModerator) { i.Group = commandList.Groups["mod"]; } else { i.Group = commandList.Groups["all"]; } } } } }
void SetComponent(TBotCommand command, string flag) { commandOptionPanel.Controls.Clear(); if (flag != "") { textBox1.Text = flag; } switch (commandTypeList.Text) { case TBotCommandType.SayText: Command_sayText f = new Command_sayText(CommandChosen); if (command != null) { f.SetValues((string)command.Data.TagData[0]); } commandOptionPanel.Controls.Add(f); break; case TBotCommandType.AddToGiveaway: SetCommandPanel(new Command_AddToGiveaway(CommandChosen)); break; case TBotCommandType.BanUser: SetCommandPanel(new Command_banUser(CommandChosen)); break; case TBotCommandType.TimeoutUser: SetCommandPanel(new Command_TimeoutUser(CommandChosen)); break; case TBotCommandType.AntiBot: SetCommandPanel(new Command_AntiBotOnOff(CommandChosen)); break; case TBotCommandType.StartGiveaway: SetCommandPanel(new Command_StartGiveaway(CommandChosen)); break; case TBotCommandType.EndGiveaway: SetCommandPanel(new Command_EndGiveaway(CommandChosen)); break; /* * case TBotCommandType.WisperText: * SetCommandPanel(new Command_wisperText(CommandChosen)); * break; */ default: SetCommandPanel(new Command_notCompleted()); break; } }
public AddCommandForm(TBotCommand command, string flag) { InitializeComponent(); flagIsregex.Checked = command.FlagIsRegex; flagCasesensitive.Checked = command.FlagCaseSensitive; modOnly.Checked = command.RequiresModerator; foreach (var cmdName in typeof(TBotCommandType).GetFields()) { commandTypeList.Items.Add(cmdName.GetValue(cmdName)); } commandTypeList.Text = command.Data.Type; SetComponent(command, flag); }
void CommandChosen(CommandData cmd, ParamiterType paramiterOptions) { if (textBox1.Text == "") { MessageBox.Show("Enter a flag"); return; } if (paramiterOptions != ParamiterType.NoParamiters) { if (textBox1.Text.Contains(' ')) { MessageBox.Show("This command does not support spaces in the flag."); return; } if (flagIsregex.Checked) { MessageBox.Show("This command does not support regex flags."); return; } } if (flagIsregex.Checked) { try { Regex.Match("testRegex", textBox1.Text); } catch { MessageBox.Show("Regex is invalid."); return; } } _data = new TBotCommand(cmd, textBox1.Text); _data.FlagIsRegex = flagIsregex.Checked; _data.FlagCaseSensitive = flagCasesensitive.Checked; _data.RequiresModerator = modOnly.Checked; _data.Paramiters = paramiterOptions; this.DialogResult = System.Windows.Forms.DialogResult.OK; }
private void SayGiveawayCommands() { List <string> giveawayCommands = new List <string>(); foreach (ListViewItem i in commandList.Items) { TBotCommand cmd = (TBotCommand)i.Tag; if (cmd.Data.Type == TBotCommandType.AddToGiveaway) { giveawayCommands.Add(i.Text); } } if (giveawayCommands.Count < 1) { Bot.SayBuffer("No commands set to join the giveaway."); Bot.SayFlush(); return; } Bot.SayBuffer("Type {0} to join the giveaway!", string.Join(" or ", giveawayCommands.ToArray())); Bot.SayFlush(); }
private void SayAllCommands() { List <string> Commands = new List <string>(); Commands.Add("Commands:"); foreach (ListViewItem i in commandList.Items) { TBotCommand cmd = (TBotCommand)i.Tag; switch (cmd.Data.Type) { case TBotCommandType.SayText: Commands.Add(string.Format("[{0}] {1} - Say: {2}", i.Group.Name, cmd.Flag, (string)cmd.Data.TagData[0])); break; default: Commands.Add(string.Format("[{0}] {1} - {2}", i.Group.Name, cmd.Flag, cmd.Data.Type)); break; } } Bot.SayAsync(string.Join("; ", Commands.ToArray())); }
private bool AddCommand(TBotCommand cmd) { bool canAdd = true; foreach (ListViewItem ci in commandList.Items) { if (ci.Text.ToLower() == cmd.Flag.ToLower()) { canAdd = false; } } if (canAdd) { ListViewItem i = new ListViewItem(cmd.Flag); i.Tag = cmd; i.SubItems.Add(cmd.Data.Type); if (cmd.FlagIsRegex) { i.SubItems[1].Text += " [R]"; } if (cmd.FlagCaseSensitive) { i.SubItems[1].Text += " [C]"; } if (cmd.RequiresModerator) { i.Group = commandList.Groups["mod"]; } else { i.Group = commandList.Groups["all"]; } commandList.Items.Add(i); } return(canAdd); }
void _bot_OnMessageRead(TBot sender, TBotMessage message, string raw) { Chatlog.AppendText(string.Format("<{0}> {1}\n", message.Username, message.Text)); TBotCommand command = null; foreach (ListViewItem i in commandList.Items) { TBotCommand _tCom = (TBotCommand)i.Tag; string msgCompare = message.Text; string msgCompareSplit = message.Text; if (msgCompare.Contains(" ")) { msgCompareSplit = msgCompare.Split(' ')[0]; } if (!_tCom.FlagCaseSensitive) { msgCompare = msgCompare.ToLower(); } if (_tCom.FlagIsRegex) { if (Regex.Match(msgCompare, _tCom.Flag).Success) { command = _tCom; } } else { switch (_tCom.Paramiters) { case ParamiterType.HasParamiters: if (i.Text.ToLower() == msgCompare) { command = _tCom; } break; case ParamiterType.NoParamiters: if (i.Text.ToLower() == msgCompareSplit) { command = _tCom; } break; default: if (i.Text.ToLower() == msgCompareSplit || i.Text.ToLower() == msgCompare) { command = _tCom; } break; } } if (command != null) { break; } } if (command != null) { ExecuteCommand(command, message); } CheckBlacklist(message); }
void ExecuteCommand(TBotCommand command, TBotMessage msg) { string[] msgBreakdown; if (command.RequiresModerator && !IsMod(msg.Username)) { return; } switch (command.Data.Type) { case TBotCommandType.SayText: Bot.SayAsync(((string)command.Data.TagData[0]).Replace("{username}", msg.Username)); break; case TBotCommandType.AddToGiveaway: AddToGiveaway(msg.Username); break; case TBotCommandType.BanUser: msgBreakdown = msg.Text.Split(' '); if (msgBreakdown.Length != 2) { return; } Bot.Ban(msgBreakdown[1].ToLower()); break; case TBotCommandType.TimeoutUser: msgBreakdown = msg.Text.Split(' '); if (msgBreakdown.Length != 3) { return; } int time; if (!int.TryParse(msgBreakdown[2], out time)) { return; } Bot.Timeout(msgBreakdown[1], time); break; case TBotCommandType.AntiBot: msgBreakdown = msg.Text.Split(' '); if (msgBreakdown.Length != 2) { return; } if (msgBreakdown[1].ToLower() != "on" && msgBreakdown[1].ToLower() != "off") { return; } this.Invoke(msgBreakdown[1].ToLower() == "on" ? (Action)Bot.AntiBotOn : Bot.AntiBotOff); break; case TBotCommandType.StartGiveaway: if (acceptGiveawayEntries.Checked) { return; } acceptGiveawayEntries.Checked = true; msgBreakdown = msg.Text.Split(new char[] { ' ' }); if (msgBreakdown.Length == 2) { acceptGiveawayEntries.Checked = true; AddCommand(new TBotCommand(new CommandData(TBotCommandType.AddToGiveaway), msgBreakdown[1])); } Bot.SayBuffer("Giveaway started!"); SayGiveawayCommands(); break; case TBotCommandType.EndGiveaway: if (!acceptGiveawayEntries.Checked) { return; } acceptGiveawayEntries.Checked = false; msgBreakdown = msg.Text.Split(new char[] { ' ' }); acceptGiveawayEntries.Checked = false; if (giveawayEntries.Items.Count < 1) { GiveawayWinner.Text = "Nobody wins."; } else { string winner = (string)giveawayEntries.Items[r.Next(0, giveawayEntries.Items.Count - 1)]; GiveawayWinner.Text = winner; _bot.SayAsync("{0} has won the giveaway!", winner); } if (msgBreakdown.Length == 2 && msgBreakdown[1] == "clear") { lock (Bot) { foreach (ListViewItem i in commandList.Items) { if (((TBotCommand)i.Tag).Data.Type == TBotCommandType.AddToGiveaway) { commandList.Items.Remove(i); } } } } break; //case TBotCommandType.WisperText: // Bot.Whisper(msg.Username, ((string)command.Data.TagData[0]).Replace("{username}", msg.Username)); //break; } }