private static async Task SendUsernameWarning(TelegramBotAbstract telegramBotClient, bool username, bool name, string lang, string usernameOfUser, long chatId, int userId, int?messageId, ChatType messageChatType, string firstName, string lastName) { var s1I = "Imposta un username e un nome più lungo dalle impostazioni di telegram\n"; if (username && !name) { s1I = "Imposta un username dalle impostazioni di telegram\n"; } else if (!username && name) { s1I = "Imposta un nome più lungo " + "dalle impostazioni di telegram\n"; } var s1E = "Set an username and a longer first name from telegram settings"; if (username && !name) { s1E = "Set an username from telegram settings"; } else if (!username && name) { s1E = "Set a longer first name from telegram settings"; } var s2 = new Language(new Dictionary <string, string> { { "it", s1I }, { "en", s1E } }); await SendMessage.SendMessageInPrivateOrAGroup(telegramBotClient, s2, lang, usernameOfUser, userId, firstName, lastName, chatId, messageChatType); await RestrictUser.Mute(60 * 5, telegramBotClient, chatId, userId); if (messageId != null) { await telegramBotClient.DeleteMessageAsync(chatId, messageId.Value, messageChatType); } }
public static async Task AntiSpamMeasure(TelegramBotAbstract telegramBotClient, MessageEventArgs e, SpamType checkSpam) { if (checkSpam == SpamType.ALL_GOOD) { return; } await RestrictUser.Mute(60 * 5, telegramBotClient, e.Message.Chat.Id, e.Message.From.Id); var language = e.Message.From.LanguageCode.ToLower(); switch (checkSpam) { case SpamType.SPAM_LINK: { var text2 = new Language(new Dictionary <string, string> { { "en", "You sent a message with spam, and you were muted for 5 minutes" }, { "it", "Hai inviato un messaggio con spam, e quindi il bot ti ha mutato per 5 minuti" } }); await SendMessage.SendMessageInPrivate(telegramBotClient, e, text2); break; } case SpamType.NOT_ALLOWED_WORDS: { var text2 = new Language(new Dictionary <string, string> { { "en", "You sent a message with banned words, and you were muted for 5 minutes" }, { "it", "Hai inviato un messaggio con parole bandite, e quindi il bot ti ha mutato per 5 minuti" } }); await SendMessage.SendMessageInPrivate(telegramBotClient, e, text2); break; } case SpamType.FOREIGN: { var text2 = new Language(new Dictionary <string, string> { { "en", "You sent a message with banned characters, and you were muted for 5 minutes" }, { "it", "Hai inviato un messaggio con caratteri banditi, e quindi il bot ti ha mutato per 5 minuti" } }); await SendMessage.SendMessageInPrivate(telegramBotClient, e, text2); break; } // ReSharper disable once UnreachableSwitchCaseDueToIntegerAnalysis case SpamType.ALL_GOOD: return; default: throw new ArgumentOutOfRangeException(nameof(checkSpam), checkSpam, null); } await telegramBotClient.DeleteMessageAsync(e.Message.Chat.Id, e.Message.MessageId, e.Message.Chat.Type); }
private static async Task SendUsernameWarning(TelegramBotAbstract telegramBotClient, bool username, bool name, string lang, string usernameOfUser, long chatId, int userId, int?messageId, ChatType messageChatType, string firstName, string lastName, User[] newChatMembers) { var s1I = "Imposta un username e un nome più lungo dalle impostazioni di telegram per poter scrivere in questo gruppo\n"; if (username && !name) { s1I = "Imposta un username dalle impostazioni di telegram per poter scrivere in questo gruppo\n"; } else if (!username && name) { s1I = "Imposta un nome più lungo " + "dalle impostazioni di telegram\n"; } var s1E = "Set an username and a longer first name from telegram settings to write in this group\n"; if (username && !name) { s1E = "Set an username from telegram settings to write in this group\n"; } else if (!username && name) { s1E = "Set a longer first name from telegram settings to write in this group\n"; } var s2 = new Language(new Dictionary <string, string> { { "it", s1I }, { "en", s1E } }); var r1 = await SendMessage.SendMessageInPrivateOrAGroup(telegramBotClient, s2, lang, usernameOfUser, userId, firstName, lastName, chatId, messageChatType); const int MINUTES_WAIT = 2; if (r1.GetChatType() != ChatType.Private) { var r2 = r1.GetMessage(); if (r2 != null) { if (r2 is TLMessage r3) { lock (GlobalVariables.MessagesToDelete) { var timeUntilDelete = TimeSpan.FromMinutes(MINUTES_WAIT); var TimeToDelete = DateTime.Now + timeUntilDelete; var toDelete = new MessageToDelete(r3, chatId, TimeToDelete, telegramBotClient.GetId(), r1.GetChatType(), null); GlobalVariables.MessagesToDelete.Add(toDelete); FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete, GlobalVariables.MessagesToDelete); } } else if (r2 is Message r4) { lock (GlobalVariables.MessagesToDelete) { var timeUntilDelete = TimeSpan.FromMinutes(MINUTES_WAIT); var TimeToDelete = DateTime.Now + timeUntilDelete; var toDelete = new MessageToDelete(r4, chatId, TimeToDelete, telegramBotClient.GetId(), r1.GetChatType(), null); GlobalVariables.MessagesToDelete.Add(toDelete); FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete, GlobalVariables.MessagesToDelete); } } else { var e4 = "Attempted to add a message to be deleted in queue\n" + r2?.GetType() + " " + r2; var e3 = new Exception(e4); await NotifyUtil.NotifyOwners(e3, telegramBotClient); } } } if (newChatMembers == null || newChatMembers.Length == 0) { await RestrictUser.Mute(60 * 5, telegramBotClient, chatId, userId, messageChatType); } if (messageId != null) { await telegramBotClient.DeleteMessageAsync(chatId, messageId.Value, messageChatType, null); } }