Exemplo n.º 1
0
        private void GetSoloMentions(BubbleGroup group, Action <List <Mention> > result)
        {
            using (var client = new FullClientDisposable(this))
            {
                var resultList = new List <Mention>();

                var user      = _dialogs.GetUser(uint.Parse(group.Address));
                var inputUser = TelegramUtils.CastUserToInputUser(user);

                UserFull userFull =
                    (UserFull)
                    TelegramUtils.RunSynchronously(
                        client.Client.Methods.UsersGetFullUserAsync(new UsersGetFullUserArgs
                {
                    Id = inputUser
                }));

                if (userFull == null)
                {
                    result(resultList);
                }

                var telegramBotInfo = userFull.BotInfo as SharpTelegram.Schema.BotInfo;
                if (telegramBotInfo != null)
                {
                    var username = TelegramUtils.GetUserHandle(user);
                    var name     = TelegramUtils.GetUserName(user);

                    var botCommandMention = new Mention
                    {
                        Type          = MentionType.BotCommand,
                        BubbleGroupId = group.ID,
                        Value         = username,
                        Name          = name,
                        Address       = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture)
                    };

                    var disaBotInfo = new Disa.Framework.Bots.BotInfo
                    {
                        Address     = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture),
                        Description = telegramBotInfo.Description,
                        Commands    = new List <Disa.Framework.Bots.BotCommand>()
                    };

                    foreach (var c in telegramBotInfo.Commands)
                    {
                        var telegramBotCommand = c as SharpTelegram.Schema.BotCommand;
                        if (telegramBotCommand != null)
                        {
                            disaBotInfo.Commands.Add(new Disa.Framework.Bots.BotCommand
                            {
                                Command     = telegramBotCommand.Command,
                                Description = telegramBotCommand.Description
                            });
                        }
                    }

                    botCommandMention.BotInfo = disaBotInfo;

                    resultList.Add(botCommandMention);
                }

                result(resultList);
            }
        }
Exemplo n.º 2
0
        private void GetPartyMentions(BubbleGroup group, Action <List <Mention> > result)
        {
            var fullChat          = MentionsFetchFullChat(group.Address, group.IsExtendedParty);
            var partyParticipants = MentionsGetPartyParticipants(fullChat);

            var resultList = new List <Mention>();

            if (!group.IsExtendedParty)
            {
                foreach (var partyParticipant in partyParticipants.ChatParticipants)
                {
                    var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                    if (id != null)
                    {
                        var user                 = _dialogs.GetUser(uint.Parse(id));
                        var username             = TelegramUtils.GetUserHandle(user);
                        var name                 = TelegramUtils.GetUserName(user);
                        var groupUsernameMention = new Mention
                        {
                            Type          = MentionType.Username,
                            BubbleGroupId = group.ID,
                            Value         = username,
                            Name          = name,
                            Address       = id
                        };
                        resultList.Add(groupUsernameMention);
                    }
                }
            }
            else
            {
                foreach (var partyParticipant in partyParticipants.ChannelParticipants)
                {
                    var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant);
                    if (id != null)
                    {
                        var user     = _dialogs.GetUser(uint.Parse(id));
                        var username = TelegramUtils.GetUserHandle(user);
                        var name     = TelegramUtils.GetUserName(user);
                        var channelUsernameMention = new Mention
                        {
                            Type          = MentionType.Username,
                            BubbleGroupId = group.ID,
                            Value         = username,
                            Name          = name,
                            Address       = id
                        };

                        resultList.Add(channelUsernameMention);
                    }
                }
            }

            var chatFull = fullChat.FullChat as ChatFull;

            if (chatFull != null)
            {
                foreach (var chatFullBotInfo in chatFull.BotInfo)
                {
                    var telegramBotInfo = chatFullBotInfo as SharpTelegram.Schema.BotInfo;
                    if (telegramBotInfo != null)
                    {
                        var user     = _dialogs.GetUser(telegramBotInfo.UserId);
                        var username = TelegramUtils.GetUserHandle(user);
                        var name     = TelegramUtils.GetUserName(user);

                        var botCommandMention = new Mention
                        {
                            Type          = MentionType.BotCommand,
                            BubbleGroupId = group.ID,
                            Value         = username,
                            Name          = name,
                            Address       = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture)
                        };

                        var disaBotInfo = new Disa.Framework.Bots.BotInfo
                        {
                            Address     = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture),
                            Description = telegramBotInfo.Description,
                            Commands    = new List <Disa.Framework.Bots.BotCommand>()
                        };

                        foreach (var c in telegramBotInfo.Commands)
                        {
                            var telegramBotCommand = c as SharpTelegram.Schema.BotCommand;
                            if (telegramBotCommand != null)
                            {
                                disaBotInfo.Commands.Add(new Disa.Framework.Bots.BotCommand
                                {
                                    Command     = telegramBotCommand.Command,
                                    Description = telegramBotCommand.Description
                                });
                            }
                        }

                        botCommandMention.BotInfo = disaBotInfo;

                        resultList.Add(botCommandMention);
                    }
                }
            }

            result(resultList);
        }