예제 #1
0
        public async Task UpdateReactionItem(ulong guildId, ReactionRoleItem item, Emote test)
        {
            // Update item
            item.GuildId = guildId;
            await this.reactionRoleItemDb.Save(item);

            await this.UpdateReactionRoleAndHeader(item.ReactionRoleId);
        }
예제 #2
0
        public async Task DeleteReactionItem(ulong guildId, string itemId)
        {
            ReactionRoleItem item = await this.reactionRoleItemDb.Load(itemId);

            if (item == null)
            {
                return;
            }

            if (item.GuildId != guildId)
            {
                throw new Exception("Attempt to delete another guilds reaction role");
            }

            await this.reactionRoleItemDb.Delete(itemId);

            await this.UpdateReactionRoleAndHeader(item.ReactionRoleId);
        }
예제 #3
0
        private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                // Try get reaction role
                ReactionRole reactionRole = await this.GetReactionRoleIfValid(message, channel, reaction);

                // Reaction Role not found or no Reactions - skip
                if (reactionRole == null || !reactionRole.Reactions.Any())
                {
                    return;
                }

                // If Item matching added Reaction doesn't exist for reaction role - skip
                ReactionRoleItem item = reactionRole.Reactions.FirstOrDefault(x => x.ReactionEmote.Name == reaction.Emote.Name && x.Role != null);
                if (item == null)
                {
                    return;
                }

                // Need to fetch message and guild to get user and role
                IUserMessage userMessage = await message.DownloadAsync();

                IGuild     guild = userMessage.GetGuild();
                IGuildUser user  = await guild.GetUserAsync(reaction.UserId);

                IRole role = guild.GetRole(item.Role.GetValueOrDefault());
                if (role != null)
                {
                    if (!user.RoleIds.Contains(role.Id))
                    {
                        await user.AddRoleAsync(role);
                    }
                }
            }
            catch (Exception ex)
            {
                await Utils.Logger.LogExceptionToDiscordChannel(
                    ex,
                    $"Role Reaction Added - MessageId: {message.Id}",
                    (channel as IGuildChannel)?.GuildId.ToString(),
                    (reaction.User.GetValueOrDefault() as IGuildUser)?.GetName());
            }
        }
예제 #4
0
        private async Task ReactionRemoved(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                // Try get reaction role
                ReactionRole reactionRole = await this.GetReactionRoleIfValid(message, channel, reaction);

                // Reaction Role not found or no Reactions - skip
                if (reactionRole == null || !reactionRole.Reactions.Any())
                {
                    return;
                }

                // If Item matching added Reaction doesn't exist for reaction role - skip
                ReactionRoleItem item = reactionRole.Reactions.FirstOrDefault(x => x.ReactionEmote.Name == reaction.Emote.Name && x.Role != null);
                if (item == null)
                {
                    return;
                }

                IUserMessage userMessage = await message.DownloadAsync();

                IGuild     guild = userMessage.GetGuild();
                IGuildUser user  = await guild.GetUserAsync(reaction.UserId);

                IRole role = guild.GetRole(item.Role.GetValueOrDefault());
                if (role != null)
                {
                    if (user.RoleIds.Contains(role.Id))
                    {
                        await user.RemoveRoleAsync(role);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }