private async void ExecuteCSharpScript(string code)
        {
            //Kimimaru: Store the default console output stream
            TextWriter defaultOut = Console.Out;

            try
            {
                //Kimimaru: Output any Console output to the chat
                //To do this, we're overriding the Console's output stream
                using (BotWriter writer = new BotWriter())
                {
                    Console.SetOut(writer);
                    BotProgram.IgnoreConsoleLog = true;

                    var script = await CSharpScript.RunAsync(code, ScriptCompileOptions);

                    Console.SetOut(defaultOut);
                    BotProgram.IgnoreConsoleLog = false;
                }
            }
            catch (CompilationErrorException exception)
            {
                BotProgram.QueueMessage($"Compiler error: {exception.Message}");
            }
            //Regardless of what happens, return the output stream to the default
            finally
            {
                Console.SetOut(defaultOut);
                BotProgram.IgnoreConsoleLog = false;
            }
        }
Пример #2
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            string name        = e.Command.ChatMessage.DisplayName;
            string nameToLower = name.ToLower();

            User user = BotProgram.GetOrAddUser(nameToLower);

            if (user == null)
            {
                return;
            }

            if (user.OptedOut == false)
            {
                user.SetOptOut(true);

                BotProgram.SaveBotData();
                BotProgram.MsgHandler.QueueMessage("Opted out of bot stats!");
                return;
            }
            else if (user.OptedOut == true)
            {
                user.SetOptOut(false);

                BotProgram.SaveBotData();
                BotProgram.MsgHandler.QueueMessage("Opted back into bot stats!");
                return;
            }
        }
Пример #3
0
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args == null || args.Count <= 0)
            {
                BotProgram.QueueMessage("Choose one or more people to high five!");
                return;
            }

            string highFive = string.Empty;

            for (int i = 0; i < args.Count; i++)
            {
                int nextInd = i + 1;

                if (i > 0)
                {
                    highFive += ", ";
                    if (nextInd == args.Count)
                    {
                        highFive += "and ";
                    }
                }

                highFive += args[i];
            }

            BotProgram.QueueMessage($"{e.Command.ChatMessage.DisplayName} high fives {highFive}!");
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            Expression exp = null;

            try
            {
                string expression = e.Command.ChatMessage.Message.Replace($"{Globals.CommandIdentifier}calculate", string.Empty);

                exp                    = new Expression(expression);
                exp.Options            = EvaluateOptions.IgnoreCase;
                exp.EvaluateParameter += Exp_EvaluateParameter;
                exp.EvaluateFunction  += Exp_EvaluateFunction;

                string finalExpr = exp.Evaluate().ToString();
                //string finalExpr = CalculateTable.Compute(expression, null).ToString();

                BotProgram.QueueMessage(finalExpr);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);

                BotProgram.QueueMessage(exc.Message);//"Sorry, I can't calculate that!");
            }
            finally
            {
                if (exp != null)
                {
                    exp.EvaluateParameter -= Exp_EvaluateParameter;
                    exp.EvaluateFunction  -= Exp_EvaluateFunction;
                }
            }
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            //Reload settings and bot data
            BotProgram.LoadSettingsAndBotData();

            BotProgram.QueueMessage("Reloaded bot settings and data!");
        }
Пример #6
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count != 1)
            {
                BotProgram.MsgHandler.QueueMessage($"{Globals.CommandIdentifier}removemacro usage: \"#macroname\"");
                return;
            }

            string macroName = args[0].ToLowerInvariant();

            if (BotProgram.BotData.Macros.ContainsKey(macroName) == true)
            {
                char macroFirstChar = macroName[1];

                //Remove from the parser macro list
                List <string> parserMacroList = BotProgram.BotData.ParserMacroLookup[macroFirstChar];
                parserMacroList.Remove(macroName);
                if (parserMacroList.Count == 0)
                {
                    BotProgram.BotData.ParserMacroLookup.Remove(macroFirstChar);
                }

                BotProgram.BotData.Macros.TryRemove(macroName, out string removedMacro);
                BotProgram.SaveBotData();

                BotProgram.MsgHandler.QueueMessage($"Removed macro {macroName}.");
            }
            else
            {
                BotProgram.MsgHandler.QueueMessage($"Macro \"{macroName}\" could not be found.");
            }
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            string args = e.Command.ArgumentsAsString;

            if (string.IsNullOrEmpty(args) == true)
            {
                BotProgram.QueueMessage("Usage: \"Input\"");
                return;
            }

            //Parse the input
            (bool valid, List <List <Parser.Input> > inputList, bool containsStartInput, int durationCounter)
            parsedData = default;

            try
            {
                string parse_message = Parser.Expandify(Parser.PopulateMacros(args));

                parsedData = Parser.Parse(parse_message);
            }
            catch
            {
                parsedData.valid = false;
            }

            if (parsedData.valid == false)
            {
                BotProgram.QueueMessage("Invalid input. Note that length cannot be determined for dynamic macros without inputs filled in.");
                return;
            }

            BotProgram.QueueMessage($"Total length: {parsedData.durationCounter}ms");
        }
Пример #8
0
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count > 1)
            {
                BotProgram.QueueMessage("Usage: \"username\"");
                return;
            }

            string username = string.Empty;

            //If no arguments are specified, use the name of the user who performed the command
            if (args.Count == 0)
            {
                username = e.Command.ChatMessage.Username;
            }
            else
            {
                username = args[0];
            }

            User user = BotProgram.GetUser(username, false);

            if (user == null)
            {
                BotProgram.QueueMessage($"User does not exist in database!");
                return;
            }

            //Print the user's information
            BotProgram.QueueMessage($"User: {user.Name} | Level: {user.Level} | Total Inputs: {user.ValidInputs} | Total Messages: {user.TotalMessages}");
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            string[] validInputs = InputGlobals.CurrentConsole.ValidInputs;

            if (validInputs == null || validInputs.Length == 0)
            {
                BotProgram.QueueMessage($"Interesting! There are no valid inputs for {InputGlobals.CurrentConsoleVal}?!");
                return;
            }

            StrBuilder.Clear();

            StrBuilder.Append("Valid inputs for ").Append(InputGlobals.CurrentConsoleVal.ToString()).Append(": ");

            for (int i = 0; i < validInputs.Length; i++)
            {
                StrBuilder.Append(validInputs[i]).Append(", ");
            }

            //Remove trailing comma
            StrBuilder.Remove(StrBuilder.Length - 2, 2);

            string validInputsStr = StrBuilder.ToString();

            BotProgram.QueueMessage(validInputsStr);
        }
Пример #10
0
        public override void HandleArgsOnConsoleChange(List <string> arguments)
        {
            if (arguments?.Count == 0)
            {
                return;
            }

            for (int i = 0; i < arguments.Count; i++)
            {
                //Check for enum mode
                if (Enum.TryParse(arguments[i], true, out InputModes mode) == true)
                {
                    InputMode = mode;
                    BotProgram.QueueMessage($"Changed Wii input mode to {mode}!");
                }

                //Kimimaru: I'm debating including the ability to set it by number, so we'll keep it commented until a decision is made
                //if (int.TryParse(arguments[i], out int inputMode) == true)
                //{
                //    InputModes newInputMode = (InputModes)inputMode;
                //    InputMode = (InputModes)inputMode;
                //    Console.WriteLine($"Changed Wii input mode to {newInputMode}");
                //}
            }
        }
Пример #11
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            string msg = e.Command.ArgumentsAsString;

            if (msg == null)
            {
                msg = string.Empty;
            }

            BotProgram.BotData.GameMessage = msg;

            //Always save the message to a file so it updates on OBS

            /*For reading from this file on OBS:
             * 1. Create Text (GDI+)
             * 2. Check the box labeled "Read from file"
             * 3. Browse and select the file
             */
            if (Globals.SaveToTextFile(Globals.GameMessageFilename, BotProgram.BotData.GameMessage) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Unable to save message to file");
            }

            BotProgram.SaveBotData();
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            string displayLower = e.Command.ChatMessage.DisplayName.ToLower();

            if (GroupDuelCommand.UsersInDuel.ContainsKey(displayLower) == false)
            {
                BotProgram.QueueMessage("You're not in the group duel!");
                return;
            }
            else
            {
                long betAmt = GroupDuelCommand.UsersInDuel[displayLower];
                GroupDuelCommand.UsersInDuel.Remove(displayLower);

                BotProgram.QueueMessage($"{e.Command.ChatMessage.DisplayName} has backed out of the group duel and retained their {betAmt} credit(s)!");

                //Check for ending the group duel if there are no longer enough participants
                if (GroupDuelCommand.DuelStarted == true && GroupDuelCommand.UsersInDuel.Count < GroupDuelCommand.MinUsersForDuel)
                {
                    GroupDuelCommand.StopGroupDuel();

                    int count = GroupDuelCommand.UsersInDuel.Count;

                    BotProgram.QueueMessage($"Oh no! The group duel has ended since there no longer enough participants. {GroupDuelCommand.MinUsersForDuel - count} more is/are required to start it up again!");
                }
            }
        }
Пример #13
0
        public void HandleCommand(object sender, OnChatCommandReceivedArgs e)
        {
            if (e == null || e.Command == null || e.Command.ChatMessage == null)
            {
                Console.WriteLine($"{nameof(OnChatCommandReceivedArgs)} or its Command or ChatMessage is null! Not parsing command");
                return;
            }

            string userToLower = e.Command.ChatMessage.DisplayName.ToLower();

            //Don't handle certain users (Ex. MrMacroBot)
            if (ExemptUsers.Contains(userToLower) == true)
            {
                Console.WriteLine($"User {e.Command.ChatMessage.DisplayName} is exempt and I won't take commands from them");
                return;
            }

            User user = BotProgram.GetOrAddUser(userToLower);

            string commandToLower = e.Command.CommandText.ToLower();

            if (CommandDict.TryGetValue(commandToLower, out BaseCommand command) == true)
            {
                //Handle permissions
                if (user.Level >= command.AccessLevel)
                {
                    command.ExecuteCommand(sender, e);
                }
                else
                {
                    BotProgram.QueueMessage(INVALID_ACCESS_MESSAGE);
                }
            }
        }
Пример #14
0
        //Clean up anything we need to here
        public void Dispose()
        {
            if (Initialized == false)
            {
                return;
            }

            UnsubscribeEvents();

            RoutineHandler?.CleanUp();

            CommandHandler.CleanUp();
            ClientService?.CleanUp();

            MsgHandler?.CleanUp();

            if (ClientService?.IsConnected == true)
            {
                ClientService.Disconnect();
            }

            //Clean up and relinquish the virtual controllers when we're done
            InputGlobals.ControllerMngr?.CleanUp();

            instance = null;
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            string logMessage = e.Command.ArgumentsAsString;

            if (string.IsNullOrEmpty(logMessage) == true)
            {
                BotProgram.QueueMessage("Please enter a message for the log.");
                return;
            }

            DateTime curTime = DateTime.UtcNow;

            //Add a new log
            GameLog newLog = new GameLog();

            newLog.LogMessage = logMessage;
            newLog.User       = e.Command.ChatMessage.Username;

            string date = curTime.ToShortDateString();
            string time = curTime.ToLongTimeString();

            newLog.DateTimeString = $"{date} at {time}";

            BotProgram.BotData.Logs.Add(newLog);
            BotProgram.SaveBotData();

            BotProgram.QueueMessage("Successfully logged message!");
        }
Пример #16
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            //Reload settings and bot data
            BotProgram.LoadSettingsAndBotData();

            BotProgram.MsgHandler.QueueMessage("Reloaded bot settings and data!");
        }
Пример #17
0
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            int randinspiration = Rand.Next(0, RandomInspiration.Length);

            string message = RandomInspiration[randinspiration].Replace("{name}", e.Command.ChatMessage.DisplayName);

            BotProgram.QueueMessage(message);
        }
Пример #18
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count < 2)
            {
                BotProgram.MsgHandler.QueueMessage($"{Globals.CommandIdentifier}addmeme usage: memename memevalue");
                return;
            }

            if (args[0].ElementAt(0) == '/' || args[1].ElementAt(0) == '/')
            {
                BotProgram.MsgHandler.QueueMessage("Memes cannot start with Twitch chat commands!");
                return;
            }

            if (args[0].ElementAt(0) == Globals.CommandIdentifier)
            {
                BotProgram.MsgHandler.QueueMessage($"Memes cannot start with \'{Globals.CommandIdentifier}\'");
                return;
            }

            if (args[0].ElementAt(0) == Globals.MacroIdentifier)
            {
                BotProgram.MsgHandler.QueueMessage($"Memes cannot start with \'{Globals.MacroIdentifier}\'");
                return;
            }

            if (args[0].Length > MAX_MEME_LENGTH)
            {
                BotProgram.MsgHandler.QueueMessage($"The max meme length is {MAX_MEME_LENGTH} characters!");
                return;
            }

            string memeToLower     = args[0].ToLower();
            bool   sendOverwritten = false;

            if (BotProgram.BotData.Memes.ContainsKey(memeToLower) == true)
            {
                BotProgram.BotData.Memes.TryRemove(memeToLower, out string meme);
                sendOverwritten = true;
            }

            string actualMeme = e.Command.ArgumentsAsString.Remove(0, args[0].Length + 1);

            BotProgram.BotData.Memes.TryAdd(memeToLower, actualMeme);

            BotProgram.SaveBotData();

            if (sendOverwritten == true)
            {
                BotProgram.MsgHandler.QueueMessage("Meme overwritten!");
            }
            else
            {
                MemesCommand.CacheMemesString();
            }
        }
Пример #19
0
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> amount = e.Command.ArgumentsAsList;

            if (amount.Count != 1)
            {
                BotProgram.QueueMessage($"Sorry, please enter a valid bet amount!");
                return;
            }

            if (long.TryParse(amount[0], out long creditBet) == true)
            {
                if (creditBet <= 0)
                {
                    BotProgram.QueueMessage("Bet amount must be greater than 0!");
                    return;
                }

                string name        = e.Command.ChatMessage.DisplayName;
                string nameToLower = name.ToLower();

                User user = BotProgram.GetOrAddUser(nameToLower);

                long credits = user.Credits;

                if (creditBet > credits)
                {
                    BotProgram.QueueMessage("Bet amount is greater than credits!");
                }
                else
                {
                    bool   success = (Rand.Next(0, 2) == 0);
                    string message = string.Empty;

                    if (success)
                    {
                        credits += creditBet;
                        message  = $"{name} won {creditBet} credits :D !";
                    }
                    else
                    {
                        credits -= creditBet;
                        message  = $"{name} lost {creditBet} credits :(";
                    }

                    BotProgram.QueueMessage(message);

                    user.Credits = credits;
                    BotProgram.SaveBotData();
                }
            }
            else
            {
                BotProgram.QueueMessage($"Sorry, please enter a valid bet amount!");
            }
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            //If a username was specified, view that user's silenced state
            if (args.Count == 1)
            {
                string username = args[0].ToLowerInvariant();
                User   user     = BotProgram.GetUser(username);

                if (user == null)
                {
                    BotProgram.QueueMessage($"User does not exist in database!");
                }
                else
                {
                    if (user.Silenced == false)
                    {
                        BotProgram.QueueMessage($"User {username} is not currently silenced and can perform inputs.");
                    }
                    else
                    {
                        BotProgram.QueueMessage($"User {username} is currently silenced and cannot perform inputs.");
                    }
                }

                return;
            }

            //No arguments, so print all users who are silenced
            if (BotProgram.BotData.SilencedUsers.Count == 0)
            {
                BotProgram.QueueMessage("No users are silenced. Hurray!");
                return;
            }

            //Copy for safety in case this gets modified during iteration
            string[] silencedNames = new string[BotProgram.BotData.SilencedUsers.Count];
            BotProgram.BotData.SilencedUsers.CopyTo(silencedNames);

            StrBuilder.Clear();

            StrBuilder.Append("Currently silenced users: ");

            for (int i = 0; i < silencedNames.Length; i++)
            {
                StrBuilder.Append(silencedNames[i]).Append(", ");
            }

            //Remove trailing comma
            StrBuilder.Remove(StrBuilder.Length - 2, 2);

            string silencedStr = StrBuilder.ToString();

            BotProgram.QueueMessage(silencedStr);
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            if (string.IsNullOrEmpty(BotProgram.BotData.InfoMessage) == true)
            {
                BotProgram.QueueMessage(EmptyMessage);
                return;
            }

            BotProgram.QueueMessage(BotProgram.BotData.InfoMessage);
        }
Пример #22
0
 public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
 {
     if (BotProgram.BotData != null && BotProgram.BotData.JRData != null)
     {
         BotProgram.QueueMessage($"The biggest jump rope streak is {BotProgram.BotData.JRData.Streak}!");
     }
     else
     {
         BotProgram.QueueMessage("Something went wrong - I can't find the highest Jump Rope streak!");
     }
 }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args == null || args.Count != 2)
            {
                BotProgram.QueueMessage("Please specify a single user followed by the amount of credits you wish to transfer!");
                return;
            }

            string giver        = e.Command.ChatMessage.DisplayName;
            string giverToLower = giver.ToLower();

            string receiver        = args[0];
            string receiverToLower = receiver.ToLower();

            if (giverToLower == receiverToLower)
            {
                BotProgram.QueueMessage("You cannot transfer points to yourself!");
                return;
            }

            //If the user transferring points isn't in the database, add them
            User giverUser    = BotProgram.GetOrAddUser(giverToLower);
            User receiverUser = BotProgram.GetUser(receiverToLower);

            if (receiverUser == null)
            {
                BotProgram.QueueMessage($"{receiver} is not in the database!");
                return;
            }

            long transferAmount = -1L;
            bool success        = long.TryParse(args[1], out transferAmount);

            if (success == false || transferAmount <= 0)
            {
                BotProgram.QueueMessage("Please specify a positive whole number of credits greater than 0!");
                return;
            }

            if (giverUser.Credits < transferAmount)
            {
                BotProgram.QueueMessage("The transfer amount is greater than your credits!");
                return;
            }

            giverUser.Credits    -= transferAmount;
            receiverUser.Credits += transferAmount;
            BotProgram.SaveBotData();

            BotProgram.QueueMessage($"{giver} has transferred {transferAmount} points to {receiver} :D !");
        }
        public static void StopGroupDuel()
        {
            if (DuelStarted == false)
            {
                Console.WriteLine("****Can't stop group duel since it hasn't started!****");
                return;
            }

            BotProgram.RemoveRoutine(BotProgram.FindRoutine <GroupDuelRoutine>());

            DuelStarted = false;
        }
        public static void StartGroupDuel()
        {
            if (DuelStarted == true)
            {
                Console.WriteLine("****Can't start group duel since it already started!****");
                return;
            }

            BotProgram.AddRoutine(new GroupDuelRoutine(GroupDuelMinutes));

            DuelStarted = true;
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            string code = e.Command.ArgumentsAsString;

            if (string.IsNullOrEmpty(code) == true)
            {
                BotProgram.QueueMessage($"Usage: \"C# code\"");
                return;
            }

            ExecuteCSharpScript(code);
        }
Пример #27
0
        private void OnReSubscriber(object sender, OnReSubscriberArgs e)
        {
            User user = BotProgram.GetOrAddUser(e.ReSubscriber.DisplayName, false);

            EvtOnReSubscriptionArgs reSubArgs = new EvtOnReSubscriptionArgs
            {
                ReSubscriptionData = new EvtReSubscriptionData(e.ReSubscriber.UserId, e.ReSubscriber.DisplayName,
                                                               e.ReSubscriber.DisplayName, e.ReSubscriber.Months)
            };

            UserReSubscribedEvent?.Invoke(user, reSubArgs);
        }
Пример #28
0
        private void OnNewSubscriber(object sender, OnNewSubscriberArgs e)
        {
            User user = BotProgram.GetOrAddUser(e.Subscriber.DisplayName, false);

            EvtOnSubscriptionArgs subArgs = new EvtOnSubscriptionArgs
            {
                SubscriptionData = new EvtSubscriptionData(e.Subscriber.UserId, e.Subscriber.DisplayName,
                                                           e.Subscriber.DisplayName)
            };

            UserNewlySubscribedEvent?.Invoke(user, subArgs);
        }
        public BotProgram()
        {
            crashHandler = new CrashHandler();

            instance = this;

            //Below normal priority
            Process thisProcess = Process.GetCurrentProcess();

            thisProcess.PriorityBoostEnabled = false;
            thisProcess.PriorityClass        = ProcessPriorityClass.Idle;
        }
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count < 3)
            {
                BotProgram.MsgHandler.QueueMessage("Usage: \"console\" \"synonymName\" \"input\"");
                return;
            }

            string consoleStr = args[0];

            //Check if a valid console is specified
            if (Enum.TryParse <InputGlobals.InputConsoles>(consoleStr, true, out InputGlobals.InputConsoles console) == false ||
                InputGlobals.Consoles.ContainsKey(console) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Please specify a valid console.");
                return;
            }

            InputSynonymData inputSyns = BotProgram.BotData.InputSynonyms;

            string synonymName = args[1];

            //Get the actual synonym from the remaining arguments
            string actualSynonym = e.Command.ArgumentsAsString.Remove(0, args[0].Length + 1).Remove(0, args[1].Length + 1);

            //Add to the dictionary if it doesn't exist
            if (inputSyns.SynonymDict.TryGetValue(console, out Dictionary <string, string> dict) == false)
            {
                dict = new Dictionary <string, string>(8);
                inputSyns.SynonymDict[console] = dict;
            }

            string message = string.Empty;

            if (dict.ContainsKey(synonymName) == true)
            {
                message = $"Updated input synonym \"{synonymName}\" for \"{actualSynonym}\"!";
            }
            else
            {
                message = $"Added input synonym \"{synonymName}\" for \"{actualSynonym}\"!";
            }

            //Update value and save bot data
            dict[synonymName] = actualSynonym;

            BotProgram.SaveBotData();

            BotProgram.MsgHandler.QueueMessage(message);
        }