Exemplo n.º 1
0
        public async Task TestCommandArea(CommandContext c)
        {
            #region database connection

            var client     = new MongoClient("mongodb://127.0.0.1:27017/");
            var database   = client.GetDatabase("_YoneUsers");
            var collection = database.GetCollection <BsonDocument>($"_{c.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 == false)
            {
                await c.RespondAsync(
                    "You are not blocked from using `Yone`, But as I am testing I will block you from using yone (Not really since it doesn't work it, it is just a test!)");

                await c.RespondAsync("I have blacked listed you now");

                await YoneUsers.BlacklistUser(c.User.Id);
            }
            else if (data.Blocked)
            {
                await c.RespondAsync("I am now going to Whitelist from `Yone`.");

                await YoneUsers.WhitelistUser(c.User.Id);

                await c.RespondAsync("You may now use `Yone` again!.");
            }
        }
Exemplo n.º 2
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;
                }
            }
        }