public BotMain(List <IChatClient> chatClients, IRepository repository, CommandHandler commandHandler, SubscriberHandler subscriberHandler, FollowerHandler followerHandler) { _chatClients = chatClients; _repository = repository; _commandHandler = commandHandler; _subscriberHandler = subscriberHandler; _followerHandler = followerHandler; }
private readonly int _refreshInterval = 1000;//the milliseconds the bot waits before checking for new messages public BotMain(List <IChatClient> chatClients, IRepository repository, CommandHandler commandHandler, SubscriberHandler subscriberHandler, FollowableSystem followableSystem, AutomatedActionSystem automatedActionSystem) { _chatClients = chatClients; _repository = repository; _commandHandler = commandHandler; _subscriberHandler = subscriberHandler; _followableSystem = followableSystem; _automatedActionSystem = automatedActionSystem; }
public static BotMain NewBot(TwitchClientSettings twitchSettings, string connectionString) { var twitchApi = new TwitchAPI(twitchSettings.TwitchClientId); var twitchChatClient = new TwitchChatClient(twitchSettings, twitchApi); var chatClients = new List <IChatClient> { new ConsoleChatClient(), twitchChatClient, }; var twitchFollowerService = new TwitchFollowerService(twitchApi, twitchSettings); IRepository repository = SetUpDatabase.SetUpRepository(connectionString); var chatUserCollection = new ChatUserCollection(repository); var currencyGenerator = new CurrencyGenerator(chatClients, chatUserCollection); var currencyUpdate = new CurrencyUpdate(1, currencyGenerator); var automatedActionSystem = new AutomatedActionSystem(new List <IIntervalAction> { currencyUpdate }); var rockPaperScissorsGame = new RockPaperScissorsGame(currencyGenerator, automatedActionSystem); var wordList = new List <string> { "apple", "banana", "orange", "mango", "watermellon", "grapes", "pizza", "pasta", "pepperoni", "cheese", "mushroom", "csharp", "javascript", "cplusplus", "nullreferenceexception", "parameter", "argument" }; var hangmanGame = new HangmanGame(currencyGenerator, automatedActionSystem, wordList); var simpleCommands = repository.List <SimpleCommand>(); List <IBotCommand> allCommands = new List <IBotCommand>(); allCommands.AddRange(simpleCommands); allCommands.Add(new GiveCommand(chatUserCollection)); allCommands.Add(new HelpCommand(allCommands)); allCommands.Add(new CommandsCommand(allCommands)); allCommands.Add(new CoinsCommand(repository)); allCommands.Add(new BonusCommand(currencyGenerator)); allCommands.Add(new StreamsCommand(repository)); allCommands.Add(new ShoutOutCommand(twitchFollowerService)); allCommands.Add(new QuoteCommand(repository)); allCommands.Add(new AddQuoteCommand(repository)); allCommands.Add(new AddCommandCommand(repository, allCommands)); allCommands.Add(new RemoveCommandCommand(repository, allCommands)); allCommands.Add(new HangmanCommand(hangmanGame)); allCommands.Add(new RockPaperScissorsCommand(rockPaperScissorsGame)); var commandHandler = new CommandHandler(chatClients, allCommands); var subscriberHandler = new SubscriberHandler(chatClients); var twitchSystem = new FollowableSystem(new[] { twitchChatClient }, twitchFollowerService); var botMain = new BotMain(chatClients, repository, commandHandler, subscriberHandler, twitchSystem, automatedActionSystem); return(botMain); }
public BotMain(IList <IChatClient> chatClients, IRepository repository, IFollowableSystem followableSystem, IAutomatedActionSystem automatedActionSystem, ICommandHandler commandHandler, SubscriberHandler subscriberHandler, CurrencyUpdate currencyUpdate) { _chatClients = chatClients; _repository = repository; _followableSystem = followableSystem; _automatedActionSystem = automatedActionSystem; _commandHandler = commandHandler; _subscriberHandler = subscriberHandler; _currencyUpdate = currencyUpdate; }
public static BotMain NewBot(TwitchClientSettings clientSettings, EfGenericRepo efGenericRepo) { var chatClients = new List <IChatClient> { new ConsoleChatClient(), new TwitchChatClient(clientSettings), }; var commandMessages = efGenericRepo.List(DataItemPolicy <SimpleResponseMessage> .ActiveOnly()); var commandHandler = new CommandHandler(chatClients, commandMessages); var subscriberHandler = new SubscriberHandler(chatClients); var followerHandler = new FollowerHandler(chatClients); var botMain = new BotMain(chatClients, efGenericRepo, commandHandler, subscriberHandler, followerHandler); return(botMain); }
private XtResult RegisterHandler <TMessage>(Action <TMessage> syncCallback = null, Func <TMessage, Task> asyncCallback = null, CancellationToken token = default) where TMessage : class, new() { Exception exception = null; // handle notifies when the server is set up eventHandle = new ManualResetEvent(false); _ = Task.Run(() => { var next = new SubscriberHandler <TMessage> ( new SubscriberSocket(), _configuration, new NetMQ.NetMQPoller(), token, syncCallback: syncCallback, asyncCallback: asyncCallback ); var(success, exception) = next.Setup(); // dispose handler when an exception was registered during setup if (exception is not null) { next.Dispose(); return; } // add subscriber to dispsables to get rid of them later lock (_concurrencyToken) { _handlers.Add(next); } // open resetevent after using setup on the handler and after the poller has started asynchronously eventHandle.Set(); }); eventHandle.WaitOne(); if (exception is not null) { return(XtResult.Failed(exception, "register-subscriber")); } return(XtResult.Success("register-subscriber")); }
public void SubscriberTest() { var file = System.Reflection.Assembly.GetExecutingAssembly() .GetManifestResourceStream("SharpYaml.Tests.files.test12.yaml"); var childrenAdded = 0; var tracker = new YamlNodeTracker(); var fileStream = new StreamReader(file); var yaml = YamlStream.Load(fileStream, tracker); var mapping1 = (YamlMapping)((YamlSequence)yaml[0].Contents)[1]; var mapping2 = (YamlMapping)((YamlSequence)yaml[0].Contents)[2]; var handler = new SubscriberHandler(); tracker.Subscribe(handler, null, "A"); tracker.Subscribe(handler, tracker.GetPaths(yaml[0].Contents)[0], "B"); tracker.Subscribe(handler, tracker.GetPaths(mapping1)[0], "C"); mapping1["key 1"] = new YamlValue("Bla"); Assert.AreEqual(1, handler.ACalls); Assert.AreEqual(1, handler.BCalls); Assert.AreEqual(1, handler.CCalls); mapping2[0] = new KeyValuePair <YamlElement, YamlElement>(new YamlValue("K"), new YamlValue("V")); Assert.AreEqual(2, handler.ACalls); Assert.AreEqual(2, handler.BCalls); Assert.AreEqual(1, handler.CCalls); ((YamlSequence)yaml[0].Contents).Add(new YamlValue("5")); Assert.AreEqual(3, handler.ACalls); Assert.AreEqual(3, handler.BCalls); Assert.AreEqual(1, handler.CCalls); }