public async Task ChnlCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] ITextChannel chnl) { await _service.AddPermissions(Context.Guild.Id, new Permissionv2 { PrimaryTarget = PrimaryPermissionType.Channel, PrimaryTargetId = chnl.Id, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Name.ToLowerInvariant(), State = action.Value, }); if (action.Value) { await ReplyConfirmLocalized("cx_enable", Format.Code(command.Name), GetText("of_command"), Format.Code(chnl.Name)).ConfigureAwait(false); } else { await ReplyConfirmLocalized("cx_disable", Format.Code(command.Name), GetText("of_command"), Format.Code(chnl.Name)).ConfigureAwait(false); } }
public async Task UsrCmd(CommandOrCrInfo command, PermissionAction action, [Leftover] IGuildUser user) { await _service.AddPermissions(ctx.Guild.Id, new Permissionv2 { PrimaryTarget = PrimaryPermissionType.User, PrimaryTargetId = user.Id, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Name.ToLowerInvariant(), State = action.Value, IsCustomCommand = command.IsCustom, }).ConfigureAwait(false); if (action.Value) { await ReplyConfirmLocalizedAsync("ux_enable", Format.Code(command.Name), GetText("of_command"), Format.Code(user.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("ux_disable", Format.Code(command.Name), GetText("of_command"), Format.Code(user.ToString())).ConfigureAwait(false); } }
public async Task RoleCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IRole role) { if (role == role.Guild.EveryoneRole) { return; } await _service.AddPermissions(Context.Guild.Id, new Permissionv2 { PrimaryTarget = PrimaryPermissionType.Role, PrimaryTargetId = role.Id, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Name.ToLowerInvariant(), State = action.Value, }); if (action.Value) { await ReplyConfirmLocalized("rx_enable", Format.Code(command.Name), GetText("of_command"), Format.Code(role.Name)).ConfigureAwait(false); } else { await ReplyConfirmLocalized("rx_disable", Format.Code(command.Name), GetText("of_command"), Format.Code(role.Name)).ConfigureAwait(false); } }
public async Task SrvrCmd(CommandOrCrInfo command, PermissionAction action) { await _service.AddPermissions(Context.Guild.Id, new Permissionv2 { PrimaryTarget = PrimaryPermissionType.Server, PrimaryTargetId = 0, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Name.ToLowerInvariant(), State = action.Value, IsCustomCommand = command.IsCustom, }).ConfigureAwait(false); if (action.Value) { await ReplyConfirmLocalized("sx_enable", Format.Code(command.Name), GetText("of_command")).ConfigureAwait(false); } else { await ReplyConfirmLocalized("sx_disable", Format.Code(command.Name), GetText("of_command")).ConfigureAwait(false); } }
public async Task Gcmd(CommandOrCrInfo cmd) { var commandName = cmd.Name.ToLowerInvariant(); if (_service.BlockedCommands.Add(commandName)) { using (var uow = _db.UnitOfWork) { var bc = uow.BotConfig.GetOrCreate(); bc.BlockedCommands.Add(new BlockedCmdOrMdl { Name = commandName, }); uow.Complete(); } await ReplyConfirmLocalized("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } else if (_service.BlockedCommands.TryRemove(commandName)) { using (var uow = _db.UnitOfWork) { var bc = uow.BotConfig.GetOrCreate(); bc.BlockedCommands.RemoveWhere(x => x.Name == commandName); uow.Complete(); } await ReplyConfirmLocalized("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } }
public async Task CmdCooldown(CommandOrCrInfo command, int secs) { var channel = (ITextChannel)ctx.Channel; if (secs < 0 || secs > 3600) { await ReplyErrorLocalizedAsync("invalid_second_param_between", 0, 3600).ConfigureAwait(false); return; } var name = command.Name.ToLowerInvariant(); using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigs.ForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns)); var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CommandCooldown>()); var toDelete = config.CommandCooldowns.FirstOrDefault(cc => cc.CommandName == name); if (toDelete != null) { uow._context.Set <CommandCooldown>().Remove(toDelete); } localSet.RemoveWhere(cc => cc.CommandName == name); if (secs != 0) { var cc = new CommandCooldown() { CommandName = name, Seconds = secs, }; config.CommandCooldowns.Add(cc); localSet.Add(cc); } await uow.SaveChangesAsync(); } if (secs == 0) { var activeCds = ActiveCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <ActiveCooldown>()); activeCds.RemoveWhere(ac => ac.Command == name); await ReplyConfirmLocalizedAsync("cmdcd_cleared", Format.Bold(name)).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("cmdcd_add", Format.Bold(name), Format.Bold(secs.ToString())).ConfigureAwait(false); } }
public async Task GlobalCommand(CommandOrCrInfo cmd) { var commandName = cmd.Name.ToLowerInvariant(); var added = _service.ToggleCommand(commandName); if (added) { await ReplyConfirmLocalizedAsync("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } await ReplyConfirmLocalizedAsync("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false); }
public async Task DiscordPermOverride(CommandOrCrInfo cmd, params GuildPerm[] perms) { if (perms is null || perms.Length == 0) { await _service.RemoveOverride(ctx.Guild.Id, cmd.Name); await ReplyConfirmLocalizedAsync("perm_override_reset"); return; } var aggregatePerms = perms.Aggregate((acc, seed) => seed | acc); await _service.AddOverride(Context.Guild.Id, cmd.Name, aggregatePerms); await ReplyConfirmLocalizedAsync("perm_override", Format.Bold(aggregatePerms.ToString()), Format.Code(cmd.Name)); }
public async Task Gcmd(CommandOrCrInfo cmd) { var commandName = cmd.Name.ToLowerInvariant(); if (_service.BlockedCommands.Add(commandName)) { using (var uow = _db.UnitOfWork) { var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.BlockedCommands)); bc.BlockedCommands.Add(new BlockedCmdOrMdl { Name = commandName, }); uow.Complete(); } await ReplyConfirmLocalized("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } else if (_service.BlockedCommands.TryRemove(commandName)) { using (var uow = _db.UnitOfWork) { var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.BlockedCommands)); var obj = bc.BlockedCommands.FirstOrDefault(x => x.Name == commandName); if (obj != null) { uow._context.Set <BlockedCmdOrMdl>().Remove(obj); } uow.Complete(); } await ReplyConfirmLocalized("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } }
public async Task Gcmd(CommandOrCrInfo cmd) { var commandName = cmd.Name.ToLowerInvariant(); if (_service.BlockedCommands.Add(commandName)) { using (var uow = _db.GetDbContext()) { var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.BlockedCommands)); bc.BlockedCommands.Add(new BlockedCmdOrMdl { Name = commandName, }); uow.SaveChanges(); } await ReplyConfirmLocalizedAsync("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } else if (_service.BlockedCommands.TryRemove(commandName)) { using (var uow = _db.GetDbContext()) { var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.BlockedCommands)); var objs = bc.BlockedCommands.Where(x => x.Name == commandName); if (objs.Any()) { uow._context.RemoveRange(objs.ToArray()); } uow.SaveChanges(); } await ReplyConfirmLocalizedAsync("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false); return; } }