spirit ban, permission checkers, permissions almost done

This commit is contained in:
Master Kwoth
2016-02-12 01:56:55 +01:00
parent c1fb5397ce
commit fdd5824580
11 changed files with 253 additions and 27 deletions

View File

@ -44,6 +44,8 @@ namespace NadekoBot.Modules {
manager.CreateCommands(NadekoBot.botMention, cgb => {
var client = manager.Client;
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand("uptime")

View File

@ -18,6 +18,8 @@ namespace NadekoBot.Modules
{
manager.CreateCommands("", cgb =>
{
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
commands.ForEach(com => com.Init(cgb));
cgb.CreateCommand("$raffle")

View File

@ -28,6 +28,8 @@ namespace NadekoBot.Modules
{
commands.ForEach(cmd => cmd.Init(cgb));
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
cgb.CreateCommand(">choose")
.Description("Chooses a thing from a list of things\n**Usage**: >choose Get up;Sleep more;Sleep even more")
.Parameter("list", Discord.Commands.ParameterType.Unparsed)

View File

@ -28,7 +28,9 @@ namespace NadekoBot.Modules {
var client = NadekoBot.client;
manager.CreateCommands("!m", cgb => {
//queue all more complex commands
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand("n")

View File

@ -16,6 +16,9 @@ namespace NadekoBot.Modules {
public override void Install(ModuleManager manager) {
manager.CreateCommands("", cgb => {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
cgb.CreateCommand("~hentai")
.Description("Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri")
.Parameter("tag", ParameterType.Unparsed)
@ -27,7 +30,7 @@ namespace NadekoBot.Modules {
await e.Send(":heart: Danbooru: " + await SearchHelper.GetDanbooruImageLink(tag));
});
cgb.CreateCommand("~danbooru")
.Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri")
.Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~danbooru yuri")
.Parameter("tag", ParameterType.Unparsed)
.Do(async e => {
string tag = e.GetArg("tag");
@ -36,7 +39,7 @@ namespace NadekoBot.Modules {
await e.Send(await SearchHelper.GetDanbooruImageLink(tag));
});
cgb.CreateCommand("~gelbooru")
.Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri")
.Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~gelbooru yuri")
.Parameter("tag", ParameterType.Unparsed)
.Do(async e => {
string tag = e.GetArg("tag");

View File

@ -8,7 +8,7 @@ using PermsHandler = NadekoBot.Classes.Permissions.PermissionsHandler;
namespace NadekoBot.Modules {
class PermissionModule : DiscordModule
{
string trigger = "*";
string prefix = "*";
public PermissionModule() : base()
{
//Empty for now
@ -21,11 +21,65 @@ namespace NadekoBot.Modules {
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand(trigger + "ssm").Alias(trigger + "setservermodule")
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
cgb.CreateCommand(prefix + "serverperms")
.Description("Shows banned permissions for this server.")
.Do(async e => {
var perms = PermsHandler.GetServerPermissions(e.Server);
if (perms == null)
await e.Send("No permissions set.");
await e.Send(perms.ToString());
});
cgb.CreateCommand(prefix + "roleperms")
.Description("Shows banned permissions for a certain role. No argument means for everyone.")
.Parameter("role", ParameterType.Unparsed)
.Do(async e => {
var arg = e.GetArg("role");
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
var perms = PermsHandler.GetRolePermissionsById(e.Server, role.Id);
if (perms == null)
await e.Send("No permissions set.");
await e.Send(perms.ToString());
});
cgb.CreateCommand(prefix + "channelperms")
.Description("Shows banned permissions for a certain channel. No argument means for this channel.")
.Parameter("channel", ParameterType.Unparsed)
.Do(async e => {
var arg = e.GetArg("channel");
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
var perms = PermsHandler.GetChannelPermissionsById(e.Server, channel.Id);
if (perms == null)
await e.Send("No permissions set.");
await e.Send(perms.ToString());
});
cgb.CreateCommand(prefix + "userperms")
.Description("Shows banned permissions for a certain user. No argument means for yourself.")
.Parameter("user", ParameterType.Unparsed)
.Do(async e => {
var arg = e.GetArg("user");
Discord.User user;
if (string.IsNullOrWhiteSpace(e.GetArg("user")))
user = e.User;
else
user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
var perms = PermsHandler.GetUserPermissionsById(e.Server, user.Id);
if (perms == null)
await e.Send("No permissions set.");
await e.Send(perms.ToString());
});
cgb.CreateCommand(prefix + "sm").Alias(prefix + "servermodule")
.Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Description("Sets a module's permission at the server level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -46,11 +100,10 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "ssc").Alias(trigger + "setservercommand")
cgb.CreateCommand(prefix + "sc").Alias(prefix + "servercommand")
.Parameter("command", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Description("Sets a command's permission at the server level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -71,12 +124,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "srm").Alias(trigger + "setrolemodule")
cgb.CreateCommand(prefix + "rm").Alias(prefix + "rolemodule")
.Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("role", ParameterType.Unparsed)
.Description("Sets a module's permission at the role level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -98,12 +150,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "src").Alias(trigger + "setrolecommand")
cgb.CreateCommand(prefix + "rc").Alias(prefix + "rolecommand")
.Parameter("command", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("role",ParameterType.Unparsed)
.Description("Sets a command's permission at the role level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -125,12 +176,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "scm").Alias(trigger + "setchannelmodule")
cgb.CreateCommand(prefix + "cm").Alias(prefix + "channelmodule")
.Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed)
.Description("Sets a module's permission at the channel level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -152,12 +202,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "scc").Alias(trigger + "setchannelcommand")
cgb.CreateCommand(prefix + "cc").Alias(prefix + "channelcommand")
.Parameter("command", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed)
.Description("Sets a command's permission at the channel level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -179,12 +228,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "sum").Alias(trigger + "setusermodule")
cgb.CreateCommand(prefix + "um").Alias(prefix + "usermodule")
.Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("user", ParameterType.Unparsed)
.Description("Sets a module's permission at the user level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try
@ -206,12 +254,11 @@ namespace NadekoBot.Modules {
}
});
cgb.CreateCommand(trigger + "suc").Alias(trigger + "setusercommand")
cgb.CreateCommand(prefix + "uc").Alias(prefix + "usercommand")
.Parameter("command", ParameterType.Required)
.Parameter("bool", ParameterType.Required)
.Parameter("user", ParameterType.Unparsed)
.Description("Sets a command's permission at the user level.")
// .AddCheck() -> fix this
.Do(async e =>
{
try

View File

@ -21,6 +21,8 @@ namespace NadekoBot.Modules {
manager.CreateCommands("", cgb => {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand("~yt")