private static async Task IterationAsync(TelegramBotAbstract bot) { try { var url = "https://spottedpolimi.altervista.org/s/getposts.php?password="******"&random=" + randomstring; var x = await Web.DownloadHtmlAsync(urlFinal, RequestCacheLevel.NoCacheNoStore); if (x == null || x.IsValid() == false) { return; } var data = x.GetData(); await DoThingsAsyncBotAsync2Async(data); } catch (Exception e) { await ExceptionNumbered.SendExceptionAsync(e, bot); } }
public static async Task PermittedSpamMeasure(TelegramBotAbstract telegramBotClient, MessageEventArgs messageEventArgs, SpamType checkSpam) { var title = ""; if (messageEventArgs is { Message : { Chat : { Title : { } } } })
private static async Task <Tuple <ToExit, ChatMember[], List <int> > > CheckIfToExit_NullValue2Async( TelegramBotAbstract telegramBotClient, MessageEventArgs e) { var r = await telegramBotClient.GetChatAdministratorsAsync(e.Message.Chat.Id); if (r == null) { return(new Tuple <ToExit, ChatMember[], List <int> >(ToExit.STAY, r, new List <int> { 3 })); } foreach (var chatMember in r) { var isCreator = Creators.CheckIfIsCreatorOrSubCreator(chatMember); if (isCreator != null && isCreator.Value) { return(new Tuple <ToExit, ChatMember[], List <int> >(ToExit.STAY, r, new List <int> { 4 })); } } return(new Tuple <ToExit, ChatMember[], List <int> >(ToExit.EXIT, r, new List <int> { 5 })); }
private static async Task <Tuple <bool?, DateTime?> > FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot6Async( TLChat x5, TLAbsInputPeer u, TelegramBotAbstract telegramBotAbstract) { ; var isOurBotPresent2 = await CheckIfOurBotIsPresent3Async(x5, telegramBotAbstract); if (isOurBotPresent2 == null) { return(new Tuple <bool?, DateTime?>(false, null)); } ; if (isOurBotPresent2.Item2 != null) { return(new Tuple <bool?, DateTime?>(null, isOurBotPresent2.Item2)); } if (isOurBotPresent2.Item1 != null && isOurBotPresent2.Item1.Value) { return(new Tuple <bool?, DateTime?>(true, null)); } var r4 = await InsertOurBotAsyncChat(x5, u, null, telegramBotAbstract); return(new Tuple <bool?, DateTime?>(r4, null)); }
private static async Task AskForMessageToReplyTo2(TelegramBotAbstract telegramBotAbstract, MessageEventArgs e, int identity) { //ask link var question = new Language(new Dictionary <string, string> { { "it", "Inserisci il link del messaggio a cui vuoi rispondere" } }); var r = await AskUser.AskAsync(e.Message.From.Id, question, telegramBotAbstract, e.Message.From.LanguageCode, e.Message.From.Username); var tuple = GetMessageReply(r); if (r == null) { var l2 = new Language(new Dictionary <string, string> { { "it", "Errore, non siamo riusciti a comprendere il link che hai inviato\n" + "Operazione annullata." } }); } await PlaceMessageInQueue(telegramBotAbstract, new MessaggeAnonToSendInQueue(e), identity, tuple); }
internal static async Task NotifyIfFalseAsync(Tuple <bool?, string, long> r1, string extraInfo, TelegramBotAbstract sender) { if (r1 == null) { return; } if (r1.Item1 == null) { return; } if (r1.Item1.Value) { return; } var error = "Error (notifyIfFalse): "; error += "\n"; error += "String: " + r1?.Item2 + "\n"; error += "Long: " + r1.Item3 + "\n"; error += "Extra: " + extraInfo; error += "\n"; var exception = new ExceptionNumbered(error); await NotifyOwners(exception, sender); }
internal static async Task <bool> CreateInviteLinkAsync(long chatId, TelegramBotAbstract sender) { string r = null; try { r = await sender.ExportChatInviteLinkAsync(chatId); } catch { // ignored } if (string.IsNullOrEmpty(r)) { return(false); } const string q1 = "UPDATE Groups SET link = @link, last_update_link = @lul WHERE id = @id"; SqLite.Execute(q1, new Dictionary <string, object> { { "@link", r }, { "@lul", DateTime.Now }, { "@id", chatId } }); return(true); }
private static async Task HandleMessageAsync(TelegramBotAbstract telegramBotClient, MessageEventArgs e) { if (e.Message.Chat.Id == 1001129635578 || e.Message.Chat.Id == -1001129635578) { await HandleMessage2Async(telegramBotClient, e); } }
private static Tuple <bool, List <string> > CheckIfLimitOfMaxKingsHasBeenReached( TelegramBotAbstract telegramBotClient, MessageEventArgs e, string t) { var q = "SELECT * FROM Primo"; var r = SqLite.ExecuteSelect(q); if (r == null || r.Rows.Count == 0) { return(new Tuple <bool, List <string> >(false, null)); } var countOfUser = CountOfUserMethod(r, e); if (countOfUser == null) { return(new Tuple <bool, List <string> >(false, null)); } if (countOfUser.Count >= 2) { return(new Tuple <bool, List <string> >(true, countOfUser)); } return(new Tuple <bool, List <string> >(false, null)); }
public static async Task <bool> CheckIfToExitAndUpdateGroupList(TelegramBotAbstract sender, MessageEventArgs e) { switch (e.Message.Chat.Type) { case ChatType.Private: return(false); case ChatType.Group: break; case ChatType.Channel: break; case ChatType.Supergroup: break; default: throw new ArgumentOutOfRangeException(); } const string q1 = "SELECT id, valid FROM Groups WHERE id = @id"; var dt = SqLite.ExecuteSelect(q1, new Dictionary <string, object> { { "@id", e.Message.Chat.Id } }); if (dt != null && dt.Rows.Count > 0) { return(await CheckIfToExit(sender, e, dt.Rows[0].ItemArray[1])); } InsertGroup(sender, e); return(await CheckIfToExit(sender, e, null)); }
private static async Task MainMethod2(object sender, MessageEventArgs e) { TelegramBotClient telegramBotClientBot = null; TelegramBotAbstract telegramBotClient = null; try { if (sender is TelegramBotClient tmp) { telegramBotClientBot = tmp; } if (telegramBotClientBot == null) { return; } telegramBotClient = TelegramBotAbstract.GetFromRam(telegramBotClientBot); if (telegramBotClient == null) { return; } await HandleMessageAsync(telegramBotClient, e); } catch (Exception exception) { Console.WriteLine(exception.Message); await NotifyUtil.NotifyOwners(exception, telegramBotClient); } }
public static async Task <bool> Assoc_SendAsync(TelegramBotAbstract sender, MessageEventArgs e) { var replyTo = e.Message.ReplyToMessage; var languageList = new Language(new Dictionary <string, string> { { "it", "Scegli l'entità per il quale stai componendo il messaggio" }, { "en", "Choose the entity you are writing this message for" } }); var messageFromIdEntity = await GetIdEntityFromPersonAsync(e.Message.From.Id, languageList, sender, e.Message.From.LanguageCode, e.Message.From.Username); if (messageFromIdEntity == null) { var languageList3 = new Language(new Dictionary <string, string> { { "en", "We can't find the entity you want to post from. Are you sure you are a member of some entity allowed to post?" }, { "it", "Non riusciamo a trovare l'organizzazione per la quale vuoi postare. Sei sicuro di essere un membro di qualche organizzazione autorizzata a postare?" } }); await sender.SendTextMessageAsync(e.Message.From.Id, languageList3, ChatType.Private, default,
internal static async Task <bool> SendMessageInPrivateOrAGroup(TelegramBotAbstract telegramBotClient, Language text, string lang, string username, int userId, string firstName, string lastName, long chatId, ChatType chatType) { try { var r = await telegramBotClient.SendTextMessageAsync(userId, text, ChatType.Private, parseMode : ParseMode.Html, lang : lang, username : username, replyMarkupObject : new ReplyMarkupObject(ReplyMarkupEnum.REMOVE)); if (r) { return(true); } } catch { // ignored } var messageTo = GetMessageTo(firstName, lastName, userId); var text3 = new Language(new Dictionary <string, string> { { "en", "[Message for " + messageTo + "]\n\n" + text.Select("en") }, { "it", "[Messaggio per " + messageTo + "]\n\n" + text.Select("it") } }); return(await telegramBotClient.SendTextMessageAsync(chatId, text3, chatType, lang, ParseMode.Html, new ReplyMarkupObject(ReplyMarkupEnum.REMOVE), username)); }
private static async Task HelpPrivate(TelegramBotAbstract sender, MessageEventArgs e) { const string text = "<i>Lista di funzioni</i>:\n" + "\n📑 Sistema di recensioni dei corsi (per maggiori info /help_review)\n" + "\n🔖 Link ai materiali nei gruppi (per maggiori info /help_material)\n" + "\n🙋 <a href='https://polinetwork.github.io/it/faq/index.html'>" + "FAQ (domande frequenti)</a>\n" + "\n🏫 Bot ricerca aule libere @AulePolimiBot\n" + "\n🕶️ Sistema di pubblicazione anonima (per maggiori info /help_anon)\n" + "\n🎙️ Registrazione delle lezioni (per maggiori info /help_record)\n" + "\n👥 Gruppo consigliati e utili /groups\n" + "\n⚠ Hai già letto le regole del network? /rules\n" + "\n✍ Per contattarci /contact"; const string textEng = "<i>List of features</i>:\n" + "\n📑 Review system of courses (for more info /help_review)\n" + "\n🔖 Link to notes (for more info /help_material)\n" + "\n🙋 <a href='https://polinetwork.github.io/it/faq/index.html'>" + "FAQ (frequently asked questions)</a>\n" + "\n🏫 Bot to find free rooms @AulePolimiBot\n" + "\n🕶️ Anonymous posting system (for more info /help_anon)\n" + "\n🎙️ Record of lessons (for more info /help_record)\n" + "\n👥 Recommended groups /groups\n" + "\n⚠ Have you already read our network rules? /rules\n" + "\n✍ To contact us /contact"; var text2 = new Language(new Dictionary <string, string> { { "en", textEng }, { "it", text } }); await SendMessage.SendMessageInPrivate(sender, e, text2, ParseMode.Html); }
internal static async Task <int> FillMissingLinksIntoDB_Async(TelegramBotAbstract sender, MessageEventArgs e) { const string q1 = "SELECT id FROM Groups WHERE link IS NULL OR link = ''"; var dt = SqLite.ExecuteSelect(q1); var n = 0; if (dt == null || dt.Rows.Count == 0) { return(n); } foreach (DataRow dr in dt.Rows) { var success = await CreateInviteLinkAsync((long)dr.ItemArray[0], sender, e); switch (success.isNuovo) { case SuccessoGenerazioneLink.NUOVO_LINK: case SuccessoGenerazioneLink.RICICLATO: n++; break; } } return(n); }
private static async Task BanAllUnbanAllMethod1Async(RestrictAction restrictAction, string finalTarget, MessageEventArgs e, TelegramBotAbstract sender, string lang, string username, DateTime?until) { if (string.IsNullOrEmpty(finalTarget)) { var lang2 = new Language(new Dictionary <string, string> { { "en", "We can't find the target." }, { "it", "Non riusciamo a trovare il bersaglio" } }); await sender.SendTextMessageAsync(e.Message.From.Id, lang2, ChatType.Private, lang, ParseMode.Default, username : username, replyMarkupObject : new ReplyMarkupObject(ReplyMarkupEnum.REMOVE)); return; } var done = await RestrictUser.BanAllAsync(sender, e, finalTarget, restrictAction, until); var text2 = done.Item1.GetLanguage(restrictAction, finalTarget, done.Item3); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text2, ParseMode.Default, e.Message.MessageId); await SendReportOfSuccessAndFailures(sender, e, done); }
private static async Task <MessageSentResult> TestTime(TelegramBotAbstract sender, MessageEventArgs e) { var sentDate = await DateTimeClass.AskDateAsync(e.Message.From.Id, e.Message.Text, e.Message.From.LanguageCode, sender, e.Message.From.Username); if (sentDate.Item2 != null) { await NotifyUtil.NotifyOwners(new ExceptionNumbered(sentDate.Item2), sender, 0, sentDate.Item3); return(null); } var sentDate2 = sentDate.Item1.GetDate(); var dict = new Dictionary <string, string> { { "en", DateTimeClass.DateTimeToItalianFormat(sentDate2) } }; var text = new Language(dict); return(await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text, ParseMode.Default, e.Message.MessageId)); }
private static async Task SendRecommendedGroupsAsync(TelegramBotAbstract sender, MessageEventArgs e) { const string text = "<i>Lista di gruppi consigliati</i>:\n" + "\n👥 Gruppo di tutti gli studenti @PoliGruppo 👈\n" + "\n📖 Libri @PoliBook\n" + "\n🤪 Spotted & Memes @PolimiSpotted @PolimiMemes\n" + "\n🥳 Eventi @PoliEventi\n" + "\nRicordiamo che sul nostro sito vi sono tutti i link ai gruppi con tanto ricerca, facci un salto!\n" + "https://polinetwork.github.io/"; const string textEng = "<i>List of recommended groups</i>:\n" + "\n👥 Group with all students @PoliGruppo 👈\n" + "\n📖 Books @PoliBook\n" + "\n🤪 Spotted & Memes @PolimiSpotted @PolimiMemes\n" + "\n🥳 Events @PoliEventi\n" + "\nWe remind you that on our website there are all link to the groups, and they are searchable, have a look!\n" + "https://polinetwork.github.io/"; var text2 = new Language(new Dictionary <string, string> { { "en", textEng }, { "it", text } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text2, ParseMode.Html, null); }
private static async Task PrivateMessage(TelegramBotAbstract telegramBotClient, MessageEventArgs e) { if (AskUser.UserAnswers.ContainsKey(e.Message.From.Id)) { if (AskUser.UserAnswers[e.Message.From.Id] != null) { if (AskUser.UserAnswers[e.Message.From.Id].GetState() == AnswerTelegram.State.WAITING_FOR_ANSWER) { AskUser.UserAnswers[e.Message.From.Id].RecordAnswer(e.Message.Text); return; } } } //todo: check user state var text2 = new Language(new Dictionary <string, string> { { "en", "Hi, at the moment is not possible to have conversation with the bot.\n" + "We advice you to write /help to see what this bot can do" }, { "it", "Ciao, al momento non è possibile fare conversazione col bot.\n" + "Ti consigliamo di premere /help per vedere le funzioni disponibili" } }); await SendMessage.SendMessageInPrivate(telegramBotClient, e, text2); }
internal static async Task <int?> GetTargetUserIdAsync(string target, TelegramBotAbstract telegramBotAbstract) { if (string.IsNullOrEmpty(target)) { return(null); } if (target.StartsWith("-")) { try { return(Convert.ToInt32(target)); } catch { return(null); } } if (target[0] < '0' || target[0] > '9') { return(await GetIdFromUsernameAsync(target, telegramBotAbstract)); } try { return(Convert.ToInt32(target)); } catch { return(null); } }
internal static async Task <DateTimeSchedule> AskDateAsync(int id, string text, string lang, TelegramBotAbstract sender, string username) { if (string.IsNullOrEmpty(text)) { return(await AskDate2Async(id, lang, sender, username)); } var s = text.Split(' '); if (s.Length == 1) { return(await AskDate2Async(id, lang, sender, username)); } switch (s[1]) { case "ora": case "now": { return(new DateTimeSchedule(DateTime.Now, true)); } } return(await AskDate2Async(id, lang, sender, username)); }
internal static async Task DetectMessage(TelegramBotAbstract telegramBotClient, MessageEventArgs e) { if (e.Message.Chat.Type == ChatType.Private) { await PrivateMessage(telegramBotClient, e); } }
internal static TelegramBotAbstract GetFirstModerationRealBot(TelegramBotAbstract telegramBotAbstract = null) { if (telegramBotAbstract != null) { return(telegramBotAbstract); } foreach (var x in GlobalVariables.Bots.Keys) { var bot = GlobalVariables.Bots[x]; var botType = bot.GetBotType(); switch (botType) { case BotTypeApi.REAL_BOT: { var botMode = bot.GetMode(); if (botMode == BotStartMethods.Moderation) { return(bot); } break; } case BotTypeApi.USER_BOT: break; case BotTypeApi.DISGUISED_BOT: break; } } return(null); }
internal static async Task Mute(int time, TelegramBotAbstract telegramBotClient, long chatId, int userId, ChatType chatType) { var untilDate = DateTime.Now.AddSeconds(time); await Mute2Async(untilDate, telegramBotClient, chatId, userId, chatType); }
private static async Task DeleteMessageAddedAsync2(int?idMessageAdded, int id, long?accessHash, TelegramBotAbstract telegramBotAbstract) { if (idMessageAdded != null) { try { await telegramBotAbstract.DeleteMessageAsync(id, idMessageAdded.Value, ChatType.Supergroup, accessHash); } catch (Exception e3) { ; try { await telegramBotAbstract.DeleteMessageAsync(id, idMessageAdded.Value, ChatType.Group, accessHash); } catch { ; try { var messageToDelete = new TLVector <int> { idMessageAdded.Value }; TLAbsInputChannel x7 = new TLInputChannel { AccessHash = accessHash.Value, ChannelId = id }; await telegramBotAbstract._userbotClient.ChannelsDeleteMessageAsync(x7, messageToDelete); } catch { ; try { /* * TLVector<int> messageToDelete = new TLVector<int>(); * messageToDelete.Add(idMessageAdded.Value); * TLAbsInputChannel x7 = new TLInputChannel() { AccessHash = x5.AccessHash.Value, ChannelId = x5.Id }; * await this._userbotClient.DeleteMessageFromChat(x7, messageToDelete); */ } catch { ; } } } } ; Thread.Sleep(2000); } }
internal static async Task <NuovoLink> CreateInviteLinkAsync(long chatId, TelegramBotAbstract sender, MessageEventArgs e) { var successoGenerazione = SuccessoGenerazioneLink.ERRORE; var r = await TryGetCurrentInviteLinkAsync(chatId, sender, e); if (string.IsNullOrEmpty(r)) { try { r = await sender.ExportChatInviteLinkAsync(chatId, null); } catch { // ignored } } else { successoGenerazione = SuccessoGenerazioneLink.RICICLATO; } if (string.IsNullOrEmpty(r)) { return(new NuovoLink(successoGenerazione)); } successoGenerazione = SuccessoGenerazioneLink.NUOVO_LINK; SalvaNuovoLink(r, chatId); return(new NuovoLink(successoGenerazione, r)); }
private static async Task ForceCheckInviteLinksAsync(TelegramBotAbstract sender, MessageEventArgs e) { int?n = null; try { n = await InviteLinks.FillMissingLinksIntoDB_Async(sender, e); } catch (Exception e2) { await NotifyUtil.NotifyOwners(new ExceptionNumbered(e2), sender); } if (n == null) { return; } var text2 = new Language(new Dictionary <string, string> { { "en", "I have updated n=" + n + " links" }, { "it", "Ho aggiornato n=" + n + " link" } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text2, ParseMode.Default, e.Message.MessageId); }
internal static async Task <string> AskAsync(long idUser, Language question, TelegramBotAbstract sender, string lang, string username, bool sendMessageConfirmationChoice = false) { var botId = sender.GetId(); UserAnswers.Reset(idUser, botId); await sender.SendTextMessageAsync(idUser, question, ChatType.Private, parseMode : default,
private static async Task <bool> CheckIfToExit_NullValue(TelegramBotAbstract telegramBotClient, MessageEventArgs e) { var r = await telegramBotClient.GetChatAdministratorsAsync(e.Message.Chat.Id); //todo: check if admins are allowed and set valid column return(false); }
private static async Task FreeClassroomAsync(TelegramBotAbstract sender, MessageEventArgs e) { var t3 = await GetDailySituationAsync(sender, e); if (t3 == null) { var text4 = new Language(new Dictionary <string, string> { { "it", "Errore nella consultazione del sito del polimi!" }, { "en", "Error while getting polimi website!" } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text4, ParseMode.Default, null); return; } var tupleTime = await GetStartAndStopHoursAsync(sender, e); var t4 = GetFreeRooms(t3[0], tupleTime.Item1, tupleTime.Item2); if (t4 == null || t4.Count == 0) { var text3 = new Language(new Dictionary <string, string> { { "it", "Nessuna aula libera trovata!" }, { "en", "No free rooms found!" } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text3, ParseMode.Default, null); return; } var reply_text = ""; foreach (var room in t4) { reply_text += room + "\n"; } var text2 = new Language(new Dictionary <string, string> { { "en", reply_text } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text2, ParseMode.Html, null); }