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); }
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 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; }
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; } }
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; } }