示例#1
0
        private async Task ReactionAddAsync(Cacheable <IUserMessage, ulong> cacheable, Cacheable <IMessageChannel, ulong> channel,
                                            SocketReaction reaction)
        {
            if (await channel.GetOrDownloadAsync() is IGuildChannel guildChannel)
            {
                MultiRoleEntry entry = GetEntry(guildChannel, reaction.MessageId);
                if (entry != null)
                {
                    string not_animated = reaction.Emote.ToString().Replace("<a:", "<:");
                    string animated     = reaction.Emote.ToString().Replace("<:", "<a:");
                    string success      = "";

                    if (entry.EmoteRolePairs.ContainsKey(animated))
                    {
                        success = animated;
                    }
                    else if (entry.EmoteRolePairs.ContainsKey(not_animated))
                    {
                        success = not_animated;
                    }

                    if (success != "")
                    {
                        IGuildUser user = reaction.User.GetValueOrDefault() as IGuildUser;
                        if (user.IsBot || user.IsWebhook)
                        {
                            return;
                        }
                        ulong roleId = entry.EmoteRolePairs[success];
                        if (entry.OnlyOne)
                        {
                            foreach (ulong id in user.RoleIds)
                            {
                                foreach (KeyValuePair <string, ulong> pair in entry.EmoteRolePairs)
                                {
                                    if (pair.Value == id)
                                    {
                                        try
                                        {
                                            await user.RemoveRoleAsync(guildChannel.Guild.GetRole(id));
                                        }
                                        catch { } // can't remove role
                                    }
                                }
                            }
                        }

                        if (!user.RoleIds.Contains(roleId))
                        {
                            if (guildChannel.Guild.GetRole(roleId) is IRole role)
                            {
                                await user.AddRoleAsync(role);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 private async Task MessageDeleted(Cacheable <IMessage, ulong> message, Cacheable <IMessageChannel, ulong> channel)
 {
     if (await channel.GetOrDownloadAsync() is IGuildChannel gCh)
     {
         MultiRoleEntry entry = GetEntry(gCh, channel.Id);
         if (entry != null)
         {
             Entries.Remove(entry);
             Save();
         }
     }
 }