public ModeratorCommands(
     IChatModeChanger changer,
     ILinkedAccountRepo linkedAccountRepo,
     IResponseCommandRepo responseCommandRepo)
 {
     _changer             = changer;
     _linkedAccountRepo   = linkedAccountRepo;
     _responseCommandRepo = responseCommandRepo;
 }
Exemplo n.º 2
0
 public record Databases(
     IUserRepo UserRepo,
     IPollRepo PollRepo,
     IBadgeRepo BadgeRepo,
     IBank <User> PokeyenBank,
     IBank <User> TokensBank,
     ICommandLogger CommandLogger,
     IMessagequeueRepo MessagequeueRepo,
     IMessagelogRepo MessagelogRepo,
     ILinkedAccountRepo LinkedAccountRepo,
     ISubscriptionLogRepo SubscriptionLogRepo,
     IModLogRepo ModLogRepo,
     IResponseCommandRepo ResponseCommandRepo
     );
Exemplo n.º 3
0
        private static void SetUpDynamicCommands(
            ILogger logger, CommandProcessor commandProcessor, IResponseCommandRepo responseCommandRepo)
        {
            IImmutableList <ResponseCommand> commands = responseCommandRepo.GetCommands().Result;

            HashSet <string> dynamicallyInstalledCommands = new();

            void InstallCommand(ResponseCommand command)
            {
                Command?existing = commandProcessor.FindCommand(command.Command);

                if (existing != null)
                {
                    logger.LogWarning(
                        "not installing static response command '{Command}' " +
                        "because it conflicts with an existing command", command.Command);
                }
                else
                {
                    commandProcessor
                    .InstallCommand(new Command(command.Command, CommandUtils.StaticResponse(command.Response)));
                    dynamicallyInstalledCommands.Add(command.Command);
                }
            }

            void UninstallCommand(string commandName)
            {
                if (!dynamicallyInstalledCommands.Contains(commandName))
                {
                    return; // this command wasn't added dynamically, probably because it conflicted
                }
                commandProcessor.UninstallCommand(commandName);
                dynamicallyInstalledCommands.Remove(commandName);
            }

            foreach (ResponseCommand command in commands)
            {
                InstallCommand(command);
            }
            responseCommandRepo.CommandRemoved  += (_, name) => UninstallCommand(name);
            responseCommandRepo.CommandInserted += (_, command) => InstallCommand(command);
        }