コード例 #1
0
        public async Task AddRank(IRole rankRole, double cashRequired)
        {
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (rankRole.Position >= Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                throw new Exception($"DEA must be higher in the heigharhy than {rankRole.Mention}.");
            }
            if (guild.RankRoles == null)
            {
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, new BsonDocument()
                {
                    { rankRole.Id.ToString(), cashRequired }
                }), Context.Guild.Id);
            }
            else
            {
                if (guild.RankRoles.Any(x => x.Name == rankRole.Id.ToString()))
                {
                    throw new Exception("This role is already a rank role.");
                }
                if (guild.RankRoles.Any(x => (int)x.Value.AsDouble == (int)cashRequired))
                {
                    throw new Exception("There is already a role set to that amount of cash required.");
                }
                guild.RankRoles.Add(rankRole.Id.ToString(), cashRequired);
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id);
            }

            await ReplyAsync($"You have successfully added the {rankRole.Mention} rank!");
        }
コード例 #2
0
        public async Task SetNSFWChannel(ITextChannel nsfwChannel)
        {
            GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.NsfwId, nsfwChannel.Id), Context.Guild.Id);
            var nsfwRole = Context.Guild.GetRole(GuildRepository.FetchGuild(Context.Guild.Id).NsfwRoleId);

            if (nsfwRole != null && Context.Guild.CurrentUser.GuildPermissions.Administrator)
            {
                await nsfwChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions().Modify(null, null, null, PermValue.Deny));

                await nsfwChannel.AddPermissionOverwriteAsync(nsfwRole, new OverwritePermissions().Modify(null, null, null, PermValue.Allow));
            }
            await ReplyAsync($"{Context.User.Mention}, You have successfully set the NSFW channel to {nsfwChannel.Mention}.");
        }
コード例 #3
0
        public static async Task Handle(IGuild guild, ulong userId)
        {
            if (!((await guild.GetCurrentUserAsync()).GuildPermissions.ManageRoles))
            {
                return;
            }
            double cash = (UserRepository.FetchUser(userId, guild.Id)).Cash;
            var    user = await guild.GetUserAsync(userId);                         //FETCHES THE USER

            var currentUser = await guild.GetCurrentUserAsync() as SocketGuildUser; //FETCHES THE BOT'S USER

            var          guildData     = GuildRepository.FetchGuild(guild.Id);
            List <IRole> rolesToAdd    = new List <IRole>();
            List <IRole> rolesToRemove = new List <IRole>();

            if (guild != null && user != null && guildData.RankRoles != null)
            {
                //CHECKS IF THE ROLE EXISTS AND IF IT IS LOWER THAN THE BOT'S HIGHEST ROLE
                foreach (var rankRole in guildData.RankRoles)
                {
                    var role = guild.GetRole(Convert.ToUInt64(rankRole.Name));
                    if (role != null && role.Position < currentUser.Roles.OrderByDescending(x => x.Position).First().Position)
                    {
                        if (cash >= rankRole.Value && !user.RoleIds.Any(x => x.ToString() == rankRole.Name))
                        {
                            rolesToAdd.Add(role);
                        }
                        if (cash < rankRole.Value && user.RoleIds.Any(x => x.ToString() == rankRole.Name))
                        {
                            rolesToRemove.Add(role);
                        }
                    }
                    else
                    {
                        guildData.RankRoles.Remove(rankRole.Name);
                        await DEABot.Guilds.UpdateOneAsync(x => x.Id == guild.Id, DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guildData.RankRoles));
                    }
                }
                if (rolesToAdd.Count >= 1)
                {
                    await user.AddRolesAsync(rolesToAdd);
                }
                else if (rolesToRemove.Count >= 1)
                {
                    await user.RemoveRolesAsync(rolesToRemove);
                }
            }
        }
コード例 #4
0
        public async Task RemoveModRole(IRole modRole)
        {
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (guild.ModRoles == null)
            {
                throw new Exception("There are no moderator roles yet!");
            }
            if (!guild.ModRoles.Any(x => x.Name == modRole.Id.ToString()))
            {
                throw new Exception("This role is not a moderator role!");
            }
            guild.ModRoles.Remove(modRole.Id.ToString());
            GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, guild.ModRoles), Context.Guild.Id);
            await ReplyAsync($"{Context.User.Mention}, You have successfully set the moderator role to {modRole.Mention}!");
        }
コード例 #5
0
        public async Task RemoveRank(IRole rankRole)
        {
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (guild.RankRoles == null)
            {
                throw new Exception("There are no ranks yet!");
            }
            if (!guild.RankRoles.Any(x => x.Name == rankRole.Id.ToString()))
            {
                throw new Exception("This role is not a rank role.");
            }
            guild.RankRoles.Remove(rankRole.Id.ToString());
            GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id);
            await ReplyAsync($"You have successfully removed the {rankRole.Mention} rank!");
        }
コード例 #6
0
        public async Task Unmute(IGuildUser userToUnmute, [Remainder] string reason = "No reason.")
        {
            var mutedRoleId = GuildRepository.FetchGuild(Context.Guild.Id).MutedRoleId;

            if (userToUnmute.RoleIds.All(x => x != mutedRoleId))
            {
                throw new Exception("You cannot unmute a user who isn't muted.");
            }
            await ModuleMethods.InformSubjectAsync(Context.User, "Unmute", userToUnmute, reason);

            await userToUnmute.RemoveRoleAsync(Context.Guild.GetRole(mutedRoleId));

            MuteRepository.RemoveMute(userToUnmute.Id, Context.Guild.Id);
            await Logger.ModLog(Context, "Unmute", new Color(12, 255, 129), reason, userToUnmute);

            await ReplyAsync($"{Context.User.Mention} has successfully unmuted {userToUnmute.Mention}!");
        }
コード例 #7
0
ファイル: Gangs.cs プロジェクト: AushrewIsBae/Aushrew-DEA
        public async Task LeaveGang()
        {
            var gang   = GangRepository.FetchGang(Context);
            var prefix = GuildRepository.FetchGuild(Context.Guild.Id).Prefix;

            if (gang.LeaderId == Context.User.Id)
            {
                throw new Exception($"You may not leave a gang if you are the owner. Either destroy the gang with the `{prefix}DestroyGang` command, or " +
                                    $"transfer the ownership of the gang to another member with the `{prefix}TransferLeadership` command.");
            }
            GangRepository.RemoveMember(Context.User.Id, Context.Guild.Id);
            await ReplyAsync($"{Context.User.Mention}, You have successfully left {gang.Name}");

            var channel = await Context.Client.GetUser(gang.LeaderId).CreateDMChannelAsync();

            await channel.SendMessageAsync($"{Context.User} has left {gang.Name}.");
        }
コード例 #8
0
        public async Task SetNSFWRole(IRole nsfwRole)
        {
            if (nsfwRole.Position > Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                throw new Exception("You may not set the NSFW role to a role that is higher in hierarchy than DEA's highest role.");
            }
            GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.NsfwRoleId, nsfwRole.Id), Context.Guild.Id);
            var nsfwChannel = Context.Guild.GetChannel(GuildRepository.FetchGuild(Context.Guild.Id).NsfwId);

            if (nsfwChannel != null && Context.Guild.CurrentUser.GuildPermissions.Administrator)
            {
                await nsfwChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions().Modify(null, null, null, PermValue.Deny));

                await nsfwChannel.AddPermissionOverwriteAsync(nsfwRole, new OverwritePermissions().Modify(null, null, null, PermValue.Allow));
            }
            await ReplyAsync($"{Context.User.Mention}, You have successfully set the NSFW role to {nsfwRole.Mention}.");
        }
コード例 #9
0
        public async Task ChangeNSFWSettings()
        {
            switch (GuildRepository.FetchGuild(Context.Guild.Id).Nsfw)
            {
            case true:
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.Nsfw, false), Context.Guild.Id);
                await ReplyAsync($"{Context.User.Mention}, You have successfully disabled NSFW commands!");

                break;

            case false:
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.Nsfw, true), Context.Guild.Id);
                await ReplyAsync($"{Context.User.Mention}, You have successfully enabled NSFW commands!");

                break;
            }
        }
コード例 #10
0
 private void AutoUnmute()
 {
     Timer t = new Timer(async method =>
     {
         foreach (Mute mute in await(await DEABot.Mutes.FindAsync("")).ToListAsync())
         {
             if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds > mute.MuteLength)
             {
                 var guild = _client.GetGuild(mute.GuildId);
                 if (guild != null && guild.GetUser(mute.UserId) != null)
                 {
                     var guildData = GuildRepository.FetchGuild(guild.Id);
                     var mutedRole = guild.GetRole(guildData.MutedRoleId);
                     if (mutedRole != null && guild.GetUser(mute.UserId).Roles.Any(x => x.Id == mutedRole.Id))
                     {
                         var channel = guild.GetTextChannel(guildData.ModLogId);
                         if (channel != null && guild.CurrentUser.GuildPermissions.EmbedLinks &&
                             (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).SendMessages &&
                             (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).EmbedLinks)
                         {
                             await guild.GetUser(mute.UserId).RemoveRoleAsync(mutedRole);
                             var footer = new EmbedFooterBuilder()
                             {
                                 IconUrl = "http://i.imgur.com/BQZJAqT.png",
                                 Text    = $"Case #{guildData.CaseNumber}"
                             };
                             var builder = new EmbedBuilder()
                             {
                                 Color       = new Color(12, 255, 129),
                                 Description = $"**Action:** Automatic Unmute\n**User:** {guild.GetUser(mute.UserId)} ({guild.GetUser(mute.UserId).Id})",
                                 Footer      = footer
                             }.WithCurrentTimestamp();
                             GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guildData.CaseNumber), guild.Id);
                             await channel.SendMessageAsync("", embed: builder);
                         }
                     }
                 }
                 MuteRepository.RemoveMute(mute.UserId, mute.GuildId);
             }
         }
     },
                         null,
                         Config.AUTO_UNMUTE_COOLDOWN,
                         Timeout.Infinite);
 }
コード例 #11
0
        public static IRole FetchRank(SocketCommandContext context)
        {
            var   guild = GuildRepository.FetchGuild(context.Guild.Id);
            var   cash  = UserRepository.FetchUser(context).Cash;
            IRole role  = null;

            if (guild.RankRoles != null)
            {
                foreach (var rankRole in guild.RankRoles.OrderBy(x => x.Value))
                {
                    if (cash >= rankRole.Value)
                    {
                        role = context.Guild.GetRole(Convert.ToUInt64(rankRole.Name));
                    }
                }
            }
            return(role);
        }
コード例 #12
0
        private async Task HandleUserJoin(SocketGuildUser u)
        {
            await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false);

            var user      = u as IGuildUser;
            var mutedRole = user.Guild.GetRole(((GuildRepository.FetchGuild(user.Guild.Id)).MutedRoleId));

            if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles &&
                mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                await RankHandler.Handle(u.Guild, u.Id);

                if (MuteRepository.IsMuted(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                {
                    await user.AddRoleAsync(mutedRole);
                }
            }
        }
コード例 #13
0
        public static async Task DetailedLog(SocketGuild guild, string actionType, string action, string objectType, string objectName, ulong id, Color color, bool incrementCaseNumber = true)
        {
            var guildData = GuildRepository.FetchGuild(guild.Id);

            if (guild.GetTextChannel(guildData.DetailedLogsId) != null)
            {
                var channel = guild.GetTextChannel(guildData.DetailedLogsId);
                if (guild.CurrentUser.GuildPermissions.EmbedLinks && (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).SendMessages &&
                    (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).EmbedLinks)
                {
                    string caseText = $"Case #{guildData.CaseNumber}";
                    if (!incrementCaseNumber)
                    {
                        caseText = id.ToString();
                    }
                    EmbedFooterBuilder footer = new EmbedFooterBuilder()
                    {
                        IconUrl = "http://i.imgur.com/BQZJAqT.png",
                        Text    = caseText
                    };

                    string idText = null;
                    if (incrementCaseNumber)
                    {
                        idText = $"\n**Id:** {id}";
                    }
                    var builder = new EmbedBuilder()
                    {
                        Color       = color,
                        Description = $"**{actionType}:** {action}\n**{objectType}:** {objectName}{idText}",
                        Footer      = footer
                    }.WithCurrentTimestamp();

                    await guild.GetTextChannel(guildData.DetailedLogsId).SendMessageAsync("", embed: builder);

                    if (incrementCaseNumber)
                    {
                        GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guildData.CaseNumber), guild.Id);
                    }
                }
            }
        }
コード例 #14
0
        public async Task JoinNSFW()
        {
            var guild    = GuildRepository.FetchGuild(Context.Guild.Id);
            var NsfwRole = Context.Guild.GetRole(guild.NsfwRoleId);

            if (NsfwRole == null)
            {
                throw new Exception("Everyone will always be able to use NSFW commands since there has been no NSFW role that has been set.\n" +
                                    $"In order to change this, an administrator may use the `{guild.Prefix}SetNSFWRole` command.");
            }
            if ((Context.User as IGuildUser).RoleIds.Any(x => x == guild.NsfwRoleId))
            {
                await(Context.User as IGuildUser).RemoveRoleAsync(NsfwRole);
                await ReplyAsync($"{Context.User.Mention}, You have successfully disabled your ability to use NSFW commands.");
            }
            else
            {
                await(Context.User as IGuildUser).AddRoleAsync(NsfwRole);
                await ReplyAsync($"{Context.User.Mention}, You have successfully enabled your ability to use NSFW commands.");
            }
        }
コード例 #15
0
        public async Task CleanAsync(int count = 25, [Remainder] string reason = "No reason.")
        {
            if (count < Config.MIN_CLEAR)
            {
                throw new Exception($"You may not clear less than {Config.MIN_CLEAR} messages.");
            }
            if (count > Config.MAX_CLEAR)
            {
                throw new Exception($"You may not clear more than {Config.MAX_CLEAR} messages.");
            }
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (Context.Channel.Id == guild.ModLogId || Context.Channel.Id == guild.DetailedLogsId)
            {
                throw new Exception("For security reasons, you may not use this command in a log channel.");
            }
            var messages = await Context.Channel.GetMessagesAsync(count).Flatten();

            await Context.Channel.DeleteMessagesAsync(messages);

            await Logger.ModLog(Context, "Clear", new Color(34, 59, 255), reason, null, $"\n**Quantity:** {count}");
        }
コード例 #16
0
        public async Task AddModRole(IRole modRole, int permissionLevel = 1)
        {
            if (permissionLevel < 1 || permissionLevel > 3)
            {
                throw new Exception("Permission levels:\nModeration: 1\nAdministration: 2\nServer Owner: 3");
            }
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (guild.ModRoles == null)
            {
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, new BsonDocument()
                {
                    { modRole.Id.ToString(), permissionLevel }
                }), Context.Guild.Id);
            }
            else
            {
                guild.ModRoles.Add(modRole.Id.ToString(), permissionLevel);
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.ModRoles, guild.ModRoles), Context.Guild.Id);
            }
            await ReplyAsync($"{Context.User.Mention}, You have successfully add {modRole.Mention} as a Moderation role with a permission level of {permissionLevel}.");
        }
コード例 #17
0
        public static bool IsMod(SocketCommandContext context, IGuildUser user)
        {
            if (user.GuildPermissions.Administrator)
            {
                return(true);
            }
            var guild = GuildRepository.FetchGuild(context.Guild.Id);

            if (guild.ModRoles != null)
            {
                foreach (var role in guild.ModRoles)
                {
                    if (user.Guild.GetRole(Convert.ToUInt64(role.Value)) != null)
                    {
                        if (user.RoleIds.Any(x => x.ToString() == role.Value))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #18
0
        public async Task Mute(IGuildUser userToMute, [Remainder] string reason = "No reason.")
        {
            var guild     = GuildRepository.FetchGuild(Context.Guild.Id);
            var mutedRole = Context.Guild.GetRole(guild.MutedRoleId);

            if (mutedRole == null)
            {
                throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " +
                                    $"`{guild.Prefix}SetMutedRole` command to change that.");
            }
            if (ModuleMethods.IsMod(Context, userToMute))
            {
                throw new Exception("You cannot mute another mod!");
            }
            await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason);

            await userToMute.AddRoleAsync(mutedRole);

            MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, Config.DEFAULT_MUTE_TIME);
            await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {Config.DEFAULT_MUTE_TIME.TotalHours} hours");

            await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention}!");
        }
コード例 #19
0
        public async Task CustomMute(double hours, IGuildUser userToMute, [Remainder] string reason = "No reason.")
        {
            if (hours > 168)
            {
                throw new Exception("You may not mute a user for more than a week.");
            }
            if (hours < 1)
            {
                throw new Exception("You may not mute a user for less than 1 hour.");
            }
            string time = "hours";

            if (hours == 1)
            {
                time = "hour";
            }
            var guild     = GuildRepository.FetchGuild(Context.Guild.Id);
            var mutedRole = Context.Guild.GetRole(guild.MutedRoleId);

            if (mutedRole == null)
            {
                throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " +
                                    $"{guild.Prefix}SetMutedRole command to change that.");
            }
            if (ModuleMethods.IsMod(Context, userToMute))
            {
                throw new Exception("You cannot mute another mod!");
            }
            await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason);

            await userToMute.AddRoleAsync(mutedRole);

            MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, TimeSpan.FromHours(hours));
            await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {hours} {time}");

            await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention} for {hours} {time}!");
        }
コード例 #20
0
        public async Task Invest(string investString = null)
        {
            var    guild = GuildRepository.FetchGuild(Context.Guild.Id);
            var    user  = UserRepository.FetchUser(Context);
            double cash  = user.Cash;

            switch (investString)
            {
            case "line":
                if (Config.LINE_COST > cash)
                {
                    await ReplyAsync($"{Context.User.Mention}, you do not have enough money. Balance: {cash.ToString("C", Config.CI)}");

                    break;
                }
                if (user.MessageCooldown == Config.LINE_COOLDOWN.TotalMilliseconds)
                {
                    await ReplyAsync($"{Context.User.Mention}, you have already purchased this investment.");

                    break;
                }
                await UserRepository.EditCashAsync(Context, -Config.LINE_COST);

                UserRepository.Modify(DEABot.UserUpdateBuilder.Set(x => x.MessageCooldown, Config.LINE_COOLDOWN.TotalMilliseconds), Context);
                await ReplyAsync($"{Context.User.Mention}, don't forget to wipe your nose when you are done with that line.");

                break;

            case "pound":
            case "lb":
                if (Config.POUND_COST > cash)
                {
                    await ReplyAsync($"{Context.User.Mention}, you do not have enough money. Balance: {cash.ToString("C", Config.CI)}");

                    break;
                }
                if (user.InvestmentMultiplier >= Config.POUND_MULTIPLIER)
                {
                    await ReplyAsync($"{Context.User.Mention}, you already purchased this investment.");

                    break;
                }
                await UserRepository.EditCashAsync(Context, -Config.POUND_COST);

                UserRepository.Modify(DEABot.UserUpdateBuilder.Set(x => x.InvestmentMultiplier, Config.POUND_MULTIPLIER), Context);
                await ReplyAsync($"{Context.User.Mention}, ***DOUBLE CASH SMACK DAB CENTER N***A!***");

                break;

            case "kg":
            case "kilo":
            case "kilogram":
                if (Config.KILO_COST > cash)
                {
                    await ReplyAsync($"{Context.User.Mention}, you do not have enough money. Balance: {cash.ToString("C", Config.CI)}");

                    break;
                }
                if (user.InvestmentMultiplier != Config.POUND_MULTIPLIER)
                {
                    await ReplyAsync($"{Context.User.Mention}, you must purchase the pound of cocaine investment before buying this one.");

                    break;
                }
                if (user.InvestmentMultiplier >= Config.KILO_MULTIPLIER)
                {
                    await ReplyAsync($"{Context.User.Mention}, you already purchased this investment.");

                    break;
                }
                await UserRepository.EditCashAsync(Context, -Config.KILO_COST);

                UserRepository.Modify(DEABot.UserUpdateBuilder.Set(x => x.InvestmentMultiplier, Config.KILO_MULTIPLIER), Context);
                await ReplyAsync($"{Context.User.Mention}, only the black jews would actually enjoy 4$/msg.");

                break;

            default:
                var builder = new EmbedBuilder()
                {
                    Title       = "Current Available Investments:",
                    Color       = new Color(0x0000FF),
                    Description = ($"\n**Cost: {Config.LINE_COST}$** | Command: `{guild.Prefix}investments line` | Description: " +
                                   $"One line of blow. Seems like nothing, yet it's enough to lower the message cooldown from 30 to 25 seconds." +
                                   $"\n**Cost: {Config.POUND_COST}$** | Command: `{guild.Prefix}investments pound` | Description: " +
                                   $"This one pound of coke will double the amount of cash you get per message\n**Cost: {Config.KILO_COST}$** | Command: " +
                                   $"`{guild.Prefix}investments kilo` | Description: A kilo of cocaine is more than enough to " +
                                   $"quadruple your cash/message.\n These investments stack with the chatting multiplier. However, they will not stack with themselves."),
                };
                await ReplyAsync("", embed : builder);

                break;
            }
        }
コード例 #21
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            var Context = new SocketCommandContext(_client, msg);

            if (Context.User.IsBot)
            {
                return;
            }

            if (!(Context.Channel is SocketTextChannel))
            {
                return;
            }

            if (!(Context.Guild.CurrentUser as IGuildUser).GetPermissions(Context.Channel as SocketTextChannel).SendMessages)
            {
                return;
            }

            int argPos = 0;

            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            string prefix = guild.Prefix;

            if (msg.HasStringPrefix(prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                PrettyConsole.Log(LogSeverity.Debug, $"Guild: {Context.Guild.Name}, User: {Context.User}", msg.Content);
                var result = await _service.ExecuteAsync(Context, argPos, _map);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    var cmd = _service.Search(Context, argPos).Commands.First().Command;
                    if (result.ErrorReason.Length == 0)
                    {
                        return;
                    }
                    switch (result.Error)
                    {
                    case CommandError.BadArgCount:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, You are incorrectly using this command. Usage: `{prefix}{cmd.Remarks}`");

                        break;

                    case CommandError.ParseFailed:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, Invalid number.");

                        break;

                    default:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, {result.ErrorReason}");

                        break;
                    }
                }
            }
            else if (msg.ToString().Length >= Config.MIN_CHAR_LENGTH && !msg.ToString().StartsWith(":"))
            {
                var user = UserRepository.FetchUser(Context);

                if (DateTime.UtcNow.Subtract(user.Message).TotalMilliseconds > user.MessageCooldown)
                {
                    UserRepository.Modify(DEABot.UserUpdateBuilder.Combine(
                                              DEABot.UserUpdateBuilder.Set(x => x.Cash, guild.GlobalChattingMultiplier * user.TemporaryMultiplier * user.InvestmentMultiplier + user.Cash),
                                              DEABot.UserUpdateBuilder.Set(x => x.TemporaryMultiplier, user.TemporaryMultiplier + guild.TempMultiplierIncreaseRate),
                                              DEABot.UserUpdateBuilder.Set(x => x.Message, DateTime.UtcNow)), Context);
                    await RankHandler.Handle(Context.Guild, Context.User.Id);
                }
            }
        }
コード例 #22
0
ファイル: System.cs プロジェクト: AushrewIsBae/Aushrew-DEA
        public async Task HelpAsync(string commandOrModule = null)
        {
            string prefix = GuildRepository.FetchGuild(Context.Guild.Id).Prefix;

            if (commandOrModule != null)
            {
                if (commandOrModule.StartsWith(prefix))
                {
                    commandOrModule = commandOrModule.Remove(0, prefix.Length);
                }
                foreach (var module in _service.Modules)
                {
                    if (module.Name.ToLower() == commandOrModule.ToLower())
                    {
                        var longestInModule = 0;
                        foreach (var cmd in module.Commands)
                        {
                            if (cmd.Aliases.First().Length > longestInModule)
                            {
                                longestInModule = cmd.Aliases.First().Length;
                            }
                        }
                        var moduleInfo = $"**{module.Name} Commands **: ```asciidoc\n";
                        foreach (var cmd in module.Commands)
                        {
                            moduleInfo += $"{prefix}{cmd.Aliases.First()}{new string(' ', (longestInModule + 1) - cmd.Aliases.First().Length)} :: {cmd.Summary}\n";
                        }
                        moduleInfo += "```";
                        await ReplyAsync(moduleInfo);

                        return;
                    }
                }

                foreach (var module in _service.Modules)
                {
                    foreach (var cmd in module.Commands)
                    {
                        foreach (var alias in cmd.Aliases)
                        {
                            if (alias == commandOrModule.ToLower())
                            {
                                var command = new EmbedBuilder()
                                {
                                    Title       = $"{cmd.Name}",
                                    Color       = new Color(0x00AE86),
                                    Description = $"**Description:** {cmd.Summary}\n"
                                };
                                if (cmd.Remarks != null)
                                {
                                    command.Description += $"**Usage:** `{prefix}{cmd.Remarks}`";
                                }
                                await ReplyAsync("", embed : command);

                                return;
                            }
                        }
                    }
                }
                string modules = "";
                foreach (var module in _service.Modules)
                {
                    modules += $"{module.Name}, ";
                }
                await ReplyAsync($"This command/module does not exist. Current list of modules: {modules.Substring(0, modules.Length - 2)}.");
            }
            else
            {
                string modules = "";
                foreach (var module in _service.Modules)
                {
                    modules += $"{module.Name}, ";
                }
                var help = new EmbedBuilder()
                {
                    Title       = "Welcome to DEA",
                    Color       = new Color(0x00AE86),
                    Description = $@"DEA is a multi-purpose Discord Bot mainly known for it's infamous Cash System with multiple subtleties referencing to the show Narcos, which inspired the creation of this masterpiece.

For all information about command usage and setup on your Discord Sever, view the documentation: <https://realblazeit.github.io/DEA/>

This command may be used for view the commands for each of the following modules: {modules.Substring(0, modules.Length - 2)}. It may also be used the view the usage of a specific command.

In order to **add DEA to your Discord Server**, click the following link: <https://discordapp.com/oauth2/authorize?client_id={Context.Client.CurrentUser.Id}&scope=bot&permissions=477195286> 

If you have any other questions, you may join the **Official DEA Discord Server:** <https://discord.gg/Tuptja9>, a server home to infamous meme events such as insanity."
                };

                var channel = await Context.User.CreateDMChannelAsync();

                await channel.SendMessageAsync("", embed : help);
                await ReplyAsync($"{Context.User.Mention}, you have been DMed with all the command information!");
            }
        }
コード例 #23
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            var user   = context.User as IGuildUser;
            var dbUser = UserRepository.FetchUser(context as SocketCommandContext);
            var guild  = GuildRepository.FetchGuild(context.Guild.Id);

            foreach (var attribute in attributes)
            {
                switch (attribute)
                {
                case Attributes.BotOwner:
                    if (!DEABot.Credentials.OwnerIds.Any(x => x == context.User.Id))
                    {
                        return(PreconditionResult.FromError("Only an owner of this bot may use this command."));
                    }
                    break;

                case Attributes.ServerOwner:
                    if (user.Guild.OwnerId != user.Id && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 3)))
                    {
                        return(PreconditionResult.FromError("Only the owners of this server may use this command."));
                    }
                    break;

                case Attributes.Admin:
                    if (!(context.User as IGuildUser).GuildPermissions.Administrator && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 2)))
                    {
                        return(PreconditionResult.FromError("The administrator permission is required to use this command."));
                    }
                    break;

                case Attributes.Moderator:
                    if (guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString())))
                    {
                        return(PreconditionResult.FromError("Only a moderator may use this command."));
                    }
                    break;

                case Attributes.Nsfw:
                    if (!guild.Nsfw)
                    {
                        return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " +
                                                            $"`{guild.Prefix}ChangeNSFWSettings` command."));
                    }
                    var nsfwChannel = await context.Guild.GetChannelAsync(guild.NsfwId);

                    if (nsfwChannel != null && context.Channel.Id != guild.NsfwId)
                    {
                        return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}."));
                    }
                    var nsfwRole = context.Guild.GetRole(guild.NsfwRoleId);
                    if (nsfwRole != null && (context.User as IGuildUser).RoleIds.All(x => x != guild.NsfwRoleId))
                    {
                        return(PreconditionResult.FromError($"You do not have permission to use this command.\nRequired role: {nsfwRole.Mention}"));
                    }
                    break;

                case Attributes.InGang:
                    if (!GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You must be in a gang to use this command."));
                    }
                    break;

                case Attributes.NoGang:
                    if (GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You may not use this command while in a gang."));
                    }
                    break;

                case Attributes.GangLeader:
                    if (GangRepository.FetchGang(context.User.Id, context.Guild.Id).LeaderId != context.User.Id)
                    {
                        return(PreconditionResult.FromError("You must be the leader of a gang to use this command."));
                    }
                    break;

                case Attributes.Jump:
                    if (dbUser.Cash < guild.JumpRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.JumpRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Steal:
                    if (dbUser.Cash < guild.StealRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.StealRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Bully:
                    if (dbUser.Cash < guild.BullyRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.BullyRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Rob:
                    if (dbUser.Cash < guild.RobRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.RobRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.FiftyX2:
                    if (dbUser.Cash < guild.FiftyX2Requirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.FiftyX2Requirement.ToString("C", Config.CI)}."));
                    }
                    break;

                default:
                    throw new Exception($"ERROR: The {attribute} attribute does not exist!");
                }
            }
            return(PreconditionResult.FromSuccess());
        }