private static void BanUserForPositiveFilter(Message message, Filters.FilterResult result) { int limitTime = 3; Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "SpamActionLimitTime") .SingleOrDefault(); if (configValue != null) { int.TryParse(configValue.Value, out limitTime); } RemoveMessageForPositiveFilter(message, result); Bot.Manager.BotClient.KickChatMemberAsync(message.Chat.Id, message.From.Id, DateTime.UtcNow.AddMinutes(-5)); UserTools.AddPenalty(message.Chat.Id, message.From.Id, Models.TrustFactorLog.TrustFactorAction.ban, Bot.Manager.MyId); Bot.Manager.BotClient.KickChatMemberAsync(message.Chat.Id, message.From.Id, DateTime.UtcNow.AddMinutes(-5)); UserTools.AddPenalty(message.Chat.Id, message.From.Id, Models.TrustFactorLog.TrustFactorAction.ban, Bot.Manager.MyId); string author = message.From.Username == null ? message.From.FirstName + " " + message.From.LastName : "@" + message.From.Username; string logMessage = String.Format( "*[Report]*\n" + "User banned as per group _Spam Action_ preference.\n" + "⚠ do not open links you don't know ⚠\n" + "\nControl: `{0}`" + "\nChat: `{1}`" + "\nAuthor: `{2}`" + "\nUserId: `{3}`" + "\n\n*hash_code:* #UB{4}-{5}", result.CheckName, message.Chat.Title, author, message.From.Id, message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()); MessageQueueManager.EnqueueLog(new ChatMessage() { ParseMode = ParseMode.Markdown, Text = logMessage }); LogTools.AddActionLog(new ActionLog() { GroupId = CacheData.Groups[message.Chat.Id].GroupId, UtcDate = DateTime.UtcNow, ActionTypeId = "autoBan", Parameters = logMessage, }); }
public FilterResult DoCheck(Message message) { if (Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id)) { return(new FilterResult() { CheckName = "BadWord", Result = IFilter.FilterResultType.skipped }); } Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "NonLatinFilter") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new FilterResult() { CheckName = "Non-Latin Filter", Result = IFilter.FilterResultType.skipped } } } ; string regex = @"[^\x00-\x7FÀ-ÖØ-öø-ÿ"; // non latin chars regex += @"\p{IsCurrencySymbols}\p{IsMiscellaneousSymbols}\p{IsMiscellaneousTechnical}"; regex += @"p{IsArrows}\p{IsMiscellaneousSymbolsandArrows}\p{IsMathematicalOperators}]+"; Regex reg = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedWords = reg.Matches(removeEmojis(message.Text)); if (matchedWords.Count > 0) { return new FilterResult() { CheckName = "Non-Latin Filter", Result = IFilter.FilterResultType.positive, Rule = "Non-Latin Filter" } } ; return(new FilterResult() { CheckName = "Non-Latin Filter", Result = IFilter.FilterResultType.negative }); }
public FilterResult DoCheck(Message message, string text) { Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "BadWordFilter") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new FilterResult() { CheckName = "BadWord", Result = IFilter.FilterResultType.skipped } } } ; List <BadWord> badWords = CacheData.BadWords .Where(x => x.GroupId == null || x.GroupId == CacheData.Groups[message.Chat.Id].GroupId) .ToList(); foreach (BadWord badWord in badWords) { Regex reg = new Regex(badWord.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedWords = reg.Matches(text); if (matchedWords.Count > 0) { return new FilterResult() { CheckName = "BadWord", Result = IFilter.FilterResultType.positive, Rule = badWord.Name } } ; } return(new FilterResult() { CheckName = "BadWord", Result = IFilter.FilterResultType.negative }); }
public static void ToggleGate(Message message, bool newStatus) { Models.Group.ConfigurationParameter config = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "Gate") .SingleOrDefault(); if (config == null) { return; } CacheData.GroupConfigs[message.Chat.Id] [CacheData.GroupConfigs[message.Chat.Id] .IndexOf(config)] .Value = newStatus ? "true" : "false"; Manager.BotClient.SetChatPermissionsAsync(message.Chat.Id, new ChatPermissions() { CanSendMessages = newStatus, CanAddWebPagePreviews = newStatus, CanChangeInfo = newStatus, CanInviteUsers = newStatus, CanPinMessages = newStatus, CanSendMediaMessages = newStatus, CanSendOtherMessages = newStatus, CanSendPolls = newStatus }); string status = newStatus ? "open" : "closed"; MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, Text = $"The group is now {status}" }); }
public FilterResult DoCheck(Message message, string fullName) { Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "RTLNameFilter") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new FilterResult() { CheckName = "RTLNameFilter", Result = IFilter.FilterResultType.skipped } } } ; if (Utils.UserTools.NameIsRTL(fullName)) { return new FilterResult() { CheckName = "RTLNameFilter", Result = IFilter.FilterResultType.positive, Rule = "Name has RTL characters" } } ; return(new FilterResult() { CheckName = "BadWord", Result = IFilter.FilterResultType.negative }); } }
private static void LimitUserForPositiveFilter(Message message, Filters.FilterResult result) { int limitTime = 3; Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "SpamActionLimitTime") .SingleOrDefault(); if (configValue != null) { int.TryParse(configValue.Value, out limitTime); } RemoveMessageForPositiveFilter(message, result); Bot.Manager.BotClient.RestrictChatMemberAsync( message.Chat.Id, message.From.Id, new ChatPermissions() { CanSendMessages = false, CanAddWebPagePreviews = false, CanChangeInfo = false, CanInviteUsers = false, CanPinMessages = false, CanSendMediaMessages = false, CanSendOtherMessages = false, CanSendPolls = false }, DateTime.UtcNow.AddMinutes(limitTime)); string author = message.From.Username == null ? message.From.FirstName + " " + message.From.LastName : "@" + message.From.Username; string logMessage = String.Format( "*[Report]*\n" + "User limited as per group _Spam Action_ preference.\n" + "⚠ do not open links you don't know ⚠\n" + "\nControl: `{0}`" + "\nChat: `{1}`" + "\nAuthor: `{2}`" + "\nUserId: `{3}`" + "\n\n*hash_code:* #UB{4}-{5}", result.CheckName, message.Chat.Title, author, message.From.Id, message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()); MessageQueueManager.EnqueueLog(new ChatMessage() { ParseMode = ParseMode.Markdown, Text = logMessage }); LogTools.AddActionLog(new ActionLog() { GroupId = CacheData.Groups[message.Chat.Id].GroupId, UtcDate = DateTime.UtcNow, ActionTypeId = "autoLimit", Parameters = logMessage, }); }
public ControlResult DoCheck(Message message) { if (Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id)) { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped }); } Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "SafeGroupControl") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped } } } ; string regex = @"(((http|https):\/\/)|(tg:\/\/)|(t.me\/))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?|(?![\w_])(@[\w_]+)(?!.)"; Regex reg = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedWords = reg.Matches(message.Text); if (matchedWords.Count == 0) { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.negative }); } foreach (Match match in matchedWords) { string url = match.Value; if (url.StartsWith("@")) { if (message.Chat.Username != null) { if (match.Value.Remove(0, 1) == message.Chat.Username) { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped }); } } url = "https://t.me/" + match.Value.Remove(0, 1); } if (url.StartsWith("t.me")) { url = "https://" + match.Value; } if (url.Contains("t.me/") && url.StartsWith("http") && !url.StartsWith("https")) { url = url.Replace("http", "https"); } string inviteLink = Bot.Manager.BotClient.GetChatAsync(message.Chat.Id).Result.InviteLink; if (inviteLink != null) { if (match.Value == inviteLink) { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped }); } } if (url.Contains("/c/")) { if (url.Split("/c/")[1].Split('/')[0] == message.Chat.Id.ToString()) { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped }); } } if (url == "https://t.me/unifiedban_group" || url == "https://t.me/unifiedban_news" || url == "https://t.me/unifiedban_bot" || url == "https://t.me/unifiedbanBeta_bot" || url == "https://t.me/joinchat/B35YY0QbLfd034CFnvCtCA" || // Support chat of the TelegramBots library url == "https://t.me/dotnetgram") // .NET global discussion and support chat { return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.skipped }); } if (Manager.IsTelegramLink(url)) { if (safeGroupFilter.DoCheck( CacheData.Groups[message.Chat.Id].GroupId, url) .Result == Filters.IFilter.FilterResultType.positive) { return new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.positive } } } ; } return(new ControlResult() { CheckName = "Safe Group", Result = IControl.ControlResultType.negative }); }
public ControlResult DoCheck(Message message) { Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "GroupNotes") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new ControlResult() { CheckName = "Group notes", Result = IControl.ControlResultType.skipped } } } ; Regex reg = new Regex("#[A-z0-9]+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedTags = reg.Matches(message.Text); if (matchedTags.Count == 0) { return new ControlResult() { CheckName = "Group notes", Result = IControl.ControlResultType.skipped } } ; List <Models.Group.Note> notes = new List <Models.Group.Note>(); foreach (Match match in matchedTags) { notes.AddRange(noteLogic.GetByTag(match.Value, CacheData.Groups[message.Chat.Id].GroupId)); } List <Models.Group.Note> distNotes = new List <Models.Group.Note>(notes.Distinct()); foreach (Models.Group.Note note in distNotes) { note.Message += Environment.NewLine; note.Message += "NoteId: " + note.NoteId; MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, Text = note.Message }); } return(new ControlResult() { CheckName = "Group notes", Result = IControl.ControlResultType.negative }); } }
private void SetCloseTime(Message message, string time) { string groupId = CacheData.Groups[message.Chat.Id].GroupId; DateTime startTime = new DateTime( DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Convert.ToInt32(time.Split(":")[0]), Convert.ToInt32(time.Split(":")[1]), 0); if (startTime < DateTime.UtcNow) { startTime = startTime.AddDays(1); } if (CacheData.NightSchedules.ContainsKey(groupId)) { if (CacheData.NightSchedules[groupId].UtcEndDate.HasValue) { if (CacheData.NightSchedules[groupId].UtcEndDate.Value.Hour == startTime.Hour) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "Opening and closing time matches the same hour. Please select a different time.", PostSentAction = Models.ChatMessage.PostSentActions.Destroy, AutoDestroyTimeInSeconds = 5 }); return; } } nsl.Update(groupId, Models.Group.NightSchedule.Status.Programmed, startTime, CacheData.NightSchedules[groupId].UtcEndDate, -2); } else { Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "*[Error]*\nSet an opening time first." }); return; } CacheData.NightSchedules[groupId] = nsl.GetByChat(groupId); Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = "Congratulations! The night schedule has been updated!" }); Models.Group.ConfigurationParameter config = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "GateSchedule") .SingleOrDefault(); if (config == null) { return; } CacheData.GroupConfigs[message.Chat.Id] [CacheData.GroupConfigs[message.Chat.Id] .IndexOf(config)] .Value = "true"; }
public ControlResult DoCheck(Message message) { if (Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id)) { return(new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.skipped }); } Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "SpamNameControl") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.skipped } } } ; Filters.BadWordFilter badWordFilter = new Filters.BadWordFilter(); Filters.FilterResult badName = badWordFilter .DoCheck(message, message.From.FirstName + " " + message.From.LastName); if (badName.Result == Filters.IFilter.FilterResultType.positive) { return new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.positive } } ; if (!String.IsNullOrEmpty(message.From.FirstName)) { if (!isNameSafe.TryGetValue(message.From.FirstName, out bool nameIsValid)) { CheckIfNameIsValid(message.From.FirstName); } } if (!String.IsNullOrEmpty(message.From.LastName)) { if (!isNameSafe.TryGetValue(message.From.LastName, out bool surnameIsValid)) { CheckIfNameIsValid(message.From.LastName); } } if (!String.IsNullOrEmpty(message.From.FirstName)) { if (!isNameSafe[message.From.FirstName]) { return new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.positive } } } ; if (!String.IsNullOrEmpty(message.From.LastName)) { if (!isNameSafe[message.From.LastName]) { return new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.positive } } } ; return(new ControlResult() { CheckName = "Spam Names", Result = IControl.ControlResultType.negative }); } void CheckIfNameIsValid(string name) { string regex = @"((http|ftp|https):\/\/)?([\w_-]+\s?(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?"; Regex reg = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedWords = reg.Matches(name); if (matchedWords.Count == 0) { isNameSafe[name] = true; return; } using (WebClientWithTimeout client = new WebClientWithTimeout()) { string siteUri = name; if (!name.Contains("http://") && !name.Contains("https://")) { siteUri = "http://" + name; } string htmlCode = ""; try { htmlCode = client.DownloadString(siteUri); } catch { } if (htmlCode.Contains("tgme_page_extra")) { isNameSafe[name] = false; } else { isNameSafe[name] = true; } } } }
public ControlResult DoCheck(Message message) { if (ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id)) { return(new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.skipped }); } if (message.Date < DateTime.UtcNow.AddMinutes(-1)) { return new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.skipped } } ; Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "FloodControl") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.skipped } } } ; Dictionary <int, Flood> floodCounter = FloodCounter.GetValueOrDefault(message.Chat.Id); if (floodCounter == null) { FloodCounter.TryAdd(message.Chat.Id, new Dictionary <int, Flood>()); } if (!FloodCounter[message.Chat.Id].TryGetValue(message.From.Id, out Flood currentValue)) { FloodCounter[message.Chat.Id].Add(message.From.Id, new Flood() { UserId = message.From.Id, Messages = 1, LastMessage = DateTime.UtcNow }); } else { if (currentValue.LastMessage < DateTime.UtcNow.AddSeconds(-3)) { FloodCounter[message.Chat.Id][message.From.Id] = new Flood() { UserId = message.From.Id, Messages = 1, LastMessage = DateTime.UtcNow }; return(new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.negative }); } currentValue.Messages += 1; currentValue.LastMessage = DateTime.UtcNow; FloodCounter[message.Chat.Id][message.From.Id] = currentValue; } if (FloodCounter[message.Chat.Id][message.From.Id].Messages >= 5) { int minutes = 5; SysConfig floodBanMinutes = CacheData.SysConfigs.Where(x => x.SysConfigId == "FloodBanInMinutes") .SingleOrDefault(); if (floodBanMinutes != null) { int.TryParse(floodBanMinutes.Value, out minutes); } if (limitedUsers.ContainsKey(message.From.Id)) { if (limitedUsers[message.From.Id] > DateTime.UtcNow.AddMinutes(-minutes)) { goto skipLimitAndPenality; } } limitedUsers.AddOrUpdate(message.From.Id, DateTime.UtcNow, (key, value) => value = DateTime.UtcNow); Bot.Manager.BotClient.RestrictChatMemberAsync( message.Chat.Id, message.From.Id, new ChatPermissions() { CanSendMessages = false, CanAddWebPagePreviews = false, CanChangeInfo = false, CanInviteUsers = false, CanPinMessages = false, CanSendMediaMessages = false, CanSendOtherMessages = false, CanSendPolls = false }, DateTime.UtcNow.AddMinutes(minutes) ).Wait(); string author = message.From.Username == null ? message.From.FirstName + " " + message.From.LastName : "@" + message.From.Username; MessageQueueManager.EnqueueLog(new ChatMessage() { ParseMode = ParseMode.Markdown, Text = String.Format( "*[Report]*\n" + "User muted for {0} minutes due to flood.\n" + "\nChat: `{1}`" + "\nAuthor: `{3}`" + "\nUserId: `{2}`" + "\n\n*hash_code:* #UB{4}-{5}", minutes, message.Chat.Title, message.From.Id, author, message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()) }); UserTools.AddPenalty(message.Chat.Id, message.From.Id, TrustFactorLog.TrustFactorAction.limit, Bot.Manager.MyId); MessageQueueManager.EnqueueMessage( new ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = $"User {message.From.Username} has been limited for {minutes} minutes due to flood.\n" + "An admin can immediately remove this limitation by clicking the button below.", ReplyMarkup = new InlineKeyboardMarkup( InlineKeyboardButton.WithCallbackData( CacheData.GetTranslation("en", "button_removeFlood", true), $"/RemoveFlood " + message.From.Id ) ) }); skipLimitAndPenality: return(new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.positive }); } return(new ControlResult() { CheckName = "Anti Flood", Result = IControl.ControlResultType.negative }); } }
public FilterResult DoCheck(Message message, string text) { Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "ScamFilter") .SingleOrDefault(); if (configValue != null) { if (configValue.Value == "false") { return new FilterResult() { CheckName = "ScamFilter", Result = IFilter.FilterResultType.skipped } } } ; string regex = @"(http:\/\/|ftp:\/\/|https:\/\/)?([\w_-]+\s?(?:(?:\.[a-zA-Z_-]{2,})+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?"; // string regex = @"(http:\/\/|ftp:\/\/|https:\/\/)?([a-zA-Z_-]+\s?(?:(?:\.\s?[\w_-]{2,})+)?)\s?\.\s?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]{2,})?"; Regex reg = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); MatchCollection matchedWords = reg.Matches(text); if (matchedWords.Count == 0) { return(new FilterResult() { CheckName = "ScamFilter", Result = IFilter.FilterResultType.negative }); } if (lastUpdate < DateTime.UtcNow.AddDays(-1)) { updateLinksList(); } if (String.IsNullOrEmpty(linksList)) { return new FilterResult() { CheckName = "ScamFilter", Result = IFilter.FilterResultType.skipped } } ; foreach (Match match in matchedWords) { string cleanValue = match.Value.Replace(" ", ""); // if text does not contain dot and is shorter than 4 chars can't be a link if (!cleanValue.Contains(".") && cleanValue.Length < 4) { continue; } if (!safeSingleLetter.Contains(cleanValue)) { string toCheck = match.Value; if (!match.Value.StartsWith("http://") && !match.Value.StartsWith("https://")) { toCheck = "://" + match.Value; } else if (match.Value.StartsWith("https")) { toCheck = match.Value.Remove(0, 5); } else if (match.Value.StartsWith("http")) { toCheck = match.Value.Remove(0, 4); } toCheck = toCheck .Replace("/", @"\/") .Replace(".", @"\.") .Replace("?", @"\?"); string regexToTest = string.Format(@"{0}[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]?", toCheck); Regex matchTest = new Regex(regexToTest, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); if (matchTest.IsMatch(linksList)) { return(new FilterResult() { CheckName = "ScamFilter", Result = IFilter.FilterResultType.positive }); } } } return(new FilterResult() { CheckName = "ScamFilter", Result = IFilter.FilterResultType.negative }); } void updateLinksList() { safeSingleLetter = new List <string>(); safeSingleLetter.Add("a.co"); safeSingleLetter.Add("a.org"); safeSingleLetter.Add("b.org"); safeSingleLetter.Add("e.im"); safeSingleLetter.Add("g.co"); safeSingleLetter.Add("i.net"); safeSingleLetter.Add("m.me"); safeSingleLetter.Add("n.pr"); safeSingleLetter.Add("o.co"); safeSingleLetter.Add("q.com"); safeSingleLetter.Add("q.net"); safeSingleLetter.Add("s.co"); safeSingleLetter.Add("s.de"); safeSingleLetter.Add("t.com"); //safeSingleLetter.Add("t.me"); safeSingleLetter.Add("u.ae"); safeSingleLetter.Add("w.org"); safeSingleLetter.Add("y.org"); safeSingleLetter.Add("x.com"); safeSingleLetter.Add("x.org"); safeSingleLetter.Add("z.com"); Models.SysConfig sitesList = CacheData.SysConfigs.Where(x => x.SysConfigId == "PhishingLinks") .SingleOrDefault(); if (sitesList == null) { return; } using (System.Net.WebClient client = new System.Net.WebClient()) { try { linksList = client.DownloadString(sitesList.Value); } catch (Exception ex) { Data.Utils.Logging.AddLog(new Models.SystemLog() { LoggerName = CacheData.LoggerName, Date = DateTime.Now, Function = "Terminal.Filters.ScamFilter.updateLinksList", Level = Models.SystemLog.Levels.Error, Message = "Error getting updated phishing links!", UserId = -1 }); Data.Utils.Logging.AddLog(new Models.SystemLog() { LoggerName = CacheData.LoggerName, Date = DateTime.Now, Function = "Terminal.Filters.ScamFilter.updateLinksList", Level = Models.SystemLog.Levels.Error, Message = ex.Message, UserId = -1 }); } } } }
public static void ToggleSchedule(Message message, bool newStatus) { Models.Group.ConfigurationParameter config = CacheData.GroupConfigs[message.Chat.Id] .Where(x => x.ConfigurationParameterId == "GateSchedule") .SingleOrDefault(); if (config == null) { return; } CacheData.GroupConfigs[message.Chat.Id] [CacheData.GroupConfigs[message.Chat.Id] .IndexOf(config)] .Value = newStatus ? "true" : "false"; if (newStatus) { if (!CacheData.NightSchedules.ContainsKey(CacheData.Groups[message.Chat.Id].GroupId)) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = CacheData.GetTranslation("en", "command_gate_missing_schedule") }); return; } Models.Group.NightSchedule nightSchedule = CacheData.NightSchedules[CacheData.Groups[message.Chat.Id].GroupId]; if (!nightSchedule.UtcStartDate.HasValue || !nightSchedule.UtcEndDate.HasValue) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ParseMode = ParseMode.Markdown, Text = CacheData.GetTranslation("en", "command_gate_missing_schedule") }); return; } TimeSpan diffStartDate = DateTime.UtcNow - nightSchedule.UtcStartDate.Value; if (diffStartDate.Days > 0) { CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate = CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate.Value .AddDays(diffStartDate.Days); } TimeSpan diffEndDays = DateTime.UtcNow - nightSchedule.UtcEndDate.Value; if (diffEndDays.Days > 0) { CacheData.NightSchedules[nightSchedule.GroupId].UtcEndDate = CacheData.NightSchedules[nightSchedule.GroupId].UtcEndDate.Value .AddDays(diffEndDays.Days); if (CacheData.NightSchedules[nightSchedule.GroupId].UtcEndDate.Value < DateTime.UtcNow) { CacheData.NightSchedules[nightSchedule.GroupId].UtcEndDate = CacheData.NightSchedules[nightSchedule.GroupId].UtcEndDate.Value .AddDays(1); } } } CacheData.NightSchedules[CacheData.Groups[message.Chat.Id].GroupId] .State = newStatus ? Models.Group.NightSchedule.Status.Programmed : Models.Group.NightSchedule.Status.Deactivated; }