public async Task <TLAbsUpdates> addUserIntoChannel(string userID, TLChannel channel) { if (string.IsNullOrEmpty(userID)) { return(null); } switch (_isbot) { case BotTypeApi.REAL_BOT: break; case BotTypeApi.USER_BOT: { try { var users = new TLVector <TLAbsInputUser>(); if (userID.StartsWith("@")) { var u = await UserbotPeer.GetPeerUserWithAccessHash(userID.Substring(1), _userbotClient); TLAbsInputUser input2 = new TLInputUser { AccessHash = u.AccessHash, UserId = u.UserId }; users.Add(input2); } else { users.Add(UserbotPeer.GetPeerUserFromdId(Convert.ToInt32(userID))); } var tLInputChannel = new TLInputChannel { ChannelId = channel.Id }; if (channel.AccessHash != null) { tLInputChannel.AccessHash = channel.AccessHash.Value; } var r = await _userbotClient.ChannelsInviteToChannel(tLInputChannel, users); return(r); } catch (Exception e) { ; } } break; case BotTypeApi.DISGUISED_BOT: break; } return(null); }
public async Task <TLAbsUpdates> SendMedia(TLAbsInputPeer peer, TelegramClient telegramClient, Language caption, string username, string lang) { TLAbsUpdates r2 = null; try { r2 = await SendMedia2(peer, telegramClient, caption, lang); } catch (Exception e) { ; } if (r2 != null) { return(r2); } if (string.IsNullOrEmpty(username)) { return(null); } try { peer = await UserbotPeer.GetPeerUserWithAccessHash(username, telegramClient); var r = await SendMedia2(peer, telegramClient, caption, lang); return(r); } catch (Exception e2) { return(null); } return(null); }
internal async Task DeleteMessageAsync(long chatId, int messageId, ChatType chatType) { switch (_isbot) { case BotTypeApi.REAL_BOT: await _botClient.DeleteMessageAsync(chatId, messageId); break; case BotTypeApi.USER_BOT: await _userbotClient.ChannelsDeleteMessageAsync(UserbotPeer.GetPeerChannelFromIdAndType(chatId), new TLVector <int> { messageId }); break; case BotTypeApi.DISGUISED_BOT: break; default: throw new ArgumentOutOfRangeException(); } }
public async Task <TLAbsInputFile> GetTelegramUserBotInputPhoto(TelegramClient userbot) { if (_messageIdFrom == null) { return(null); } var filename = "photo" + _uniqueId; var peer = UserbotPeer.GetPeerFromIdAndType(_chatId, _chatType); const int offsetDate = 0; var r = await userbot.GetHistoryAsync(peer, _messageIdFrom.Value, offsetDate, 0, 1); if (r == null) { return(null); } if (r is TLMessagesSlice tlMessagesSlice) { if (tlMessagesSlice.Messages.Count == 1) { var t = tlMessagesSlice.Messages[0]; if (t == null) { return(null); } if (t is TLMessage t2) { var t3 = t2.Media; if (t3 == null) { return(null); } if (t3 is TLMessageMediaPhoto tlPhoto) { var t4 = tlPhoto.Photo; if (t4 == null) { return(null); } if (t4 is TLPhoto t5) { var t6 = t5.Sizes; var t7 = BestPhoto(t6); if (t7 == null) { return(null); } if (t7 is TLPhotoSize t8) { //todo } //var fileResult = (TLInputFile)await userbot.UploadFile(filename, new StreamReader("tmp/" + filename)); //return fileResult; } } } } } return(null); }
internal static async Task MainMethodAsync(TelegramBotAbstract telegramBotAbstract) { try { ; var links = new List <string>(); var groupsRaw = File.ReadAllText(@"C:\Users\eliam\Documents\groups.csv"); var groups = Regex.Split(groupsRaw, "\r\n|\r|\n"); //using StreamWriter groupsFile = new StreamWriter(@"C:\Users\eliam\Documents\WriteLines.txt", append: true); //await groupsFile.WriteLineAsync("Nome Gruppo $ Link di Invito"); using (var sw = File.AppendText(@"C:\Users\eliam\Documents\groupslist.txt")) { sw.WriteLine("Nome Gruppo $ Link di Invito"); } foreach (var group in groups) { var toBeDone = true; while (toBeDone) { if (group.Length > 0) { try { // await telegramBotAbstract.FixTheFactThatSomeGroupsDoesNotHaveOurModerationBotAsync(); //file,,, var name = group; if (name.Length > 255) { using (var sw = File.AppendText(@"C:\Users\eliam\Documents\errorlist.txt")) { sw.WriteLine(name + " FAILED"); } } var desc = "Gruppo @polinetwork \nPer tutti i link: polinetwork.github.io"; var members = new List <long>(); //ID members to insert long?chatID = null; while (chatID == null) { chatID = await telegramBotAbstract.CreateGroup(name, desc, members); } Thread.Sleep(1 * 1000 * 10); var channel = await telegramBotAbstract.upgradeGroupIntoSupergroup(chatID); if (channel == null) { return; } //await telegramBotAbstract.EditDescriptionChannel(channel, desc); Thread.Sleep(1 * 1000 * 10); await telegramBotAbstract.addUserIntoChannel("@polinetwork3bot", channel); var admins = new List <TLInputUser>(); var adminTags = new List <string> { "polinetwork3bot" }; //tag members to set admins (MUST BE INSIDE THE members ARRAY) foreach (var admin in adminTags) { Thread.Sleep(1 * 1000 * 10); TLAbsInputPeer u = await UserbotPeer.GetPeerUserWithAccessHash(admin, telegramBotAbstract._userbotClient); if (u is TLInputPeerUser u2) { var user1 = new TLInputUser { AccessHash = u2.AccessHash, UserId = u2.UserId }; admins.Add(user1); } } foreach (var admin in admins) { Thread.Sleep(1 * 1000 * 10); await telegramBotAbstract.PromoteChatMember(admin, channel.Id, channel.AccessHash); } Thread.Sleep(1 * 1000 * 10); var link = await telegramBotAbstract.ExportChatInviteLinkAsync(channel.Id, channel.AccessHash); links.Add(link); using (var sw = File.AppendText(@"C:\Users\eliam\Documents\groupslist.txt")) { sw.WriteLine(group + " $ " + link); } Console.WriteLine("added: " + group + " $ " + link); Thread.Sleep(5 * 1000 * 60); toBeDone = false; } catch (Exception e) { Console.WriteLine(e.Message + " -> In Main Thread!"); Thread.Sleep(int.Parse(Regex.Match(e.Message, @"\d+").Value) * 1000); await NotifyUtil.NotifyOwners(e, telegramBotAbstract); } } } } Console.WriteLine("====== CREATION COMPLETE ======"); } catch (Exception ignore) { ; } }
private static async Task OccupanciesOfTheDayAsync(TelegramBotAbstract sender, MessageEventArgs e) { var t3 = await GetDailySituationAsync(sender, e); if (t3 == null) { var text2 = 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, text2, ParseMode.Default, null); return; } var question = new Language(new Dictionary <string, string> { { "en", "Which room? (example: 3.0.1)" }, { "it", "Quale aula? (esempio 3.0.1)" } }); var roomName = await AskUser.AskAsync(e.Message.From.Id, question, sender, e.Message.From.LanguageCode, e.Message.From.Username, true); var t4 = GetRoomTitleAndHours(t3[0], roomName); ; if (t4 == null || t4.Count == 0) { var text2 = new Language(new Dictionary <string, string> { { "it", "Aula non trovata!" }, { "en", "Room not found!" } }); await SendMessage.SendMessageInPrivate(sender, e.Message.From.Id, e.Message.From.LanguageCode, e.Message.From.Username, text2, ParseMode.Default, null); return; } var htmlresult = "<html><head><style>td {border: 1px solid;}</style></head><body><table>"; foreach (var t5 in t4) { htmlresult += t5.OuterHtml; } htmlresult += "</table></body></html>"; ; var peer2 = UserbotPeer.GetPeerFromIdAndType(e.Message.From.Id, ChatType.Private); var peer = new Tuple <TLAbsInputPeer, long>(peer2, e.Message.From.Id); var text = new Language(new Dictionary <string, string> { { "en", roomName } }); var document = UtilsFileText.GenerateFileFromString(htmlresult, roomName + ".html", roomName, "text/html"); await sender.SendFileAsync(document, peer, text, TextAsCaption.AS_CAPTION, e.Message.From.Username, e.Message.From.LanguageCode, null, true); }