Beispiel #1
0
        public override IrcMessage ProcessMessage(IrcMessage message)
        {
            // Whenever it encounters a URL, the Slack IRC relay does two things:
            // First, it inserts an HTTP URL after everything it thinks might be formatted like a domain name (or an incorrectly formatted URL),
            // With the inserted URL pointing to the previously mentioned domain.
            // Additionally, it adds some spaces around the URL, just for good measure.
            // Second, while it doesn't add a URL after any correctly formatted URLs, it will, in its infinite wisdom,
            // nonetheless decide to add a space after that URL.
            // Guess who's going to have to fix that?

            // When in doubt, regex. This is ugly as hell, but it mostly works.
            // Start by removing all those superflous spaces. Replace HTTP(S):// with slack-workaround:// to mark a URL as handled, so it won't
            // accidentally be matched again in the next recursion.
            var newMessage = RecursiveReplace(message.Message, @"^(.*?)(https?:\/\/)(.*?)( )(.*)$", "$1slack-workaround://$3$5");
            newMessage = newMessage.Replace("slack-workaround://", "http://");

            // Now let's get rid of those extra URLs.
            newMessage = RecursiveReplace(newMessage, @"^(.*? |)(.+)( https?:\/\/\2)(.*)$", "$1slack-workaround://$2$4");
            newMessage = newMessage.Replace("slack-workaround://", "");

            return new IrcMessage(message.Sender, message.Channel, newMessage, message.Action);
        }
Beispiel #2
0
 public virtual IrcMessage ProcessMessage(IrcMessage message)
 {
     return message;
 }
Beispiel #3
0
 // Convert a message object to a raw string and send it.
 public bool SendMessage(IrcMessage message)
 {
     return(SendString(IrcMessage.MakeString(message)));
 }