Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 void CheckBlacklist(TBotMessage msg)
 {
     if (IsMod(msg.Username))
         return;
     foreach(string s in blacklistedWords.Items)
     {
         if (msg.Text.ToLower().Contains(s.ToLower()))
         {
             _bot.Timeout(msg.Username, 60 * 2);
             //_bot.Say("The word \"{0}\" is blacklisted, please refrain from using it.", s);
         }
     }
 }