Example #1
0
        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);
        }
Example #2
0
        public virtual async Task addMemmberTest()
        {
            NumberToSendMessage = ConfigurationManager.AppSettings[MemberInfoGetting.GetMemberName(() => NumberToSendMessage)];
            if (string.IsNullOrWhiteSpace(NumberToSendMessage))
            {
                throw new Exception("Please fill the" + MemberInfoGetting.GetMemberName(() => NumberToSendMessage) + " setting in app.config file first");
            }

            // this is because the contacts in the address come without the "+" prefix
            var normalizedNumber = NumberToSendMessage.StartsWith("+") ?
                                   NumberToSendMessage.Substring(1, NumberToSendMessage.Length - 1) :
                                   NumberToSendMessage;

            var client = NewClient();

            await client.ConnectAsync();

            var result = await client.GetContactsAsync();


            var user = result.Users
                       .OfType <TLUser>()
                       .FirstOrDefault(x => x.Phone == normalizedNumber);

            if (user == null)
            {
                throw new System.Exception("Number was not found in Contacts List of user: "******"khune");
            int b = 5;

            TLInputUser u = new TLInputUser()
            {
                UserId = user.Id, AccessHash = (long)user.AccessHash
            };
            int a = 5;
            await client.ConnectAsync();

            //var req = new TLRequestAddChatUser()
            //{
            //    ChatId = chat.Id,
            //    UserId = u,
            //    FwdLimit = 100
            //};
            TLVector <TLAbsInputUser>    u2 = new TLVector <TLAbsInputUser>();
            TLVector <TLAbsInputChannel> c2 = new TLVector <TLAbsInputChannel>();

            u2.Add(u);
            c2.Add(new TLInputChannel()
            {
                ChannelId = chat.Id, AccessHash = (long)chat.AccessHash
            });
            var req2 = new TLRequestInviteToChannel()
            {
                //Channel = new TLInputChannel() { ChannelId = chat.Id },
                Channel = c2[0],
                Users   = u2
            };
            await client.ConnectAsync();

            try
            {
                var update = await client.SendRequestAsync <TLUpdates>(req2);
            }

            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
            }
            int a2 = 5;
        }
Example #3
0
        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 <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));
        }