Exemplo n.º 1
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.  This includes loading any configuration files,
        /// starting services, etc.  Allowed to throw Exceptions.
        ///
        /// This function should be used to validates that the environment is good for the plugin.
        /// For example, it has all dependencies installed, config files are in the correct spot, etc.
        /// It should also load GetHandlers() with the handlers.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            this.urlReader = new UrlReader(initor.Log, initor.HttpClient);

            MessageHandlerConfig msgConfig = new MessageHandlerConfig
            {
                LineRegex  = ".+",
                LineAction = this.HandleMessage
            };

            MessageHandler handler = new MessageHandler(
                msgConfig
                );

            this.handlers.Add(handler);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles a message from the channel.
        /// </summary>
        /// <param name="writer">The IRC Writer to write to.</param>
        /// <param name="response">The response from the channel.</param>
        private async void HandleMessage(IIrcWriter writer, IrcResponse response)
        {
            string url;

            if (UrlReader.TryParseUrl(response.Message, out url))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("@{0}: Here's a description of that URL: ", response.RemoteUser);
                builder.Append(await this.urlReader.GetDescription(url));

                writer.SendMessageToUser(
                    builder.ToString(),
                    response.Channel
                    );
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles a message from the channel.
        /// </summary>
        private async void HandleMessage(MessageHandlerArgs args)
        {
            string url;

            if (UrlReader.TryParseUrl(args.Message, out url))
            {
                UrlResponse urlResponse = await this.urlReader.AsyncGetDescription(url);

                if (urlResponse.IsValid)
                {
                    args.Writer.SendMessage(
                        string.Format("Title: {0}", urlResponse.TitleShortened),
                        args.Channel
                        );
                }
            }
        }
Exemplo n.º 4
0
        // -------- Constructor --------

        /// <summary>
        /// Constructor.
        /// </summary>
        public UrlBot()
        {
            this.urlReader = new UrlReader();
            this.handlers  = new List <IIrcHandler>();
        }