Browse Source

Added max title length to url parsing.

master
Teknikode 7 years ago
parent
commit
fa496aaa36
  1. 8
      Modules/Url Parsing/Module.config
  2. 5
      Modules/Url Parsing/Url_Parsing.cs

8
Modules/Url Parsing/Module.config

@ -5,5 +5,11 @@ @@ -5,5 +5,11 @@
"ChannelBlacklist": [],
"NickBlacklist": [],
"Commands": [],
"Options": []
"Options": [
{
"Name": "Max Title",
"Description": "The maximum number of characters to display for a title",
"Value": 140
}
]
}

5
Modules/Url Parsing/Url_Parsing.cs

@ -57,6 +57,11 @@ namespace Combot.Modules.Plugins @@ -57,6 +57,11 @@ namespace Combot.Modules.Plugins
x.Encoding = Encoding.UTF8;
string source = x.DownloadString(urlMatch.ToString());
string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
int maxTitle = Convert.ToInt32(GetOptionValue("Max Title"));
if (title.Length > (int)maxTitle)
{
title = string.Format("{0}...", title.Substring(0, (int)maxTitle));
}
Bot.IRC.Command.SendPrivateMessage(message.Channel, string.Format("[URL] {0} ({1})", HttpUtility.HtmlDecode(HttpUtility.UrlDecode(StripTagsCharArray(title))), url.Host));
}
break;

Loading…
Cancel
Save