Example #1
0
        /*/ Constructors /*/

        /// <summary>
        /// Initializes a new instance of the <see cref="IrcBot"/> class.
        /// </summary>
        /// <param name="juvoClient">Host.</param>
        /// <param name="ircClient">IRC client.</param>
        /// <param name="config">IRC configuration.</param>
        /// <param name="logManager">Log manager.</param>
        public IrcBot(IJuvoClient juvoClient, IIrcClient ircClient, IrcConfigConnection config, ILogManager?logManager = null)
        {
            this.config     = config;
            this.host       = juvoClient;
            this.logManager = logManager;
            this.client     = ircClient;
            this.log        = logManager?.GetLogger(typeof(IrcBot));

            this.client.Network     = IrcClient.LookupNetwork(this.config.Network ?? string.Empty);
            this.client.NickName    = config.Nickname ?? throw new Exception("Nickname is missing from configuration");
            this.client.NickNameAlt = config.NicknameAlt ?? $"{config.Nickname}-";
            this.client.RealName    = config.RealName ?? string.Empty;
            this.client.Username    = config.Ident ?? config.Nickname.ToLowerInvariant();

            this.client.ChannelJoined      += this.Client_ChannelJoined;
            this.client.ChannelMessage     += this.Client_ChannelMessage;
            this.client.ChannelModeChanged += this.Client_ChannelModeChanged;
            this.client.ChannelParted      += this.Client_ChannelParted;
            this.client.Connected          += this.Client_Connected;
            this.client.Disconnected       += this.Client_Disconnected;
            this.client.HostHidden         += this.Client_HostHidden;
            this.client.MessageReceived    += this.Client_MessageReceived;
            this.client.PrivateMessage     += this.Client_PrivateMessage;
            this.client.UserModeChanged    += this.Client_UserModeChanged;
            this.client.UserQuit           += this.Client_UserQuit;
            this.commandToken = config.CommandToken ?? DefaultCommandToken;
        }
Example #2
0
        /// <inheritdoc />
        public IIrcBot Create(IrcConfigConnection config, IServiceProvider services, IJuvoClient host)
        {
            var bot = new IrcBot(
                host,
                services.GetService <IIrcClient>(),
                config,
                services.GetService <ILogManager>());

            return(bot);
        }