Repair "www" removal
This commit is contained in:
parent
30cdf087cc
commit
bf3e8a65e1
@ -208,11 +208,11 @@ namespace RSSBot {
|
|||||||
|
|
||||||
// Remove "www."
|
// Remove "www."
|
||||||
var index = linkName.IndexOf("www.", StringComparison.Ordinal);
|
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 = "";
|
var content = "";
|
||||||
if (!string.IsNullOrWhiteSpace(entry.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))
|
else if (!string.IsNullOrWhiteSpace(entry.Description))
|
||||||
content = Utils.ProcessContent(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.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace RSSBot {
|
namespace RSSBot {
|
||||||
public static class Utils {
|
public static class Utils {
|
||||||
|
private static readonly Regex RegexHtml = new Regex("<.*?>");
|
||||||
|
|
||||||
public static string StripHtml(string input) {
|
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) {
|
private static string CleanRss(string input) {
|
||||||
@ -58,22 +60,13 @@ namespace RSSBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string ProcessContent(string input) {
|
public static string ProcessContent(string input) {
|
||||||
string content = StripHtml(input);
|
var content = StripHtml(HttpUtility.HtmlDecode(input));
|
||||||
content = CleanRss(content);
|
content = CleanRss(content);
|
||||||
if (content.Length > 250) {
|
if (content.Length > 250) content = content.Substring(0, 250) + "...";
|
||||||
content = content.Substring(0, 250) + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
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) {
|
public static GroupCollection ReturnMatches(string text, string pattern) {
|
||||||
return Regex.Match(text,
|
return Regex.Match(text,
|
||||||
pattern,
|
pattern,
|
||||||
|
Loading…
Reference in New Issue
Block a user