public async Task Ban(IGuildUser userToBan, [Remainder] string reason = null) { if (_moderationService.GetPermLevel(Context, Context.GUser) <= _moderationService.GetPermLevel(Context, userToBan)) { ReplyError("You cannot ban another mod with a permission level higher or equal to your own."); } await _moderationService.InformSubjectAsync(Context.User, "Ban", userToBan, reason); await Context.Guild.AddBanAsync(userToBan); await SendAsync($"{Context.User.Boldify()} has successfully banned {userToBan.Boldify()}."); await _moderationService.ModLogAsync(Context, "Ban", Config.ERROR_COLOR, reason, userToBan); }
public async Task AddPoll([Summary("Are you white?")] string poll, [Summary("HELL YEA~No~Maybe")] string choices, double daysToLast = 1, bool elderOnly = false, bool modOnly = false) { var isMod = _moderationService.GetPermLevel(Context, Context.GUser) > 0; if (modOnly && !isMod) { ReplyError("Only moderators may create mod only polls."); } var choicesArray = choices.Split('~'); if (choicesArray.Distinct().Count() != choicesArray.Length) { ReplyError("You may not have multiple choices that are identicle."); } await _pollRepo.CreatePollAsync(Context, poll, choicesArray, TimeSpan.FromDays(daysToLast), elderOnly, modOnly, isMod); await ReplyAsync($"You have successfully created poll #{await _pollRepo.Collection.CountAsync(y => y.GuildId == Context.Guild.Id)}."); }
public async Task Bully(IGuildUser userToBully, [Remainder] string nickname) { if (nickname.Length > 32) { ReplyError("The length of a nickname may not be longer than 32 characters."); } else if (_moderationService.GetPermLevel(Context, userToBully) > 0) { ReplyError("You may not bully a moderator."); } else if ((await _userRepo.GetUserAsync(userToBully)).Cash >= Context.Cash) { ReplyError("You may not bully a user with more money than you."); } await userToBully.ModifyAsync(x => x.Nickname = nickname); await SendAsync($"{userToBully.Boldify()} just got ***BULLIED*** by {Context.User.Boldify()} with his new nickname: \"{nickname}\"."); }
public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _credentials = _serviceProvider.GetService <Credentials>(); _userRepo = _serviceProvider.GetService <UserRepository>(); _moderationService = serviceProvider.GetService <ModerationService>(); _guildRepo = _serviceProvider.GetService <GuildRepository>(); _gangRepo = _serviceProvider.GetService <GangRepository>(); var guildUser = context.User as IGuildUser; var DbUser = await _userRepo.GetUserAsync(guildUser); var DbGuild = await _guildRepo.GetGuildAsync(context.Guild.Id); foreach (var attribute in _attributes) { switch (attribute) { case Attributes.BotOwner: if (!_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 (context.Guild.OwnerId != guildUser.Id && DbGuild.ModRoles.ElementCount == 0) { return(PreconditionResult.FromError("Only the owners of this server may use this command.")); } else if (guildUser.Guild.OwnerId != context.User.Id && DbGuild.ModRoles != null && !guildUser.RoleIds.Any(x => DbGuild.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 (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount == 0) { return(PreconditionResult.FromError("The administrator permission is required to use this command.")); } else if (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount != 0 && !guildUser.RoleIds.Any(x => DbGuild.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 (_moderationService.GetPermLevel(DbGuild, context.User as IGuildUser) == 0) { return(PreconditionResult.FromError("Only a moderator may use this command.")); } break; case Attributes.Nsfw: if (!DbGuild.Nsfw) { return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " + $"`{DbGuild.Prefix}ChangeNSFWSettings` command.")); } var nsfwChannel = await context.Guild.GetChannelAsync(DbGuild.NsfwChannelId); if (nsfwChannel != null && context.Channel.Id != DbGuild.NsfwChannelId) { return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}.")); } break; case Attributes.InGang: if (!await _gangRepo.InGangAsync(guildUser)) { return(PreconditionResult.FromError("You must be in a gang to use this command.")); } break; case Attributes.NoGang: if (await _gangRepo.InGangAsync(guildUser)) { return(PreconditionResult.FromError("You may not use this command while in a gang.")); } break; case Attributes.GangLeader: if ((await _gangRepo.GetGangAsync(guildUser)).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 < Config.JUMP_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.JUMP_REQUIREMENT.USD()}.")); } break; case Attributes.Steal: if (DbUser.Cash < Config.STEAL_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.STEAL_REQUIREMENT.USD()}.")); } break; case Attributes.Rob: if (DbUser.Cash < Config.ROB_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.ROB_REQUIREMENT.USD()}.")); } break; case Attributes.Bully: if (DbUser.Cash < Config.BULLY_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.BULLY_REQUIREMENT.USD()}.")); } break; case Attributes.FiftyX2: if (DbUser.Cash < Config.FIFTYX2_REQUIREMENT) { return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.FIFTYX2_REQUIREMENT.USD()}.")); } break; default: return(PreconditionResult.FromError($"ERROR: The {attribute} attribute is not being handled!")); } } return(PreconditionResult.FromSuccess()); }
public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider serviceProvider) { return(Task.Run(() => { _serviceProvider = serviceProvider; _userRepo = _serviceProvider.GetService <UserRepository>(); _moderationService = _serviceProvider.GetService <ModerationService>(); _gameService = _serviceProvider.GetService <GameService>(); Context deaContext = context as Context; var permLevel = _moderationService.GetPermLevel(deaContext.DbGuild, deaContext.GUser); var invData = _gameService.InventoryData(deaContext.DbUser); foreach (var attribute in _attributes) { switch (attribute) { case Attributes.BotOwner: if (!Data.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 (permLevel != 3) { return PreconditionResult.FromError("Only the owners of this server may use this command."); } break; case Attributes.Admin: if (permLevel < 2) { return PreconditionResult.FromError("The administrator permission is required to use this command."); } break; case Attributes.Moderator: if (permLevel == 0) { return PreconditionResult.FromError("Only a moderator may use this command."); } break; case Attributes.InGang: if (deaContext.Gang == null) { return PreconditionResult.FromError("You must be in a gang to use this command."); } break; case Attributes.NoGang: if (deaContext.Gang != null) { return PreconditionResult.FromError("You may not use this command while in a gang."); } break; case Attributes.GangLeader: if (deaContext.Gang == null || deaContext.Gang.LeaderId != context.User.Id) { return PreconditionResult.FromError("You must be the leader of a gang to use this command."); } break; case Attributes.Jump: if (deaContext.Cash < Config.JumpRequirement) { return PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.JumpRequirement.USD()}."); } break; case Attributes.Steal: if (deaContext.Cash < Config.StealRequirement) { return PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.StealRequirement.USD()}."); } break; case Attributes.Rob: if (deaContext.Cash < Config.RobRequirement) { return PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.RobRequirement.USD()}."); } break; case Attributes.Bully: if (deaContext.Cash < Config.BullyRequirement) { return PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.BullyRequirement.USD()}."); } break; case Attributes.FiftyX2: if (deaContext.Cash < Config.FiftyX2Requirement) { return PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.FiftyX2Requirement.USD()}."); } break; default: return PreconditionResult.FromError($"ERROR: The {attribute} attribute is not being handled!"); } } return PreconditionResult.FromSuccess(); })); }