コード例 #1
0
        public async Task RemoveRank(params string[] rank)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command", LogSeverity.Critical);

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO REMOVE A RANK", LogSeverity.Critical);

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            SocketUser user = Context.User;

            string _rank = BotHelpers.CondenseStringArray(rank);

            bool doubleCheck = false;

            foreach (SocketRole role in Context.Guild.Roles)
            {
                if (role.Name == _rank)
                {
                    doubleCheck = true;
                    break;
                }
            }
            if (doubleCheck == true)
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == _rank);
                await(user as IGuildUser).RemoveRoleAsync(role);
                await(ReplyAsync("Rank removed!"));
            }
            else
            {
                await(ReplyAsync("Couldn't complete request!"));
            }
        }
コード例 #2
0
        public async Task CreateRankAsync(
            params string[] name)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command", LogSeverity.Critical);

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO MESSAGE PEOPLE", LogSeverity.Critical);

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            string _name = BotHelpers.CondenseStringArray(name);

            foreach (SocketRole role in Context.Guild.Roles)
            {
                if (role.Name == _name)
                {
                    await Context.Channel.SendMessageAsync("Rank already exists!");
                    await Log(Context.User.ToString() + "tried making the rank " + _name + " but it already exists!", LogSeverity.Error);

                    return;
                }
            }

            await Context.Guild.CreateRoleAsync(_name, null, null, false, null).ContinueWith(x => Context.Channel.SendMessageAsync("Rank made!"));

            await Log(Context.User.ToString() + " created the rank " + _name, LogSeverity.Info);
        }
コード例 #3
0
ファイル: InfoModule.cs プロジェクト: IanWigle/DiscordBot
        public async Task AnnoyDeath(string username, int numTimes, params string[] message)
        {
            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);
                    await ReplyAsync("You need to be on the whitelist!");

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            if (numTimes > 50)
            {
                numTimes = 50;
            }

            await Log($"Sending {numTimes} messages to " + username);

            var users = Context.Guild.Users;

            foreach (var user in users)
            {
                if (user.ToString() != username)
                {
                    continue;
                }

                for (int i = 0; i < numTimes; i++)
                {
                    await user.SendMessageAsync(BotHelpers.CondenseStringArray(message));

                    await Task.Delay(500);
                }
            }

            await ReplyAsync("☢️ The nukes have been launched towards " + username + ", god help us all. ☢️");

            return;
        }
コード例 #4
0
ファイル: AbilityModule.cs プロジェクト: IanWigle/DiscordBot
        public async Task DescribeAbility(params string[] name)
        {
            string _name = BotHelpers.CondenseStringArray(name);

            if (!Program.abilityLibrary.LibraryHasAbility(_name))
            {
                await Log(Context.User.ToString() + " asked for the invalid ability name " + _name, LogSeverity.Error);
                await ReplyAsync(_name + " is not a valid ability!");

                return;
            }
            else
            {
                Ability      ab           = Program.abilityLibrary.GetAbility(_name);
                EmbedBuilder embedBuilder = new EmbedBuilder();
                embedBuilder.AddField("Name", ab.Name);
                embedBuilder.AddField("Rank", ab.GetRankAsString());
                embedBuilder.AddField("Description", ab.Description);

                await ReplyAsync("Here is what I found . . . \n", false, embedBuilder.Build()).ContinueWith(x =>
                                                                                                            Log("Descibed the ability " + _name + " in the channel " + Context.Channel.ToString()));
            }
        }
コード例 #5
0
        public async Task MessagePlayersOfRank(string _rank, params string[] message)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command");

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO MESSAGE PEOPLE");

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            var users         = Context.Guild.Users;
            int numValidUsers = 0;

            foreach (var user in users)
            {
                bool hasRole = false;
                foreach (var role in user.Roles)
                {
                    if (role.ToString() == _rank)
                    {
                        hasRole = true;
                        break;
                    }
                }

                if (hasRole)
                {
                    string _message = BotHelpers.CondenseStringArray(message);

                    if (_message == "test" || _message == "")
                    {
                        _message = "Hello there! This is either a test, or the guy who made me do this didn't give me a message to give you.";
                    }

                    await user.SendMessageAsync(_message);
                    await Log("Sent message to " + user.ToString());

                    numValidUsers++;
                }
            }
            await ReplyAsync($"Sent {numValidUsers} messages");
        }