public static void UserInfo(ChatMessage user, string body, DefaultBotCommand command)
        {
            string responseMessage;

            try
            {
                var      tmpUser       = AssistantDb.Instance.Viewers.GetAll().First(user1 => user1.Username == body);
                DateTime?startingPoint = new DateTime();
                TimeSpan watchingTime  = tmpUser.WatchingTime.Subtract(startingPoint.Value);
                string   time          = $"{watchingTime:hh\\:mm\\:ss}";
                responseMessage = $@"info by user : {tmpUser.Username} 
                 ||| { ConfigSet.Config.CoinConfig.CoinsName} : {tmpUser.Coins} 
                 ||| Watching Time : {time} 
                 ||| IsFollower : {tmpUser.IsFollower} 
                 ||| IsSubscriber : {tmpUser.IsSubscriber} 
                 ||| First connect to Stream ({tmpUser.FirstConnectToStream}) 
                 ||| Last connect to Stream ({tmpUser.LastConnectToStream})
                 ||| Last coin update ({tmpUser.LastCoinUpdate})
                  ";
            }
            catch (Exception e)
            {
                responseMessage = $"User {body} not found";
            }

            Bot.CommandMessage(user.Username, responseMessage, command);
        }
        public static void Coins(ChatMessage user, string body, DefaultBotCommand command)
        {
            var    tmpUser         = AssistantDb.Instance.Viewers.GetAll().First(user1 => user1.Username == user.Username);
            string responseMessage = $"You balance : {tmpUser.Coins} { ConfigSet.Config.CoinConfig.CoinsName}";

            Bot.CommandMessage(user.Username, responseMessage, command);
        }
        private static void Help(ChatMessage user, string body, DefaultBotCommand command)
        {
            int currentIndex = PrintCommandList(CommandsController.DefaultCommandsList, 0, user, command);

            currentIndex += PrintCommandList(CommandsController.PlayerCommandsList, currentIndex, user, command);
            PrintCommandList(CommandsController.CustomCommandsList, currentIndex, user, command);
        }
        private static void InitAllCommands()
        {
            List <DefaultCommand> defaultCommands = AssistantDb.Instance.DefaultCommands.GetAll().ToList();

            foreach (var command in defaultCommands)
            {
                DefaultBotCommand newCommand = new DefaultBotCommand(command);
                newCommand.SetNewAction(DefaultCommandsFunctional.Actions[command.Action]);
                DefaultCommandsList.Add(newCommand);
            }

            List <PlayerCommand> playerCommands = AssistantDb.Instance.PlayerCommands.GetAll().ToList();

            foreach (var command in playerCommands)
            {
                PlayerBotCommand newCommand = new PlayerBotCommand(command);
                newCommand.SetNewAction(PlayerCommandsFunctional.Actions[command.Action]);
                PlayerCommandsList.Add(newCommand);
            }

            List <CustomCommand> customCoommands = AssistantDb.Instance.CustomCommands.GetAll().ToList();

            foreach (var command in customCoommands)
            {
                CustomBotCommand newCommand = new CustomBotCommand(command);
                newCommand.SetNewAction(CustomCommandsFunctional.Actions[command.Action]);
                newCommand.ResponseMessage = command.ResponseMessage;
                CustomCommandsList.Add(newCommand);
            }
        }
示例#5
0
        private void ButtonBase_OnClick(object sender, System.Windows.RoutedEventArgs e)
        {
            int id = Int32.Parse(((Button)sender).Tag.ToString());
            DetailsCommandSettingsWindow settingsWindow = new DetailsCommandSettingsWindow();
            DefaultBotCommand            xCommand       = CommandsController.DefaultCommandsList.FirstOrDefault(command => command.Id == id);

            settingsWindow.DataContext = new DetailsCommandSettingsViewModel <DefaultBotCommand>(xCommand);
            settingsWindow.ShowDialog();
            //viewModel.DeleteTimerById(id);
        }
        //Other methods
        public static void UpTime(ChatMessage user, string body, DefaultBotCommand command)
        {
            string responseMessage = "";

            if (TwitchBotGlobalObjects.IsStreamOnline)
            {
                responseMessage = $"Stream up time ({TwitchBotGlobalObjects.StreamUpTime})";
            }
            else
            {
                responseMessage = "Stream offline !";
            }
            Bot.CommandMessage(user.Username, responseMessage, command);
        }
        public static bool ExecuteCommandByName(ChatMessage user, string commandName, string commandBody = null)
        {
            try
            {
                TwitchBotGlobalObjects.CheckAndAddOrEditUserIfNeed(user);
                DefaultBotCommand xBotCommand = DefaultCommandsList.FirstOrDefault(command => "!" + command.Name == commandName);
                TryExecuteCommand(user, commandBody, xBotCommand);
                PlayerBotCommand xPlayerCommand = PlayerCommandsList.FirstOrDefault(command => "!" + command.Name == commandName);
                TryExecuteCommand(user, commandBody, xPlayerCommand);

                CustomBotCommand xCustomCommand = CustomCommandsList.FirstOrDefault(command => "!" + command.Name == commandName);
                TryExecuteCommand(user, commandBody, xCustomCommand);
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public static void SayHello(ChatMessage user, string body, DefaultBotCommand command)
        {
            string x = "Hello " + user.Username + " !";

            Bot.CommandMessage(user.Username, x, command);
        }
        private static int PrintCommandList <T>(ObservableCollection <T> commandList, int startIndex, ChatMessage user, DefaultBotCommand command) where T : BotCommand <T>
        {
            string result = "";
            int    i      = 1;

            foreach (var item in commandList)
            {
                if (item.Id == 1 && item is DefaultBotCommand)
                {
                    continue;
                }
                if (item.IsEnabled)
                {
                    if ((result + $" {i+ startIndex}) !{item.Name} - {item.Description} ||").Length >= 350)
                    {
                        Bot.CommandMessage(user.Username, result, command);
                        Thread.Sleep(200);
                        result = "";
                    }
                    result += $" {i + startIndex}) !{item.Name} - {item.Description} ||";
                    i++;
                }
            }
            result = result.Remove(result.Length - 2, 2);
            Bot.CommandMessage(user.Username, result, command);
            return(i - 1);
        }