From 5fbab6f118c68706b691039f4fc92f753aac8ffe Mon Sep 17 00:00:00 2001 From: Madpeter Date: Sun, 26 Apr 2020 02:23:05 +0100 Subject: [PATCH] adds support to access caller from within the commands lib --- Core/Commands/commandlib.cs | 18 ++++++++++++------ Core/bottypes/CommandsBot.cs | 8 ++++---- Core/bottypes/DiscordBot.cs | 6 +++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Core/Commands/commandlib.cs b/Core/Commands/commandlib.cs index 7887272..5385001 100644 --- a/Core/Commands/commandlib.cs +++ b/Core/Commands/commandlib.cs @@ -202,16 +202,16 @@ namespace BSB.Commands protected List suppress_warnings = new List(); public bool Call(string command) { - return Call(command, ""); + return Call(command, "",UUID.Zero); } - protected bool CallCommand(string command, string arg) + protected bool CallCommand(string command, string arg, UUID caller) { command = command.ToLowerInvariant(); CoreCommand cmd = (CoreCommand)GetCommand(command); if (cmd != null) { - cmd.Setup(bot); + cmd.Setup(bot, caller); if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true)) { string[] args = arg.Split(new string[] { "~#~" }, StringSplitOptions.None); @@ -255,9 +255,9 @@ namespace BSB.Commands } } - public bool Call(string command, string arg) + public bool Call(string command, string arg,UUID caller) { - bool result = CallCommand(command, arg); + bool result = CallCommand(command, arg, caller); bot.CommandHistoryAdd(command, arg, result); return result; } @@ -265,9 +265,15 @@ namespace BSB.Commands public abstract class CoreCommand : API_interface { protected CommandsBot bot = null; - public void Setup(CommandsBot setBot) + + /// + /// The UUID of the object/Avatar that called this function, you should still test if its not UUID zero and is a avatar + /// + protected UUID caller = UUID.Zero; + public void Setup(CommandsBot setBot,UUID setCaller) { bot = setBot; + caller = setCaller; } public virtual void Callback(string[] args, EventArgs e,bool status) { diff --git a/Core/bottypes/CommandsBot.cs b/Core/bottypes/CommandsBot.cs index 2d681d1..87cefea 100644 --- a/Core/bottypes/CommandsBot.cs +++ b/Core/bottypes/CommandsBot.cs @@ -96,9 +96,9 @@ namespace BSB.bottypes } } - protected virtual void CallCommandLib(string command, string arg) + protected virtual void CallCommandLib(string command, string arg, UUID caller) { - CommandsInterface.Call(command, arg); + CommandsInterface.Call(command, arg, caller); } protected override void AfterBotLoginHandler() @@ -120,12 +120,12 @@ namespace BSB.bottypes string hashcheck = helpers.GetSHA1(raw); if (hashcheck == signing_code) { - CallCommandLib(command, arg); + CallCommandLib(command, arg, fromUUID); } } else if (from_master == true) { - CallCommandLib(command, arg); + CallCommandLib(command, arg, fromUUID); } } } diff --git a/Core/bottypes/DiscordBot.cs b/Core/bottypes/DiscordBot.cs index 5238fa9..11a5bba 100644 --- a/Core/bottypes/DiscordBot.cs +++ b/Core/bottypes/DiscordBot.cs @@ -424,7 +424,7 @@ namespace BSB.bottypes bool status = false; if (bits.Length == 2) { - status = CommandsInterface.Call(command, bits[1]); + status = CommandsInterface.Call(command, bits[1],UUID.Zero); } else { @@ -500,11 +500,11 @@ namespace BSB.bottypes } Noticetitle = Noticetitle.Replace("!notice ", ""); Noticetitle = Noticetitle.Trim(); - CommandsInterface.Call("GroupNotice", ""+ group.ToString()+"~#~" + Noticetitle + "~#~" + Noticemessage); + CommandsInterface.Call("GroupNotice", ""+ group.ToString()+"~#~" + Noticetitle + "~#~" + Noticemessage,UUID.Zero); } else { - CommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + "[" + message.Author.Username + "]->" + message.Content); + CommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + "[" + message.Author.Username + "]->" + message.Content, UUID.Zero); } await message.DeleteAsync(); }