From 8f9e4d7e11d1c5bc54c1bdef7ae18081b3c51f65 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 7 Dec 2015 21:20:18 +0100 Subject: [PATCH] A lot of administration stuff, adding more tomorrow .r role-name [role-color(optional)] (creates a new role) .b @User (bans a user) .k @Users (kicks a user) .vch channel_name (creates a new voice channel) .ch channel_name (creates a new text channel) --- NadekoBot/Modules/Administration.cs | 112 ++++++++++++++++++++++++++++ NadekoBot/NadekoBot.cs | 1 + 2 files changed, 113 insertions(+) diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 52c0cfc1..a7a9d89f 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -1,4 +1,5 @@ using Discord.Modules; +using System; using System.Linq; namespace NadekoBot.Modules @@ -17,6 +18,117 @@ namespace NadekoBot.Modules commands.ForEach(cmd => cmd.Init(cgb)); + cgb.CreateCommand(".r").Alias(".role") + .Description("Creates a role with a given name, and color.\n*Both the user and the bot must have the sufficient permissions.*") + .Parameter("role_name",Discord.Commands.ParameterType.Required) + .Parameter("role_color",Discord.Commands.ParameterType.Optional) + .Do(async e => + { + var color = Discord.Color.Blue; + if (e.GetArg("role_color") != null) + { + try + { + if (e.GetArg("role_color") != null && e.GetArg("role_color").Trim().Length > 0) + color = (typeof(Discord.Color)).GetField(e.GetArg("role_color")).GetValue(null) as Discord.Color; + } + catch (Exception ex) + { + System.Console.WriteLine(ex.ToString()); + await client.SendMessage(e.Channel, "Please supply a proper color.\n Example: DarkBlue, Orange, Teal"); + return; + } + } + try + { + if (e.User.ServerPermissions.ManageRoles) + { + var r = await client.CreateRole(e.Server, e.GetArg("role_name")); + await client.EditRole(r, null,null, color); + } + } + catch (Exception) + { + await client.SendMessage(e.Channel, "No sufficient permissions."); + } + return; + }); + + cgb.CreateCommand(".b").Alias(".ban") + .Description("Kicks a mentioned user\n*Both the user and the bot must have the sufficient permissions.*") + .Do(async e => + { + try + { + if (e.User.ServerPermissions.BanMembers && e.Message.MentionedUsers.Any()) + { + var usr = e.Message.MentionedUsers.First(); + await client.BanUser(e.Message.MentionedUsers.First()); + await client.SendMessage(e.Channel, "Banned user " + usr.Name + " Id: " + usr.Id); + } + } + catch (Exception) + { + await client.SendMessage(e.Channel, "No sufficient permissions."); + } + }); + + cgb.CreateCommand(".k").Alias(".kick") + .Parameter("user") + .Description("Kicks a mentioned user.\n*Both the user and the bot must have the sufficient permissions.*") + .Do(async e => + { + try + { + if (e.User.ServerPermissions.KickMembers && e.Message.MentionedUsers.Any()) + { + var usr = e.Message.MentionedUsers.First(); + await client.KickUser(e.Message.MentionedUsers.First()); + await client.SendMessage(e.Channel,"Kicked user " + usr.Name+" Id: "+usr.Id); + } + } + catch (Exception) + { + await client.SendMessage(e.Channel, "No sufficient permissions."); + } + }); + + cgb.CreateCommand(".vch") + .Description("Creates a new voice channel with a given name.\n*Both the user and the bot must have the sufficient permissions.*") + .Parameter("channel_name", Discord.Commands.ParameterType.Required) + .Do(async e => + { + try + { + if (e.User.ServerPermissions.ManageChannels) + { + await client.CreateChannel(e.Server, e.GetArg("channel_name"), Discord.ChannelType.Voice); + } + } + catch (Exception) + { + await client.SendMessage(e.Channel, "No sufficient permissions."); + } + }); + + cgb.CreateCommand(".ch") + .Alias(".tch") + .Description("Creates a new text channel with a given name.\n*Both the user and the bot must have the sufficient permissions.*") + .Parameter("channel_name", Discord.Commands.ParameterType.Required) + .Do(async e => + { + try + { + if (e.User.ServerPermissions.ManageChannels) + { + await client.CreateChannel(e.Server, e.GetArg("channel_name"), Discord.ChannelType.Text); + } + } + catch (Exception) { + await client.SendMessage(e.Channel, "No sufficient permissions."); + } + }); + cgb.CreateCommand(".uid") .Description("Shows user id") .Parameter("user",Discord.Commands.ParameterType.Required) diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index a3d33cab..5533c737 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -21,6 +21,7 @@ namespace NadekoBot { //load credentials from credentials.json Credentials c; + try { c = JsonConvert.DeserializeObject(File.ReadAllText("credentials.json"));