Ejemplo n.º 1
0
            public async Task ChnlFilterInv(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;

                int removed;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var config = uow.GuildConfigs.For(channel.Guild.Id);
                    removed = config.FilterInvitesChannelIds.RemoveWhere(fc => fc.ChannelId == channel.Id);
                    if (removed == 0)
                    {
                        config.FilterInvitesChannelIds.Add(new Services.Database.Models.FilterChannelId()
                        {
                            ChannelId = channel.Id
                        });
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (removed == 0)
                {
                    InviteFilteringChannels.Add(channel.Id);
                    await channel.SendMessageAsync("`Invite filtering enabled on this channel.`").ConfigureAwait(false);
                }
                else
                {
                    InviteFilteringChannels.TryRemove(channel.Id);
                    await channel.SendMessageAsync("`Invite filtering disabled on this channel.`").ConfigureAwait(false);
                }
            }
Ejemplo n.º 2
0
            public async Task ChnlFilterInv()
            {
                var channel = (ITextChannel)Context.Channel;

                int removed;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var config = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds));
                    removed = config.FilterInvitesChannelIds.RemoveWhere(fc => fc.ChannelId == (long)channel.Id);
                    if (removed == 0)
                    {
                        config.FilterInvitesChannelIds.Add(new Services.Database.Models.FilterChannelId()
                        {
                            ChannelId = (long)channel.Id
                        });
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (removed == 0)
                {
                    InviteFilteringChannels.Add(channel.Id);
                    await ReplyConfirmLocalized("invite_filter_channel_on").ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalized("invite_filter_channel_off").ConfigureAwait(false);
                }
            }
Ejemplo n.º 3
0
        public async Task <bool> FilterInvites(IGuild guild, IUserMessage usrMsg)
        {
            if (guild is null)
            {
                return(false);
            }
            if (usrMsg is null)
            {
                return(false);
            }

            if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) ||
                 InviteFilteringServers.Contains(guild.Id)) &&
                usrMsg.Content.IsDiscordInvite())
            {
                try
                {
                    await usrMsg.DeleteAsync().ConfigureAwait(false);

                    return(true);
                }
                catch (HttpException ex)
                {
                    Log.Warning("I do not have permission to filter invites in channel with id " + usrMsg.Channel.Id, ex);
                    return(true);
                }
            }
            return(false);
        }