From e71bf30a9b51aa7d71f44f6b836d15ab22e1e1d1 Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Mon, 12 Oct 2015 10:51:12 -0700 Subject: [PATCH] Url parsing - Added check to see if Youtube title was in youtube result and remove it. --- Modules/Url Parsing/Url_Parsing.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/Url Parsing/Url_Parsing.cs b/Modules/Url Parsing/Url_Parsing.cs index fea5808..7d354ad 100644 --- a/Modules/Url Parsing/Url_Parsing.cs +++ b/Modules/Url Parsing/Url_Parsing.cs @@ -14,6 +14,7 @@ namespace Combot.Modules.Plugins { public class Url_Parsing : Module { + private const string YOUTUBE_URL = "(((youtube.*(v=|/v/))|(youtu\\.be/))(?[-_a-zA-Z0-9]+))"; public override void Initialize() { Bot.IRC.Message.ChannelMessageReceivedEvent += HandleChannelMessage; @@ -70,11 +71,17 @@ namespace Combot.Modules.Plugins Bot.IRC.Command.SendPrivateMessage(message.Channel, string.Format("[Audio] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength))); break; default: - Regex ytRegex = new Regex("(((youtube.*(v=|/v/))|(youtu\\.be/))(?[-_a-zA-Z0-9]+))"); + Regex ytRegex = new Regex(YOUTUBE_URL); if (ytRegex.IsMatch(urlMatch.ToString())) { Match ytMatch = ytRegex.Match(urlMatch.ToString()); string youtubeMessage = GetYoutubeDescription(ytMatch.Groups["ID"].Value); + + Regex ytTitle = new Regex(YOUTUBE_URL); + if (ytTitle.IsMatch(youtubeMessage)) + { + youtubeMessage = ytTitle.Replace(youtubeMessage, string.Empty); + } Bot.IRC.Command.SendPrivateMessage(message.Channel, youtubeMessage); } else