Ejemplo n.º 1
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            string languages = textToSpeechProcessor.TextToSpeechLanguages;

            eventBus.Publish(new SendWhisperMessageRequestedEvent(chatCommandReceivedEvent.User, languages));
            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public async Task <bool> Consume(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            lastUsed = DateTimeOffset.Now;
            await ConsumeCommandSpecific(chatCommandReceivedEvent);

            return(ShouldContinue);
        }
Ejemplo n.º 3
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var commandArgs = chatCommandReceivedEvent.CommandArgs;

            if (string.IsNullOrEmpty(commandArgs))
            {
                return(Task.CompletedTask);
            }

            var facts = configurationManager.LoadConfiguration <FactConfiguration>();

            var splittedArgs = commandArgs.Split(' ');

            if (splittedArgs.Length == 1)
            {
                var fact = facts.GetFact(splittedArgs[0]);
                if (fact == null)
                {
                    return(Task.CompletedTask);
                }

                eventBus.Publish(new SendChannelMessageRequestedEvent(fact, chatCommandReceivedEvent.ChannelName));
                return(Task.CompletedTask);
            }

            var key     = splittedArgs[0];
            var newFact = string.Join(" ", splittedArgs.Skip(1).ToArray());

            facts.AddFact(key, newFact);
            eventBus.Publish(new SendChannelMessageRequestedEvent($"Fact zu {key} angelegt / bearbeitet!", chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        public override async Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            try
            {
                var game = await twitchApiWrapper.GetCurrentGame();

                if (string.IsNullOrEmpty(game))
                {
                    logger.Warning("Es konnte kein Spiel ermittelt werden.");
                    return;
                }

                var channelName    = chatCommandReceivedEvent.ChannelName;
                var deathCounter   = configurationManager.LoadConfiguration <DeathCounterConfiguration>();
                var currentCounter = deathCounter.GetDeath(game);

                if (currentCounter > 0)
                {
                    eventBus.Publish(new SendChannelMessageRequestedEvent($"Im Spiel {game} sind wir bereits {currentCounter}-mal gestorben.", channelName));
                }
                else
                {
                    eventBus.Publish(new SendChannelMessageRequestedEvent($"Im Spiel {game} sind wir bisher noch nie gestorben.", channelName));
                }
            }
            catch (Exception e)
            {
                logger.Error("Ein Fehler ist in ViewDeathCommand aufgetreten. Exception: {e}", e);
            }

            return;
        }
Ejemplo n.º 5
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            DateTime now = DateTime.Now;

            bus.Publish(new TextToSpeechEvent(chatCommandReceivedEvent.User, $"Die Zeitleitung zeigt {now:HH} Uhr {now:mm} an."));
            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            string[] parameters = chatCommandReceivedEvent.CommandArgs.Split(' ');
            if (parameters.Length < 2)
            {
                return(Task.CompletedTask);
            }

            if (!int.TryParse(parameters[0], out int timeInSeconds))
            {
                return(Task.CompletedTask);
            }

            string timerName = string.Join(" ", parameters.Skip(1));

            eventBus.Publish(new TextToSpeechEvent(chatCommandReceivedEvent.User, $"Der Timer {timerName} wurde gestartet."));

            TimeSpan timerLength = TimeSpan.FromSeconds(timeInSeconds);

            DateTime     now    = DateTime.Now;
            DateTime     doneAt = now.Add(timerLength);
            TimerCommand timer  = new TimerCommand(timerName, doneAt, new DefaultTimeProvider());

            timerStore.AddTimer(timer);

            Task.Delay(timerLength).ContinueWith(o => PublishTimeEnded(timer, chatCommandReceivedEvent.User));
            return(Task.CompletedTask);
        }
Ejemplo n.º 7
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var facts = configurationManager.LoadConfiguration <FactConfiguration>();

            facts.RemoveFact(chatCommandReceivedEvent.CommandArgs);
            eventBus.Publish(
                new SendChannelMessageRequestedEvent($"Fakt zu {chatCommandReceivedEvent.CommandArgs} entfernt.", chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
        private void ReadWaitInputs()
        {
            while (true)
            {
                if (StopConsoleThread == true)
                {
                    break;
                }

                //if (Console.KeyAvailable == false)
                //    continue;

                string line = Console.ReadLine();

                User user = UserData;

                //Send message event
                EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
                {
                    UsrMessage = new EvtUserMsgData(user.Name, user.Name,
                                                    user.Name, string.Empty, line)
                };

                UserSentMessageEvent?.Invoke(user, umArgs);

                //Attempt to parse the message as an input
                ProcessMsgAsInput(user, umArgs);

                //Check for a command
                if (line.Length > 0 && line[0] == Globals.CommandIdentifier)
                {
                    //Build args list
                    List <string> argsList  = new List <string>(line.Split(' '));
                    string        argsAsStr = string.Empty;

                    //Remove the command itself and the space from the string
                    if (argsList.Count > 1)
                    {
                        argsAsStr = line.Remove(0, argsList[0].Length + 1);
                    }

                    //Remove command identifier
                    string cmdText = argsList[0].Remove(0, 1);

                    //Now remove the first entry from the list, which is the command, retaining only the arguments
                    argsList.RemoveAt(0);

                    EvtChatCommandArgs chatcmdArgs = new EvtChatCommandArgs();
                    EvtUserMsgData     msgData     = new EvtUserMsgData(user.Name, user.Name, user.Name, string.Empty, line);

                    chatcmdArgs.Command = new EvtChatCommandData(argsList, argsAsStr, msgData, Globals.CommandIdentifier, cmdText);

                    ChatCommandReceivedEvent?.Invoke(UserData, chatcmdArgs);
                }
            }
        }
Ejemplo n.º 9
0
        public override async Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var userId = await twitchApiWrapper.GetUserIdByUsername(chatCommandReceivedEvent.CommandArgs);

            var birthdayConfiguration = configurationManager.LoadConfiguration <BirthdaysConfiguration>();

            birthdayConfiguration.DeleteBirthday(userId);

            eventBus.Publish(new SendChannelMessageRequestedEvent("Geburstag erfolgreich gelöscht!", chatCommandReceivedEvent.ChannelName));
        }
Ejemplo n.º 10
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var channelUpdate = new UpdateChannelEvent
            {
                Title = chatCommandReceivedEvent.CommandArgs,
                Game  = null
            };

            eventBus.Publish(channelUpdate);
            return(Task.CompletedTask);
        }
Ejemplo n.º 11
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            if (textToSpeechProcessor.TryGetLanguage(chatCommandReceivedEvent.CommandArgs, out string language)) // TODO !!
            {
                var greetingConfiguration = configurationManager.LoadConfiguration <GreetingConfiguration>();
                greetingConfiguration.AddGreeting(chatCommandReceivedEvent.User, language);
                configurationManager.WriteConfiguration(greetingConfiguration);
                return(Task.CompletedTask);
            }

            eventBus.Publish(new SendChannelMessageRequestedEvent($"Die Sprache {chatCommandReceivedEvent.CommandArgs} spreche ich leider nicht.", chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
        private void ReadWaitInputs()
        {
            while (true)
            {
                if (StopConsoleThread == true)
                {
                    break;
                }

                string line = Console.ReadLine();

                //Send message event
                EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
                {
                    UsrMessage = new EvtUserMsgData(TerminalUsername, TerminalUsername, TerminalUsername,
                                                    string.Empty, line)
                };

                UserSentMessageEvent?.Invoke(umArgs);

                //Check for a command
                if (line.Length > 0 && line[0] == CommandIdentifier)
                {
                    //Build args list
                    List <string> argsList  = new List <string>(line.Split(' '));
                    string        argsAsStr = string.Empty;

                    //Remove the command itself and the space from the string
                    if (argsList.Count > 1)
                    {
                        argsAsStr = line.Remove(0, argsList[0].Length + 1);
                    }

                    //Remove command identifier
                    string cmdText = argsList[0].Remove(0, 1);

                    //Now remove the first entry from the list, which is the command, retaining only the arguments
                    argsList.RemoveAt(0);

                    EvtChatCommandArgs chatcmdArgs = new EvtChatCommandArgs();
                    EvtUserMsgData     msgData     = new EvtUserMsgData(TerminalUsername, TerminalUsername, TerminalUsername,
                                                                        string.Empty, line);

                    chatcmdArgs.Command = new EvtChatCommandData(argsList, argsAsStr, msgData, CommandIdentifier, cmdText);

                    ChatCommandReceivedEvent?.Invoke(chatcmdArgs);
                }
            }
        }
Ejemplo n.º 13
0
        private void OnChatCommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            ChatMessage cMsg = e.Command.ChatMessage;

            EvtUserMsgData msgData = new EvtUserMsgData(cMsg.UserId, cMsg.Username, cMsg.DisplayName,
                                                        cMsg.Channel, cMsg.Message);

            EvtChatCommandArgs chatCmdArgs = new EvtChatCommandArgs
            {
                Command = new EvtChatCommandData(e.Command.ArgumentsAsList, e.Command.ArgumentsAsString,
                                                 msgData, e.Command.CommandIdentifier, e.Command.CommandText)
            };

            ChatCommandReceivedEvent?.Invoke(chatCmdArgs);
        }
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            switch (chatCommandReceivedEvent.CommandText)
            {
            case "tcmd+":
                AddCommand(chatCommandReceivedEvent);
                return(Task.CompletedTask);

            case "tcmd-":
                DeleteCommand(chatCommandReceivedEvent);
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 15
0
        public override async Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var deathConfig = configurationManager.LoadConfiguration <DeathCounterConfiguration>();
            var game        = await twitchApiWrapper.GetCurrentGame();

            if (!string.IsNullOrEmpty(game))
            {
                var newCount = deathConfig.IncreaseDeath(game);
                eventBus.Publish(new SendChannelMessageRequestedEvent($"Oha. Damit sind wir in '{game}' bereits {newCount}-mal gestorben.", chatCommandReceivedEvent.ChannelName));
            }
            else
            {
                logger.Warning("Es konnte kein Spiel ermittelt werden.");
            }
        }
        private void DeleteCommand(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var config = configurationManager.LoadConfiguration <TargetedTextCommandConfiguration>();

            if (config.DeleteCommand(chatCommandReceivedEvent.CommandArgs))
            {
                eventBus.Publish(new SendChannelMessageRequestedEvent(
                                     $"Command '{chatCommandReceivedEvent.CommandArgs}' erfolgreich entfernt.",
                                     chatCommandReceivedEvent.ChannelName));
                logger.Debug($"Command {chatCommandReceivedEvent.CommandArgs} erfolgreich entfernt.");
            }
            else
            {
                logger.Debug($"Es wurde kein Command {chatCommandReceivedEvent.CommandArgs} gefunden.");
            }
        }
Ejemplo n.º 17
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            // tbd: This could be enriched with logo and other informations of the streamer if this should be shown on screen

            var args = chatCommandReceivedEvent.CommandArgs;

            if (args.StartsWith("@"))
            {
                args = args.Substring(1);
            }

            eventBus.Publish(new SendChannelMessageRequestedEvent(
                                 $"Schaut euch auch {args} an und lasst eventuell einen Follow da: https://twitch.tv/{args}",
                                 chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
Ejemplo n.º 18
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            string[] namechangeParameters = chatCommandReceivedEvent.CommandArgs.Split(';');
            if (namechangeParameters.Length != 2)
            {
                return(Task.CompletedTask);
            }

            var usernameConfiguration = configurationManager.LoadConfiguration <UsernameConfiguration>();

            if (!usernameConfiguration.FindUserByRealUsername(namechangeParameters[0], out ChannelUser user))
            {
                return(Task.CompletedTask);
            }

            usernameConfiguration.AddUsername(user.WithResolvedUsername(namechangeParameters[1]));
            return(Task.CompletedTask);
        }
Ejemplo n.º 19
0
        private void ProcessChatCommandReceivedEvent(ChatCommandReceivedEvent @event)
        {
            var chatCommands = chatCommandResolver.ResolveAllChatCommands();

            foreach (var command in chatCommands)
            {
                if (command.CanConsume(@event))
                {
                    var shouldContinue = command.Consume(@event).Result;
                    if (!shouldContinue)
                    {
                        return;
                    }
                }
            }

            var simpleTextCommandConfiguration = configurationManager.LoadConfiguration <SimpleTextCommandConfiguration>();

            if (simpleTextCommandConfiguration.Commands.ContainsKey(@event.CommandText))
            {
                string optionalUser = @event.OptionalUser;
                if (string.IsNullOrEmpty(optionalUser))
                {
                    bus.Publish(new SendChannelMessageRequestedEvent(simpleTextCommandConfiguration.Commands[@event.CommandText], @event.ChannelName));
                    return;
                }

                bus.Publish(new SendChannelMessageRequestedEvent($"{optionalUser}: {simpleTextCommandConfiguration.Commands[@event.CommandText]}", @event.ChannelName));
                return;
            }

            var targetedTextCommandConfiguration = configurationManager.LoadConfiguration <TargetedTextCommandConfiguration>();

            if (targetedTextCommandConfiguration.Commands.ContainsKey(@event.CommandText))
            {
                var targetCommand = new TargetCommand(@event.CommandArgs, targetedTextCommandConfiguration.Commands[@event.CommandText], @event.User.Username);
                if (targetCommand.IsValid())
                {
                    bus.Publish(new SendChannelMessageRequestedEvent(targetCommand.ResolvePreparedText(), @event.ChannelName));
                    return;
                }
            }
        }
Ejemplo n.º 20
0
        public override async Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var args = chatCommandReceivedEvent.CommandArgs.Split(' ');

            if (args.Length != 2)
            {
                return;
            }

            var userId = await twitchApiWrapper.GetUserIdByUsername(args[0]);

            var birthday = DateTime.Parse(args[1]);

            var birthdayConfig = configurationManager.LoadConfiguration <BirthdaysConfiguration>();

            birthdayConfig.AddBirthday(birthday, userId);

            eventBus.Publish(new SendChannelMessageRequestedEvent("Geburstag erfolgreich angelegt!", chatCommandReceivedEvent.ChannelName));
        }
Ejemplo n.º 21
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            // TODO: Vielleicht lieber Zurück aus der Zukunft Daten? 1955, 1985, 2015
            ChannelUser user        = chatCommandReceivedEvent.User;
            string      channelName = chatCommandReceivedEvent.ChannelName;

            int year = random.Next(1400, 2180);

            eventBus.Publish(new SendChannelMessageRequestedEvent($"{user.RealUsername} ist zurück von der Zeitreise aus dem Jahr {year}", channelName));

            var facts        = configurationManager.LoadConfiguration <FactConfiguration>();
            var yearAsString = Convert.ToString(year);
            var fact         = facts.GetFact(yearAsString);

            if (fact != null)
            {
                eventBus.Publish(new SendChannelMessageRequestedEvent($"Interessanter Fakt über {yearAsString}: {fact}", channelName));
            }

            return(Task.CompletedTask);
        }
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var splittedString = chatCommandReceivedEvent.CommandArgs.Split(' ');
            var command        = splittedString[0];

            var simpleTextCommandConfiguration = configurationManager.LoadConfiguration <SimpleTextCommandConfiguration>();

            switch (chatCommandReceivedEvent.CommandText)
            {
            case "+":
                var commandText = string.Join(" ", splittedString.Skip(1));
                simpleTextCommandConfiguration.AddOrUpdateCommand(command, commandText);
                break;

            case "-":
                simpleTextCommandConfiguration.DeleteCommand(command);
                break;
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 23
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var facts = configurationManager.LoadConfiguration <FactConfiguration>();

            if (string.IsNullOrEmpty(chatCommandReceivedEvent.CommandArgs))
            {
                var randomFact = facts.GetRandomFact();

                if (randomFact != null)
                {
                    eventBus.Publish(new SendChannelMessageRequestedEvent(randomFact, chatCommandReceivedEvent.ChannelName));
                }

                return(Task.CompletedTask);
            }

            var fact = facts.GetFact(chatCommandReceivedEvent.CommandArgs);

            eventBus.Publish(new SendChannelMessageRequestedEvent(fact, chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
Ejemplo n.º 24
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            var timerCommands = timerStore.GetAllTimers();

            if (!timerCommands.Any())
            {
                eventBus.Publish(new SendChannelMessageRequestedEvent($"Es sind keine Timer aktiv!", chatCommandReceivedEvent.ChannelName));
                return(Task.CompletedTask);
            }

            List <string> expiringTimers = new List <string>();

            foreach (var timer in timerCommands)
            {
                expiringTimers.Add($"{timer.Name}: {timer.FormattedTimeLeft}");
            }

            string expiringTimerOutput = string.Join(", ", expiringTimers);

            eventBus.Publish(new SendChannelMessageRequestedEvent($"Folgende Timer sind aktiv -> {expiringTimerOutput}", chatCommandReceivedEvent.ChannelName));
            return(Task.CompletedTask);
        }
        private void AddCommand(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            if (string.IsNullOrEmpty(chatCommandReceivedEvent.CommandArgs))
            {
                logger.Debug($"Es wurde kein Command eingegeben.");
                return;
            }

            var commandArgs = chatCommandReceivedEvent.CommandArgs.Split(' ');

            if (commandArgs.Length < 2)
            {
                logger.Debug($"Es wurden nicht genug Args für Command eingegeben.");
                return;
            }

            var text  = string.Join(" ", commandArgs.Skip(1).ToArray());
            var regex = new Regex(@"\$me|\$[\d]+");

            if (!regex.IsMatch(text))
            {
                logger.Debug($"Command {commandArgs[0]} enthält kein Target und wird nicht angelegt.");
                eventBus.Publish(new SendChannelMessageRequestedEvent(
                                     $"Command '{commandArgs[0]}' enthielt kein Target und wird nicht angelegt. Benutzer !+ stattdessen.",
                                     chatCommandReceivedEvent.ChannelName));
                return;
            }

            var config = configurationManager.LoadConfiguration <TargetedTextCommandConfiguration>();

            if (config.AddOrUpdateCommand(commandArgs[0], text))
            {
                logger.Debug($"Command {commandArgs[0]} erfolgreich angelegt.");
                eventBus.Publish(new SendChannelMessageRequestedEvent(
                                     $"Command '{commandArgs[0]}' erfolgreich angelegt.",
                                     chatCommandReceivedEvent.ChannelName));
                return;
            }
        }
Ejemplo n.º 26
0
 public abstract Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent);
Ejemplo n.º 27
0
 public bool CanConsume(ChatCommandReceivedEvent chatCommandReceivedEvent)
 {
     return(Commands.Contains(chatCommandReceivedEvent.CommandText) &&
            chatCommandReceivedEvent.IsForUserType(ElligableUserType) &&
            lastUsed.Add(Cooldown) < DateTimeOffset.Now);
 }