Repair "www" removal

This commit is contained in:
Andreas Bielawski 2020-03-13 13:57:10 +01:00
parent 30cdf087cc
commit bf3e8a65e1
No known key found for this signature in database
GPG Key ID: D2073645DC2C3DE5
2 changed files with 9 additions and 16 deletions

View File

@ -208,11 +208,11 @@ namespace RSSBot {
// Remove "www."
var index = linkName.IndexOf("www.", StringComparison.Ordinal);
if (index > 0) linkName = linkName.Remove(index, 4);
if (index > -1) linkName = linkName.Remove(index, 4);
var content = "";
if (!string.IsNullOrWhiteSpace(entry.Content))
content = Utils.ProcessContent(entry.Content); // magic processing missing
content = Utils.ProcessContent(entry.Content);
else if (!string.IsNullOrWhiteSpace(entry.Description))
content = Utils.ProcessContent(entry.Description);

View File

@ -1,14 +1,16 @@
using System;
using System.Linq;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace RSSBot {
public static class Utils {
private static readonly Regex RegexHtml = new Regex("<.*?>");
public static string StripHtml(string input) {
return Regex.Replace(input, "<.*?>", String.Empty).Trim();
return RegexHtml.Replace(input, string.Empty).Trim();
}
private static string CleanRss(string input) {
@ -58,22 +60,13 @@ namespace RSSBot {
}
public static string ProcessContent(string input) {
string content = StripHtml(input);
var content = StripHtml(HttpUtility.HtmlDecode(input));
content = CleanRss(content);
if (content.Length > 250) {
content = content.Substring(0, 250) + "...";
}
if (content.Length > 250) content = content.Substring(0, 250) + "...";
return content;
}
public static bool IsCommand(string messageText, string command) {
return Regex.Match(messageText,
$"^/{command}(?:@{Bot.BotInfo.Username})?$",
RegexOptions.IgnoreCase
).Success;
}
public static GroupCollection ReturnMatches(string text, string pattern) {
return Regex.Match(text,
pattern,