Added PermissionHelper.cs, Permissons.cs, changed project requirmenets, and added PermissionModule() to main cs file.
This commit is contained in:
parent
358d8a86a1
commit
8c6fd79fee
44
NadekoBot/Classes/PermissionHelper.cs
Normal file
44
NadekoBot/Classes/PermissionHelper.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace NadekoBot.Classes
|
||||
{
|
||||
static class PermissionHelper
|
||||
{
|
||||
public static bool ValidateBool(string passedArg)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passedArg.Trim()))
|
||||
{
|
||||
throw new System.ArgumentException("No value supplied! Missing argument");
|
||||
}
|
||||
switch (passedArg.ToLower())
|
||||
{
|
||||
case "t":
|
||||
case "true":
|
||||
case "enabled":
|
||||
return true;
|
||||
case "f":
|
||||
case "false":
|
||||
case "disabled":
|
||||
return false;
|
||||
default:
|
||||
throw new System.ArgumentException("Did not receive a valid boolean value");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ValidateModule(string v)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
internal static void ValidateCommand(string v)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
226
NadekoBot/Modules/Permissions.cs
Normal file
226
NadekoBot/Modules/Permissions.cs
Normal file
@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Modules;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Classes.PermissionCheckers;
|
||||
using NadekoBot.Classes;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
{
|
||||
class PermissionModule : DiscordModule
|
||||
{
|
||||
string trigger = "*";
|
||||
public PermissionModule() : base()
|
||||
{
|
||||
//Empty for now
|
||||
}
|
||||
|
||||
public override void Install(ModuleManager manager)
|
||||
{
|
||||
var client = NadekoBot.client;
|
||||
manager.CreateCommands("", cgb => {
|
||||
|
||||
commands.ForEach(cmd => cmd.Init(cgb));
|
||||
|
||||
cgb.CreateCommand(trigger + "ssm").Alias(trigger + "setservermodule")
|
||||
.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
|
||||
{
|
||||
PermissionHelper.ValidateModule(e.GetArg("module"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("module") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "ssc").Alias(trigger + "setservercommand")
|
||||
.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
|
||||
{
|
||||
PermissionHelper.ValidateCommand(e.GetArg("command"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("command") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "srm").Alias(trigger + "setrollmodule")
|
||||
.Parameter("module", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a module's permission at the roll level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateModule(e.GetArg("module"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("module") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "src").Alias(trigger + "setrollcommand")
|
||||
.Parameter("command", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a command's permission at the roll level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateCommand(e.GetArg("command"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("command") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "scm").Alias(trigger + "setchannelmodule")
|
||||
.Parameter("module", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a module's permission at the channel level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateModule(e.GetArg("module"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("module") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "scc").Alias(trigger + "setchannelcommand")
|
||||
.Parameter("command", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a command's permission at the channel level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateCommand(e.GetArg("command"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("command") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "sum").Alias(trigger + "setusermodule")
|
||||
.Parameter("module", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a module's permission at the user level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateModule(e.GetArg("module"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("module") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand(trigger + "suc").Alias(trigger + "setuserchannel")
|
||||
.Parameter("command", ParameterType.Required)
|
||||
.Parameter("bool", ParameterType.Required)
|
||||
.Description("Sets a command's permission at the user level.")
|
||||
// .AddCheck() -> fix this
|
||||
.Do(async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PermissionHelper.ValidateModule(e.GetArg("command"));
|
||||
bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
|
||||
|
||||
await e.Send("I'm setting " + e.GetArg("command") + " to " + state);
|
||||
}
|
||||
catch (ArgumentException exArg)
|
||||
{
|
||||
await e.Send(exArg.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await e.Send("Something went terribly wrong - " + ex.Message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@ namespace NadekoBot {
|
||||
|
||||
//install modules
|
||||
modules.Add(new Administration(), "Administration", ModuleFilter.None);
|
||||
modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
|
||||
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
|
||||
modules.Add(new Gambling(), "Gambling", ModuleFilter.None);
|
||||
modules.Add(new Games(), "Games", ModuleFilter.None);
|
||||
|
Loading…
Reference in New Issue
Block a user