Exemplo n.º 1
0
        public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
        {
            var channelName = message.GetChannelName();
            var nickName = message.GetSender();

            ircClient.Channels.AddIfNotExist(channelName);

            if (MessageHelper.IsMessageFromMe(message, ircClient.Credentials))
            {
                logger.Write($"We joined channel {channelName}");
                ircClient.TwitchService.AddToStreamWatchList(channelName);

                var viewers = TwitchApiClient.GetChatters(channelName.Substring(1));
                logger.Write($"Got {viewers.Count} viewers from API. Loading them now:");

                foreach (var viewer in viewers)
                {
                    logger.WriteIndented($"API: {viewer} on channel {channelName}");
                    var user = ircClient.UserService.GetOrCreateUser(viewer, channelName);
                    ircClient.Channels[channelName].AddUser(user);
                }

                var moderators = TwitchApiClient.GetOnlieModerators(channelName.Substring(1));
                logger.Write($"Got {moderators.Count} moderators from API. Loading them now:");

                foreach (var moderator in moderators)
                {
                    logger.WriteIndented($"API: {moderator} (mod) on channel {channelName}");
                    var user = ircClient.UserService.GetOrCreateUser(moderator, channelName);
                    user.IsModerator = true;
                    ircClient.Channels[channelName].AddUser(user);
                }

                logger.Write("Done loading users found through API.");
            }
            else
            {
                //Load any data we have on this client from the database, then add it to our internal list of users
                logger.Write($"JOIN {nickName} on channel {channelName}");
                var user = ircClient.UserService.GetOrCreateUser(nickName, channelName);
                ircClient.Channels[channelName].AddUser(user);
            }
        }
Exemplo n.º 2
0
        public MessageProcessor(PluginManager pluginManager, ILogger logger)
        {
            _logger = logger;

            pluginManager.Compose(this, logger);

            _logger.Write($"Found {HandlerInstances.Count} message handlers:");
            foreach (var messageHandler in HandlerInstances)
            {
                _logger.WriteIndented($"{messageHandler.GetType().Name} ({string.Join(", ", messageHandler.Commands)})");
            }
        }
Exemplo n.º 3
0
        public void Compose(object target, ILogger logger)
        {
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var owningAssemblyCatalog = new AssemblyCatalog(_callingAssembly);

            //load any plugins from the plugins folder
            var pluginsCatalog = new DirectoryCatalog("Plugins", "*.dll");

            var catalog = new AggregateCatalog(assemblyCatalog, pluginsCatalog, owningAssemblyCatalog);
            var container = new CompositionContainer(catalog);
            container.SatisfyImportsOnce(target);

            logger.Write("Handlers loaded:");
            logger.WriteIndented($"{Path.GetFileName(Assembly.GetExecutingAssembly().Location)} ({FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion})");
            logger.WriteIndented($"{Path.GetFileName(_callingAssembly.Location)} ({FileVersionInfo.GetVersionInfo(_callingAssembly.Location).FileVersion})");

            logger.Write("Plugins loaded:");
            foreach (var file in pluginsCatalog.LoadedFiles)
            {
                logger.WriteIndented($"{Path.GetFileName(file).ToLower()} ({FileVersionInfo.GetVersionInfo(file).FileVersion})");
            }
        }