コード例 #1
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
 private bool IsPartOfParty(Participants partyParticipants)
 {
     if (partyParticipants.Type == ParticipantsType.Chat)
     {
         foreach (var partyParticipant in partyParticipants.ChatParticipants)
         {
             string participantAddress = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
             if (participantAddress == Settings.AccountId.ToString(CultureInfo.InvariantCulture))
             {
                 return(true);
             }
         }
     }
     else
     {
         foreach (var partyParticipant in partyParticipants.ChannelParticipants)
         {
             string participantAddress = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant);
             if (participantAddress == Settings.AccountId.ToString(CultureInfo.InvariantCulture))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #2
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
        private bool IsCreator(string address, bool superGroup)
        {
            var fullChat          = FetchFullChat(address, superGroup);
            var partyParticipants = GetPartyParticipants(fullChat);

            if (!superGroup)
            {
                foreach (var partyParticipant in partyParticipants.ChatParticipants)
                {
                    var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                    if (id == Settings.AccountId.ToString(CultureInfo.InvariantCulture))
                    {
                        //TODO:check how the protocol responds
                        if (partyParticipant is ChatParticipantCreator)
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                var channel = _dialogs.GetChat(uint.Parse(address)) as Channel;
                if (channel != null)
                {
                    return(channel.Creator != null);
                }
            }
            return(false);
        }
コード例 #3
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
 public Task GetPartyParticipants(BubbleGroup group, Action <DisaParticipant[]> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         var fullChat = FetchFullChat(group.Address, group.IsExtendedParty);
         var partyParticipants = GetPartyParticipants(fullChat);
         var resultList = new List <DisaParticipant>();
         if (!group.IsExtendedParty)
         {
             foreach (var partyParticipant in partyParticipants.ChatParticipants)
             {
                 var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                 if (id != null)
                 {
                     var name = TelegramUtils.GetUserName(_dialogs.GetUser(uint.Parse(id)));
                     resultList.Add(new DisaParticipant(name, id));
                 }
             }
         }
         else
         {
             foreach (var partyParticipant in partyParticipants.ChannelParticipants)
             {
                 var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant);
                 if (id != null)
                 {
                     var name = TelegramUtils.GetUserName(_dialogs.GetUser(uint.Parse(id)));
                     resultList.Add(new DisaParticipant(name, id));
                 }
             }
         }
         result(resultList.ToArray());
     }));
 }
コード例 #4
0
        private List <Mention> MentionsGetMentions(string token, string address, bool isChannel, TelegramClient optionalClient = null)
        {
            // Only handling usernames now
            if (token != "@")
            {
                return(new List <Mention>());
            }

            var fullChat          = MentionsFetchFullChat(address, isChannel, optionalClient);
            var partyParticipants = MentionsGetPartyParticipants(fullChat);

            var resultList = new List <Mention>();

            if (!isChannel)
            {
                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 mention  = new Mention
                        {
                            Type    = MentionType.Username,
                            Value   = username,
                            Name    = name,
                            Address = id
                        };
                        resultList.Add(mention);
                    }
                }
            }
            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 mention  = new Mention
                        {
                            Type    = MentionType.Username,
                            Value   = username,
                            Name    = name,
                            Address = id
                        };

                        resultList.Add(mention);
                    }
                }
            }

            return(resultList);
        }
コード例 #5
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
        public Task GetPartyLeaders(BubbleGroup group, Action <DisaParticipant[]> result)
        {
            return(Task.Factory.StartNew(() =>
            {
                var fullChat = FetchFullChat(group.Address, group.IsExtendedParty);
                var partyParticipants = GetPartyParticipants(fullChat);
                List <DisaParticipant> resultList = new List <DisaParticipant>();

                if (!group.IsExtendedParty)
                {
                    if (!ChatAdminsEnabled(group.Address))
                    {
                        foreach (var partyParticipant in partyParticipants.ChatParticipants)
                        {
                            var userId = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                            var user = _dialogs.GetUser(uint.Parse(userId));
                            resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId));
                        }
                    }
                    else
                    {
                        foreach (var partyParticipant in partyParticipants.ChatParticipants)
                        {
                            var userId = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                            if (partyParticipant is ChatParticipantAdmin || partyParticipant is ChatParticipantCreator)
                            {
                                var user = _dialogs.GetUser(uint.Parse(userId));
                                resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId));
                            }
                        }
                    }
                }
                else
                {
                    foreach (var partyParticipant in partyParticipants.ChannelParticipants)
                    {
                        if ((partyParticipant is ChannelParticipantCreator) || (partyParticipant is ChannelParticipantEditor) ||
                            (partyParticipant is ChannelParticipantModerator))
                        {
                            var userId = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant);
                            var user = _dialogs.GetUser(uint.Parse(userId));
                            resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId));
                        }
                    }
                }
                result(resultList.ToArray());
            }));
        }
コード例 #6
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
        private bool IsAdmin(string address, bool isSuperGroup)
        {
            var fullChat          = FetchFullChat(address, isSuperGroup);
            var partyParticipants = GetPartyParticipants(fullChat);

            if (!isSuperGroup)
            {
                if (!ChatAdminsEnabled(address))
                {
                    return(true);
                }
                foreach (var partyParticipant in partyParticipants.ChatParticipants)
                {
                    var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant);
                    if (id == Settings.AccountId.ToString(CultureInfo.InvariantCulture))
                    {
                        if ((partyParticipant is ChatParticipantAdmin) || (partyParticipant is ChatParticipantCreator))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                foreach (var partyParticipant in partyParticipants.ChannelParticipants)
                {
                    var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant);
                    if (id == Settings.AccountId.ToString(CultureInfo.InvariantCulture))
                    {
                        if ((partyParticipant is ChannelParticipantCreator) || (partyParticipant is ChannelParticipantEditor) ||
                            (partyParticipant is ChannelParticipantModerator))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #7
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);
        }