public Runmode(ILoggerFactory loggerFactory, BaseConfig baseConfig, Func <RunmodeConfig> configLoader) { RunmodeConfig runmodeConfig = configLoader(); _logger = loggerFactory.CreateLogger <Runmode>(); _stopToken = new StopToken(); Setups.Databases repos = Setups.SetUpRepositories(_logger, baseConfig); (_broadcastServer, _overlayConnection) = Setups.SetUpOverlayServer(loggerFactory); _modeBase = new ModeBase(loggerFactory, repos, baseConfig, _stopToken, _overlayConnection, ProcessMessage); _modeBase.InstallAdditionalCommand(new Command("reloadinputconfig", _ => { ReloadConfig(configLoader().InputConfig); return(Task.FromResult(new CommandResult { Response = "input config reloaded" })); })); // TODO felk: this feels a bit messy the way it is done right now, // but I am unsure yet how I'd integrate the individual parts in a cleaner way. InputConfig inputConfig = runmodeConfig.InputConfig; _inputParser = inputConfig.ButtonsProfile.ToInputParser(); _inputBufferQueue = new InputBufferQueue <QueuedInput>(CreateBufferConfig(inputConfig)); _anarchyInputFeed = CreateInputFeedFromConfig(inputConfig); _inputServer = new InputServer(loggerFactory.CreateLogger <InputServer>(), runmodeConfig.InputServerHost, runmodeConfig.InputServerPort, _anarchyInputFeed); }
public DualcoreMode(ILoggerFactory loggerFactory, BaseConfig baseConfig) { _logger = loggerFactory.CreateLogger <DualcoreMode>(); _stopToken = new StopToken(); Setups.Databases repos = Setups.SetUpRepositories(_logger, baseConfig); OverlayConnection overlayConnection; (_broadcastServer, overlayConnection) = Setups.SetUpOverlayServer(loggerFactory); _modeBase = new ModeBase(loggerFactory, repos, baseConfig, _stopToken, overlayConnection); }
public Matchmode(ILoggerFactory loggerFactory, BaseConfig baseConfig, MatchmodeConfig matchmodeConfig) { _matchmodeConfig = matchmodeConfig; _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger<Matchmode>(); _stopToken = new StopToken(); Setups.Databases repos = Setups.SetUpRepositories(_logger, baseConfig); _pokeyenBank = repos.PokeyenBank; _userRepo = repos.UserRepo; (_broadcastServer, _overlayConnection) = Setups.SetUpOverlayServer(loggerFactory); _modeBase = new ModeBase(loggerFactory, repos, baseConfig, _stopToken, _overlayConnection); var bettingCommands = new BettingCommands(() => _bettingPeriod); foreach (Command command in bettingCommands.Commands) _modeBase.InstallAdditionalCommand(command); }
public ModeBase(ILoggerFactory loggerFactory, BaseConfig baseConfig, StopToken stopToken) { PokedexData pokedexData = PokedexData.Load(); Setups.Databases repos = Setups.SetUpRepositories(baseConfig); ArgsParser argsParser = Setups.SetUpArgsParser(repos.UserRepo, pokedexData); var chats = new Dictionary <string, IChat>(); var chatFactory = new ChatFactory(loggerFactory, SystemClock.Instance, repos.UserRepo); foreach (ConnectionConfig connectorConfig in baseConfig.Chat.Connections) { IChat chat = chatFactory.Create(connectorConfig); if (chats.ContainsKey(chat.Name)) { throw new ArgumentException($"chat name '{chat.Name}' was used multiple times. It must be unique."); } chats[chat.Name] = chat; } _chats = chats.ToImmutableDictionary(); foreach (IChat chat in _chats.Values) { chat.IncomingMessage += MessageReceived; } _commandResponders = _chats.Values.ToImmutableDictionary( c => c.Name, c => (ICommandResponder) new CommandResponder(c)); _commandProcessors = _chats.Values.ToImmutableDictionary( c => c.Name, c => Setups.SetUpCommandProcessor(loggerFactory, argsParser, repos, stopToken, baseConfig.Chat, c, c, pokedexData.KnownSpecies)); _messagequeueRepo = repos.MessagequeueRepo; _messagelogRepo = repos.MessagelogRepo; _forwardUnprocessedMessages = baseConfig.Chat.ForwardUnprocessedMessages; _clock = SystemClock.Instance; }
public ModeBase( ILoggerFactory loggerFactory, Setups.Databases repos, BaseConfig baseConfig, StopToken stopToken, OverlayConnection overlayConnection, ProcessMessage?processMessage = null) { IClock clock = SystemClock.Instance; _logger = loggerFactory.CreateLogger <ModeBase>(); PokedexData pokedexData = PokedexData.Load(); ArgsParser argsParser = Setups.SetUpArgsParser(repos.UserRepo, pokedexData); _processMessage = processMessage ?? (_ => Task.FromResult(false)); var chats = new Dictionary <string, IChat>(); var chatFactory = new ChatFactory(loggerFactory, clock, repos.UserRepo, repos.TokensBank, repos.SubscriptionLogRepo, repos.LinkedAccountRepo, overlayConnection); foreach (ConnectionConfig connectorConfig in baseConfig.Chat.Connections) { IChat chat = chatFactory.Create(connectorConfig); if (chats.ContainsKey(chat.Name)) { throw new ArgumentException($"chat name '{chat.Name}' was used multiple times. It must be unique."); } chats[chat.Name] = chat; } _chats = chats.ToImmutableDictionary(); foreach (IChat chat in _chats.Values) { chat.IncomingMessage += MessageReceived; } _commandResponders = _chats.Values.ToImmutableDictionary( c => c.Name, c => (ICommandResponder) new CommandResponder(c)); _commandProcessors = _chats.Values.ToImmutableDictionary( c => c.Name, c => Setups.SetUpCommandProcessor(loggerFactory, argsParser, repos, stopToken, c, c, pokedexData.KnownSpecies)); _messagequeueRepo = repos.MessagequeueRepo; _messagelogRepo = repos.MessagelogRepo; _forwardUnprocessedMessages = baseConfig.Chat.ForwardUnprocessedMessages; _clock = SystemClock.Instance; ILogger <Moderator> moderatorLogger = loggerFactory.CreateLogger <Moderator>(); IImmutableList <IModerationRule> availableRules = ImmutableList.Create <IModerationRule>( new BannedUrlsRule(), new SpambotRule(), new EmoteRule(), new CopypastaRule(clock), new UnicodeCharacterCategoryRule() ); foreach (string unknown in baseConfig.DisabledModbotRules.Except(availableRules.Select(rule => rule.Id))) { moderatorLogger.LogWarning("unknown modbot rule '{UnknownRule}' marked as disabled", unknown); } IImmutableList <IModerationRule> rules = availableRules .Where(rule => !baseConfig.DisabledModbotRules.Contains(rule.Id)) .ToImmutableList(); _moderators = _chats.Values.ToImmutableDictionary( c => c.Name, c => (IModerator) new Moderator(moderatorLogger, c, rules, repos.ModLogRepo, clock)); }