Пример #1
0
        /// <inheritdoc cref="IDatabaseService.RemoveBinding"/>
        public async Task <bool> RemoveBinding(IEntity <ulong> guild)
        {
            using (var db = new BlacklistUserContext(dbOptions))
            {
                var entities = db.BlacklistUserBindings.Where(b => b.GuildId == guild.Id);
                if (!entities.Any())
                {
                    return(false);
                }

                db.BlacklistUserBindings.RemoveRange(entities);
                await db.SaveChangesAsync();

                return(true);
            }
        }
Пример #2
0
        public async Task <bool> RemoveBinding(IGuild guild, IGuildUser user)
        {
            using (var db = new BlacklistUserContext(dbOptions))
            {
                var entity = await db.BlacklistUserBindings.FirstOrDefaultAsync(b => b.GuildId == guild.Id && b.UserId == user.Id);

                if (entity == null)
                {
                    return(false);
                }

                db.BlacklistUserBindings.Remove(entity);
                await db.SaveChangesAsync();

                return(true);
            }
        }
Пример #3
0
        /// <summary>
        /// Adds a binding to blacklist a user in a specific guild to not be able to use botfunctions.
        /// </summary>
        /// <param name="guild"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <bool> AddBinding(IGuild guild, IGuildUser user)
        {
            using (var db = new BlacklistUserContext(dbOptions))
            {
                if (db.BlacklistUserBindings.Any(b => b.GuildId == guild.Id && b.UserId == user.Id))
                {
                    return(false);
                }

                db.BlacklistUserBindings.Add(new BlacklistUserBinding
                {
                    GuildId = guild.Id,
                    UserId  = user.Id,
                });
                await db.SaveChangesAsync();

                return(true);
            }
        }
Пример #4
0
 public bool CheckBinding(IGuild guild, IGuildUser user)
 {
     using (var db = new BlacklistUserContext(dbOptions))
         return(db.BlacklistUserBindings.Any(b => b.GuildId == guild.Id && b.UserId == user.Id));
 }