diff --git a/SCPDiscordPlugin/BotListener.cs b/SCPDiscordPlugin/BotListener.cs index 2b82f74a..41bc6937 100644 --- a/SCPDiscordPlugin/BotListener.cs +++ b/SCPDiscordPlugin/BotListener.cs @@ -51,7 +51,7 @@ public BotListener(SCPDiscord plugin) break; case MessageWrapper.MessageOneofCase.ConsoleCommand: - plugin.sync.ScheduleConsoleCommand(data.ConsoleCommand); + plugin.sync.ScheduleDiscordCommand(data.ConsoleCommand); break; case MessageWrapper.MessageOneofCase.RoleResponse: diff --git a/SCPDiscordPlugin/RoleSync.cs b/SCPDiscordPlugin/RoleSync.cs index 5f0aa4b8..cc2c0605 100644 --- a/SCPDiscordPlugin/RoleSync.cs +++ b/SCPDiscordPlugin/RoleSync.cs @@ -111,7 +111,7 @@ public void ReceiveQueryResponse(string userID, List roleIDs) command = command.Replace("", variable.Value); } plugin.Debug("Running rolesync command: " + command); - plugin.Debug("Command response: " + plugin.ConsoleCommand(null, command.Split(' ')[0], command.Split(' ').Skip(1).ToArray())); + plugin.sync.ScheduleRoleSyncCommand(command); } plugin.Verbose("Synced " + player.Name + " (" + player.UserID + ") with Discord role id " + keyValuePair.Key); diff --git a/SCPDiscordPlugin/SCPDiscord.cs b/SCPDiscordPlugin/SCPDiscord.cs index c1e7047e..2e58c11a 100644 --- a/SCPDiscordPlugin/SCPDiscord.cs +++ b/SCPDiscordPlugin/SCPDiscord.cs @@ -366,29 +366,5 @@ public bool GetPlayerName(string steamID, ref string name) } return false; } - - /// - /// Runs a console command. - /// - /// The user to run the command as, null for the server itself. - /// The name of the command to run. - /// Command arguments split up into individual strings. - /// - public string ConsoleCommand(ICommandSender user, string command, string[] arguments) - { - if (user == null) - { - user = Server; - } - - string[] feedback = plugin.PluginManager.CommandManager.CallCommand(user, command, arguments); - - StringBuilder builder = new StringBuilder(); - foreach (string line in feedback) - { - builder.Append(line + "\n"); - } - return builder.ToString(); - } } } diff --git a/SCPDiscordPlugin/SynchronousExecutor.cs b/SCPDiscordPlugin/SynchronousExecutor.cs index 5154f4eb..75923148 100644 --- a/SCPDiscordPlugin/SynchronousExecutor.cs +++ b/SCPDiscordPlugin/SynchronousExecutor.cs @@ -1,7 +1,9 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Text; using SCPDiscord.Interface; +using Smod2.Commands; using Smod2.EventHandlers; using Smod2.Events; @@ -11,29 +13,57 @@ public class SynchronousExecutor : IEventHandlerFixedUpdate { private readonly SCPDiscord plugin; private readonly ConcurrentQueue queuedCommands = new ConcurrentQueue(); - + private readonly ConcurrentQueue queuedRoleSyncCommands = new ConcurrentQueue(); public SynchronousExecutor(SCPDiscord pl) { plugin = pl; } - - public void ScheduleConsoleCommand(ConsoleCommand command) + + public void ScheduleDiscordCommand(ConsoleCommand command) { queuedCommands.Enqueue(command); } + public void ScheduleRoleSyncCommand(string command) + { + queuedRoleSyncCommands.Enqueue(command); + } + public void OnFixedUpdate(FixedUpdateEvent ev) { while(queuedCommands.TryDequeue(out ConsoleCommand command)) { string[] words = command.Command.Split(' '); - string response = plugin.ConsoleCommand(plugin.PluginManager.Server, words[0], words.Skip(1).ToArray()); + string response = ConsoleCommand(plugin.PluginManager.Server, words[0], words.Skip(1).ToArray()); Dictionary variables = new Dictionary { { "feedback", response } }; plugin.SendMessageByID(command.ChannelID, "botresponses.consolecommandfeedback", variables); } + + while(queuedRoleSyncCommands.TryDequeue(out string stringCommand)) + { + string[] words = stringCommand.Split(' '); + plugin.Debug("RoleSync command response: " + ConsoleCommand(plugin.PluginManager.Server, words[0], words.Skip(1).ToArray())); + } + } + + private string ConsoleCommand(ICommandSender user, string command, string[] arguments) + { + if (user == null) + { + user = plugin.Server; + } + + string[] feedback = plugin.PluginManager.CommandManager.CallCommand(user, command, arguments); + + StringBuilder builder = new StringBuilder(); + foreach (string line in feedback) + { + builder.Append(line + "\n"); + } + return builder.ToString(); } } } \ No newline at end of file