コード例 #1
0
        public static TwitchCommand[] GetAll(TwitchConnection connection)
        {
            List <object[]> results = _table.Select(null, null, "ChannelUserId=?a AND BotUserId=?b",
                                                    new object[] { connection.channel.user.id, connection.bot.user.id }, null, 0);

            if (results != null)
            {
                TwitchCommand[] commands = new TwitchCommand[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    commands[i] = new SqlTwitchCommand(
                        results[i][0].FromSql <uint>(),
                        connection,
                        results[i][3].FromSql <string>(),
                        results[i][4].FromSql <string>(),
                        results[i][5].FromSql <bool>(),
                        TimeSpan.FromSeconds(results[i][6].FromSql <int>()),
                        results[i][7].FromSql <string>());
                }

                return(commands);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
    private CommandAlias FilterCommand(string msg, bool checkCode, List <CommandAlias> alias)
    {
        //check if message is command
        if (msg[0] != '!')
        {
            return(new CommandAlias(TwitchCommand.notCommand));
        }

        //split msg to words and remove '!'
        List <string> words = new List <string>(msg.Split(' '));

        words[0] = words[0].Remove(0, 1);

        //check if user is playing different game
        if (checkGameCode)
        {
            if (words[1].ToLower() != TwitchManager.instance.TwitchLogin.GameCode)
            {
                return(new CommandAlias(TwitchCommand.differentGame));
            }
            //remove gamecode from words
            words.RemoveAt(1);
        }

        //check if command is valid and allowed via this input method (whisper/chat)
        TwitchCommand cmd = ValidateCommand(alias, words[0]);

        //remove command from words, words should now contain only additional info for example coordinates
        words.RemoveAt(0);

        //TODO limit words amount if needed

        return(new CommandAlias(words, cmd));
    }
コード例 #3
0
 private void ResetAllActions(TwitchCommand cmd)
 {
     actionNumber    = 0;
     firstAction     = new CommandAlias(cmd);
     secondAction    = new CommandAlias(cmd);
     newFirstAction  = new CommandAlias(cmd);
     newSecondAction = new CommandAlias(cmd);
 }
コード例 #4
0
    private void OnChatMsgReceived(string msg)
    {
        if (msg.Contains(GAME_COMMAND))
        {
            int    msgIndex  = msg.IndexOf("PRIVMSG #");
            string msgString = msg.Substring(msgIndex + channelName.Length + 11);

            if (msgString.StartsWith(GAME_COMMAND))
            {
                msgString = msgString.Substring(GAME_COMMAND.Length);
            }
            else
            {
                return;
            }

            string user = msg.Substring(1, msg.IndexOf('!') - 1);

            if (msgString.Length > 0)
            {
                msgString = msgString.Substring(0, Mathf.Min(msgString.Length, 25));
            }

            if (string.IsNullOrEmpty(msgString) || string.IsNullOrWhiteSpace(msgString))
            {
                return;
            }

            string[] splittedString = msgString.Split(' ');

            if (Enum.TryParse(splittedString[0].ToUpper(), out CommandArg commandArg))
            {
                TwitchCommand twitchCommand = new TwitchCommand(user,
                                                                splittedString.Length > 1 ? splittedString[1] : String.Empty, commandArg);
                EventsManager.onTwitchCommandReceived(twitchCommand);
                Debug.Log(String.Format("Launched {0} from {1} with message {2}", twitchCommand.argument,
                                        twitchCommand.username, twitchCommand.message));
            }

            //Debug.Log(String.Format("Received {0} from {1}", msgString, user));
        }
    }
コード例 #5
0
 public TwitchCommandInfo(TwitchCommand command, string info)
 {
     this.command = command;
     infoString   = info;
 }
コード例 #6
0
 public TwitchCommandInfo(TwitchCommand command)
 {
     this.command = command;
     infoString   = "";
 }
コード例 #7
0
ファイル: CommandAlias.cs プロジェクト: haxax/Lumipallopeli
 public CommandAlias(List <string> words, TwitchCommand cmd)
 {
     Command = cmd;
     Alias   = new List <string>(words);
 }
コード例 #8
0
ファイル: CommandAlias.cs プロジェクト: haxax/Lumipallopeli
 public CommandAlias(TwitchCommand cmd)
 {
     Command = cmd;
     Alias   = new List <string>();
 }
コード例 #9
0
        public static TwitchCommand[] GetAll(TwitchConnection connection)
        {
            List<object[]> results = _table.Select(null, null, "ChannelUserId=?a AND BotUserId=?b",
                new object[] { connection.channel.user.id, connection.bot.user.id }, null, 0);
            if(results != null) {
                TwitchCommand[] commands = new TwitchCommand[results.Count];
                for(int i = 0; i < results.Count; i++) {
                    commands[i] = new SqlTwitchCommand(
                        results[i][0].FromSql<uint>(),
                        connection,
                        results[i][3].FromSql<string>(),
                        results[i][4].FromSql<string>(),
                        results[i][5].FromSql<bool>(),
                        TimeSpan.FromSeconds(results[i][6].FromSql<int>()),
                        results[i][7].FromSql<string>());
                }

                return commands;
            } else {
                return null;
            }
        }
コード例 #10
0
    private void CommandReceived(TwitchCommand twitchcommand)
    {
        PlayerSlot userPS;

        switch (twitchcommand.argument)
        {
        case CommandArg.JOIN:
            if (_playerSlots.GetEmptySlot(out userPS))
            {
                if (_playerSlots.GetPlayerSlotByName(twitchcommand.username))
                {
                    return;
                }
                userPS.userJoin(twitchcommand.username);
            }

            break;

        case CommandArg.LEAVE:
            if (_playerSlots.GetPlayerSlotByName(out userPS, twitchcommand.username))
            {
                userPS.UserLeave();
            }

            break;

        case CommandArg.BODYCOLOR:
        case CommandArg.BODY:
            if (_playerSlots.GetPlayerSlotByName(out userPS, twitchcommand.username))
            {
                if (!string.IsNullOrEmpty(twitchcommand.message))
                {
                    if (Int32.TryParse(twitchcommand.message, out int bodyNumber))
                    {
                        if (bodyNumber > 0 && bodyNumber < Enum.GetValues(typeof(BodyEnum)).Length)
                        {
                            BodyEnum bodyEnum = (BodyEnum)bodyNumber;
                            userPS.SetBody(bodyEnum);
                        }
                    }

                    if (customColors.TryGetValue(twitchcommand.message.ToUpper(), out string hexColor))
                    {
                        twitchcommand.message = hexColor;
                    }

                    if (ColorUtility.TryParseHtmlString(twitchcommand.message, out Color pcol))
                    {
                        userPS.SetPrimaryColor(pcol);
                    }
                }
            }

            break;

        case CommandArg.PARTCOLOR:
        case CommandArg.TOP:
        case CommandArg.FRONT:
        case CommandArg.LEFT:
        case CommandArg.RIGHT:
        case CommandArg.BOTTOM:
            if (_playerSlots.GetPlayerSlotByName(out userPS, twitchcommand.username))
            {
                if (!string.IsNullOrEmpty(twitchcommand.message))
                {
                    if (Int32.TryParse(twitchcommand.message, out int partNumber))
                    {
                        if (partNumber >= 0 && partNumber < Enum.GetValues(typeof(PartEnum)).Length)
                        {
                            PartEnum partEnum = (PartEnum)partNumber;
                            userPS.SetPart(partEnum, twitchcommand.argument);
                        }
                    }

                    if (customColors.TryGetValue(twitchcommand.message.ToUpper(), out string hexColor))
                    {
                        twitchcommand.message = hexColor;
                    }

                    if (ColorUtility.TryParseHtmlString(twitchcommand.message, out Color scol))
                    {
                        userPS.SetSecondaryColor(scol);
                    }
                }
            }

            break;

        case CommandArg.COMMIT:
        case CommandArg.READY:
            if (_playerSlots.GetPlayerSlotByName(out userPS, twitchcommand.username))
            {
                userPS.UserReady();
            }

            break;

        case CommandArg.RANDOMIZE:
            if (_playerSlots.GetPlayerSlotByName(out userPS, twitchcommand.username))
            {
                userPS.Randomize();
            }

            break;

        default:
            break;
        }
    }