Ejemplo n.º 1
0
        public async Task WhitelistUser(CommandContext c, DiscordMember m)
        {
            try
            {
                #region database connection

                var client     = new MongoClient("mongodb://127.0.0.1:27017/");
                var database   = client.GetDatabase("_YoneUsers");
                var collection = database.GetCollection <BsonDocument>($"_{m.Id}");
                var filter     = Builders <BsonDocument> .Filter.Eq("_id", 0);

                var document = collection.Find(filter).First();
                var data     = YoneUserAPI.BlacklistAPi.FromJson(document.ToJson());

                #endregion

                switch (data.Blocked)
                {
                case true:
                    await YoneUsers.WhitelistUser(m.Id);

                    await c.RespondAsync(string.Format("{0} has been whitelisted from using {1}!", m.Mention,
                                                       c.Client.CurrentUser.Mention));

                    break;

                case false:
                    await c.RespondAsync(
                        $"User({m.Mention}) has already been `whitelisted` from using `{c.Client.CurrentApplication.Name}`.");

                    break;
                }

                await YoneUsers.BlacklistUser(m.Id);

                await c.RespondAsync(string.Format("{0} has been blacklisted from using {1}!", m.Mention,
                                                   c.Client.CurrentUser.Mention));
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Sequence contains no elements"))
                {
                    await YoneUsers.CreateUserEntry(m.Id);

                    await YoneUsers.BlacklistUser(m.Id);

                    await c.RespondAsync(
                        $"{m.Mention} has been blacklisted from using {c.Client.CurrentUser.Mention}!");
                }
                else
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            try
            {
                #region database connection

                var client     = new MongoClient("mongodb://127.0.0.1:27017/");
                var database   = client.GetDatabase("_YoneUsers");
                var collection = database.GetCollection <BsonDocument>($"_{ctx.User.Id}");

                var filter = Builders <BsonDocument> .Filter.Eq("_id", 0);

                var document = collection.Find(filter).First();

                var data = YoneUserAPI.BlacklistAPi.FromJson(document.ToJson());

                #endregion

                if (data.Blocked)
                {
                    return(false);
                }
                if (data.Blocked == false)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Sequence contains no elements"))
                {
                    await YoneUsers.CreateUserEntry(ctx.User.Id);

                    return(true);
                }

                Console.WriteLine(e);
                throw;
            }

            return(false);
        }