public override void DeserializeBody(BinaryReader br) { flags = br.ReadInt32(); silent = (flags & 32) != 0; background = (flags & 64) != 0; from_peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br); id = (TLVector<int>)ObjectUtils.DeserializeVector<int>(br); random_id = (TLVector<long>)ObjectUtils.DeserializeVector<long>(br); to_peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br); }
public async Task <TLAbsDialogs> GetUserDialogsAsync(int offsetDate = 0, int offsetId = 0, TLAbsInputPeer offsetPeer = null, int limit = 100, CancellationToken token = default(CancellationToken)) { if (offsetPeer == null) { offsetPeer = new TLInputPeerSelf(); } var req = new TLRequestGetDialogs() { OffsetDate = offsetDate, OffsetId = offsetId, OffsetPeer = offsetPeer, Limit = limit }; return(await SendAuthenticatedRequestAsync <TLAbsDialogs>(req, token) .ConfigureAwait(false)); }
public override void DeserializeBody(BinaryReader br) { peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br); }
public override void DeserializeBody(BinaryReader br) { Peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br); }
public async Task SendMessageAsync(TLAbsInputPeer peer, string message) { await _telegramClient.SendMessageAsync(peer, message); }
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) { ; } }
public async Task <TLAbsDialogs> GetUserDialogsAsync(int offsetDate = 0, int offsetId = 0, TLAbsInputPeer offsetPeer = null, int limit = 100) { if (!IsUserAuthorized()) { throw new InvalidOperationException("Authorize user first!"); } if (offsetPeer == null) { offsetPeer = new TLInputPeerSelf(); } var req = new TLRequestGetDialogs() { OffsetDate = offsetDate, OffsetId = offsetId, OffsetPeer = offsetPeer, Limit = limit }; return(await SendRequestAsync <TLAbsDialogs>(req)); }
private static async Task <Tuple <bool?, string, long> > FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot3( TLAbsChat x4, TLAbsInputPeer u, TelegramBotAbstract telegramBotAbstract) { if (x4 == null) { return(null); } if (x4 is TLChat x5) { if (GlobalVariables.ExcludedChatsForBot.Contains(x5.Id)) { return(new Tuple <bool?, string, long>(null, x5.Title, x5.Id)); } var r5 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot4(x5, u, telegramBotAbstract); if (r5 == null) { return(new Tuple <bool?, string, long>(null, x5.Title, x5.Id)); } if (r5.Item2 == null) { return(new Tuple <bool?, string, long>(r5.Item1, x5.Title, x5.Id)); } WaitUntil(r5.Item2); var r6 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot4(x5, u, telegramBotAbstract); if (r6 == null) { ; return(new Tuple <bool?, string, long>(null, x5.Title, x5.Id)); } if (r6.Item2 == null) { return(new Tuple <bool?, string, long>(r6.Item1, x5.Title, x5.Id)); } ; } else if (x4 is TLChannel x6) { if (GlobalVariables.ExcludedChatsForBot.Contains(x6.Id)) { return(new Tuple <bool?, string, long>(null, x6.Title, x6.Id)); } var r2 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot5(x6, u, telegramBotAbstract); if (r2 == null) { ; return(new Tuple <bool?, string, long>(null, x6.Title, x6.Id)); } if (r2.Item2 == null) { return(new Tuple <bool?, string, long>(r2.Item1, x6.Title, x6.Id)); } WaitUntil(r2.Item2); var r3 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot5(x6, u, telegramBotAbstract); if (r3 == null) { ; return(new Tuple <bool?, string, long>(null, x6.Title, x6.Id)); } if (r3.Item2 == null) { return(new Tuple <bool?, string, long>(r3.Item1, x6.Title, x6.Id)); } ; } else if (x4 is TLChatForbidden chatForbidden) { ; } else { ; } return(null); }
public static async Task SendMessage(TelegramClient client, TLAbsInputPeer peer, string text) { await client.SendMessageAsync(peer, text); }
public static async Task <List <TLMessage> > GetLastMessages(TelegramClient client, TLAbsInputPeer peer, bool isChannel = false, int count = 2) { if (isChannel) { var msgHistory = await client.GetHistoryAsync(peer, limit : count) as TLChannelMessages; return(msgHistory?.Messages.Select(msg => msg as TLMessage).ToList()); } else { var msgHistory = await client.GetHistoryAsync(peer, limit : count) as TLMessagesSlice; return(msgHistory?.Messages.Select(msg => msg as TLMessage).ToList()); } }
public static async Task ForwardMessage(TelegramClient client, TLAbsInputPeer fromPeer, TLAbsInputPeer toPeer, int messageId) { var randomIds = new TLVector <long> { TLSharp.Core.Utils.Helpers.GenerateRandomLong() }; var forwardRequest = new TLRequestForwardMessages { FromPeer = fromPeer, Id = new TLVector <int> { messageId }, ToPeer = toPeer, RandomId = randomIds }; await client.SendRequestAsync <TLUpdates>(forwardRequest); }
private static async Task <Tuple <bool?, DateTime?> > FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot4( TLChat x5, TLAbsInputPeer u, TelegramBotAbstract telegramBotAbstract) { if (x5 == null) { return(null); } ; ; if (x5.MigratedTo == null) { var r4 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot6Async(x5, u, telegramBotAbstract); return(r4); } var x6 = x5.MigratedTo; TLInputChannel x8 = null; if (x6 is TLInputChannel x7) { x8 = x7; } else { ; return(null); } if (x5.MigratedTo == null) { return(null); } TLAbsInputChannel channel = x8; TLChatFull x = null; var channel2 = GetChannel(channel); if (channel2 == null) { return(new Tuple <bool?, DateTime?>(false, null)); } var isOurBotPresent2 = await CheckIfOurBotIsPresent2Async(channel2, 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 r3 = await InsertOurBotAsyncChat(x5, u, x8.AccessHash, telegramBotAbstract); return(new Tuple <bool?, DateTime?>(r3, null)); }
private static async Task <ResultF1> F1Async(TelegramBotAbstract telegramBotAbstract, long userIdOfOurBot, TLAbsInputPeer u, string x5Title, int x5Id, TLInputChannel channel) { var users = new TLVector <TLAbsInputUser>(); if (u == null) { return(new ResultF1(false, null, null, null)); } long accessHashUser = 0; ; TLInputPeerUser u5 = null; if (u is TLInputPeerUser u4) { u5 = u4; } if (u5 == null) { return(new ResultF1(false, null, null, null)); } accessHashUser = u5.AccessHash; TLAbsInputUser u2 = new TLInputUser { UserId = (int)userIdOfOurBot, AccessHash = accessHashUser }; users.Add(u2); TLAbsUpdates r = null; try { r = await telegramBotAbstract._userbotClient.ChannelsInviteToChannel(channel, users); } catch (Exception e) { var m = "\n"; m += "We can't add our bot in this group:\n"; m += "[Title] " + x5Title + "\n"; m += "[ID] " + x5Id; m += "\n --- end --- "; m += "\n"; var e2 = new Exception(m, e); await NotifyUtil.NotifyOwners(e2, telegramBotAbstract); return(new ResultF1(false, null, r, null)); } Thread.Sleep(2000); var idMessageAdded = GetIdMessageAdded(r); Tuple <TLAbsUpdates, Exception> r2 = null; try { r2 = await PromoteToAdminAsync(u2, channel, telegramBotAbstract); } catch (Exception e2) { ; } ; return(new ResultF1(null, idMessageAdded, r, r2)); }
public static async Task <bool> FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot2( TelegramBotAbstract telegramBotAbstract) { const int LIMIT = 20; var i = 0; TLAbsInputPeer u = await UserbotPeer.GetPeerUserWithAccessHash("polinetwork3bot", telegramBotAbstract._userbotClient); if (u == null) { return(false); } id_of_chats_we_know_are_ok = new Dictionary <long, bool>(); while (true) { TLAbsDialogs x = null; FloodException floodException1 = null; try { x = await telegramBotAbstract._userbotClient.GetUserDialogsAsync(limit : LIMIT, offsetId : i); } catch (FloodException floodException) { floodException1 = floodException; } if (x == null && floodException1 != null) { var untilWhen = GetUntilWhenWeCanMakeRequests(floodException1); WaitUntil(untilWhen); try { x = await telegramBotAbstract._userbotClient.GetUserDialogsAsync(limit : LIMIT, offsetId : i); } catch (Exception e7) { ; } } if (x == null) { return(i > 0); } if (x is TLDialogs x2) { if (x2.Chats != null) { foreach (var x4 in x2.Chats) { var r1 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot3(x4, u, telegramBotAbstract); await NotifyUtil.NotifyIfFalseAsync(r1, 1.ToString(), telegramBotAbstract); } } } else if (x is TLDialogsSlice x3) { if (x3.Chats != null) { foreach (var x4 in x3.Chats) { var r1 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot3(x4, u, telegramBotAbstract); await NotifyUtil.NotifyIfFalseAsync(r1, 2.ToString(), telegramBotAbstract); } } } else { ; } i += LIMIT; } throw new NotImplementedException(); }
public override void deserializeBody(InputStream stream, TLContext context) { this.peer = StreamingUtils.readTLObject(stream, context); this.id = StreamingUtils.readInt(stream); this.randomId = StreamingUtils.readLong(stream); }
public virtual void setPeer(TLAbsInputPeer value) { this.peer = value; }
public override void deserializeBody(InputStream stream, TLContext context) { this.peer = StreamingUtils.readTLObject(stream, context); this.action = StreamingUtils.readTLObject(stream, context); }