diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-09-22 23:30:19 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-09-22 23:30:19 -0700 |
| commit | f0d76aab62bba2d1d5bec29f4c027ace7dafa8d1 (patch) | |
| tree | 6a40a9fde6785aa7b046cd458ff3644d95b9f371 /DiscordToXIV/Plugin.cs | |
| parent | d05abe1424dfb2d42fc6ff7682d55042021b4cb0 (diff) | |
implement sending discord messages from in-game
Diffstat (limited to 'DiscordToXIV/Plugin.cs')
| -rw-r--r-- | DiscordToXIV/Plugin.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/DiscordToXIV/Plugin.cs b/DiscordToXIV/Plugin.cs index 2e40bba..29c7d6f 100644 --- a/DiscordToXIV/Plugin.cs +++ b/DiscordToXIV/Plugin.cs @@ -33,6 +33,8 @@ public sealed class Plugin : IDalamudPlugin private bool IsWebSocketServerRunning = false; private WebSocketServer webSocketServer; + private DiscordMessenger discordMessenger; + private string selectedChannelID = ""; private readonly CancellationTokenSource cancellationTokenSource; private readonly List<IWebSocketConnection> connectedClients; public Configuration Configuration { get; init; } @@ -50,11 +52,24 @@ public sealed class Plugin : IDalamudPlugin WindowSystem.AddWindow(MainWindow); cancellationTokenSource = new CancellationTokenSource(); connectedClients = new List<IWebSocketConnection>(); + discordMessenger = new DiscordMessenger(this, Configuration.DiscordAuthToken); CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) { HelpMessage = "Start WebSocket server. Usage: /pdiscordtoxiv [port]" }); + + CommandManager.AddHandler("/pdtxset", new CommandInfo(SetChannelCommand) + { + HelpMessage = "Set a channel ID to send messages to. Usage: /pdtxset <channel_id>" + }); + + CommandManager.AddHandler("/pdtxs", new CommandInfo(SendMessageCommand) + { + HelpMessage = "Send a message to the selected channel. Usage: /pdtxs <message>" + }); + + PluginInterface.UiBuilder.Draw += DrawUI; PluginInterface.UiBuilder.OpenConfigUi += ToggleConfigUI; PluginInterface.UiBuilder.OpenMainUi += ToggleMainUI; @@ -112,6 +127,42 @@ public sealed class Plugin : IDalamudPlugin } } + + private void SendMessageCommand(string command, string args) + { + if (string.IsNullOrEmpty(args)) + { + ChatGui.PrintError("[DiscordToXIV] No message provided."); + return; + } + + if (string.IsNullOrEmpty(selectedChannelID)) + { + ChatGui.PrintError("[DiscordToXIV] No channel selected."); + return; + } + + discordMessenger.SendMessageAsync(args, selectedChannelID); + } + + private void SetChannelCommand(string command, string args) + { + if (string.IsNullOrEmpty(args)) + { + ChatGui.PrintError("[DiscordToXIV] No channel ID provided."); + return; + } + + if (Configuration.ChannelMappings.ContainsKey(args)) + { + selectedChannelID = args; + ChatGui.Print("[DiscordToXIV] Channel set to " + Configuration.ChannelMappings[args]); + } + else + { + ChatGui.PrintError("[DiscordToXIV] Channel ID not found in configuration."); + } + } private void StartWebSocketServer(int port) { |
