Repair "www" removal
This commit is contained in:
parent
30cdf087cc
commit
bf3e8a65e1
@ -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);
|
||||
|
||||
|
21
Utils.cs
21
Utils.cs
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user