public async Task UnBlackListUserAsync(ulong userId)
            {
                var filteredBlacklist = CoreMethod.ReadFromFileToList(CoreMethod.GetFileLocation("UserBlacklist.txt"));

                filteredBlacklist = filteredBlacklist.Where(u => u != userId.ToString()).ToList();
                CoreMethod.WriteListToFile(filteredBlacklist, true, CoreMethod.GetFileLocation("UserBlacklist.txt"));
            }
        private static bool GetIsUserWhitelisted(SocketMessage message)
        {
            // If this command was NOT executed by predefined users, return a failure
            List <ulong> whitelistedUsers = new List <ulong>();

            CoreMethod.ReadFromFileToList(CoreMethod.GetFileLocation("UserWhitelist.txt")).ForEach(u => whitelistedUsers.Add(ulong.Parse(u)));

            //Test if user is whitelisted
            bool userIsWhiteListed = false;

            foreach (var user in whitelistedUsers)
            {
                if (message.Author.Id == user)
                {
                    userIsWhiteListed = true;
                }
            }

            bool userWhiteListed = false;

            if (userIsWhiteListed == true)
            {
                userWhiteListed = true;
            }

            return(userWhiteListed);
        }
 public async Task BlackListUserAsync(ulong userId)
 {
     //If user does not exist in block list, block
     if (!CoreMethod.ReadFromFileToList(CoreMethod.GetFileLocation("UserBlacklist.txt")).Contains(userId.ToString()))
     {
         CoreMethod.WriteStringToFile(userId.ToString(), false, CoreMethod.GetFileLocation("UserBlacklist.txt"));
     }
 }
Пример #4
0
        // Override the CheckPermissions method
        public async override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider _services)
        {
            // Get the client via Depedency Injection
            var client = _services.GetRequiredService <DiscordSocketClient>();

            // Get the ID of the bot's owner
            var appInfo = await client.GetApplicationInfoAsync().ConfigureAwait(false);

            var ownerId = appInfo.Owner.Id;

            //
            // If this command was NOT executed by predefined users, return a failure
            List <ulong> whitelistedUsers = new List <ulong>();

            whitelistedUsers.Add(ownerId);

            CoreMethod.ReadFromFileToList("UserWhitelist.txt").ForEach(u => whitelistedUsers.Add(ulong.Parse(u)));

            //Test if user is whitelisted
            bool userIsWhiteListed = false;

            foreach (var user in whitelistedUsers)
            {
                if (context.Message.Author.Id == user)
                {
                    userIsWhiteListed = true;
                }
            }

            if (userIsWhiteListed == false)
            {
                await context.Channel.SendMessageAsync(context.Message.Author.Mention + " You must be whitelisted by the great duck commander to use this command");

                return(PreconditionResult.FromError("You must be whitelisted by the great duck commander to use this command."));
            }
            else
            {
                return(PreconditionResult.FromSuccess());
            }
        }
        // Override the CheckPermissions method
        public async override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider _services)
        {
            try
            {
                //
                // If this command was executed by predefined users, return a failure
                List <ulong> blacklistedUsers = new List <ulong>();

                CoreMethod.ReadFromFileToList(CoreMethod.GetFileLocation("UserBlacklist.txt")).ForEach(u => blacklistedUsers.Add(ulong.Parse(u)));

                //Test if user is blacklisted
                bool userIsBlackListed = false;
                foreach (var user in blacklistedUsers)
                {
                    if (context.Message.Author.Id == user)
                    {
                        userIsBlackListed = true;
                    }
                }

                if (userIsBlackListed == false)
                {
                    return(PreconditionResult.FromSuccess());
                }
                else
                {
                    await context.Channel.SendMessageAsync(context.Message.Author.Mention + " You have been blocked from using this command");

                    return(PreconditionResult.FromError("You have been blocked from using this command."));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }