This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
discordchat [2019/04/03 10:05] – mochi | discordchat [2019/04/07 05:00] – mochi | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Discord Chat ====== | ====== Discord Chat ====== | ||
- | This add-on | + | This addon will send in-game chat to a discord channel. It will also take any messages (and commands) sent in that same discord channel and send it in-game. |
As an example, imagine if someone talks to you on your linkshell 3. You can see the chat in Discord on your phone, and you can reply to them in the in-game linkshell with: | As an example, imagine if someone talks to you on your linkshell 3. You can see the chat in Discord on your phone, and you can reply to them in the in-game linkshell with: | ||
+ | < | ||
!l3 Hello. | !l3 Hello. | ||
+ | </ | ||
- | ====== Discord Bot Setup ====== | + | Anything you message in Discord that starts with //!// will be processed as a FF14 chatbox input. //!l3 Hello// becomes ///l3 Hello// |
- | Discord bot setup instructions | + | |
+ | === Important Notes === | ||
+ | * There may be up to a 2 second delay in sending messages from FF14 to Discord, and up to a 4 second delay in sending messages from Discord to FF14. | ||
+ | * Please follow all these instructions to set up the addon. **You can do all these setup steps without buying/ | ||
+ | * Auto-Translate phrases are not sent. | ||
+ | * [[http:// | ||
+ | ---- | ||
+ | {{:: | ||
+ | ---- | ||
+ | |||
+ | ====== Opening the Discord Chat Addon Window ====== | ||
+ | The Discord Chat Plug-in window is under the FFXIVMinion menu. | ||
+ | ---- | ||
+ | {{: | ||
+ | |||
+ | ====== Creating a Discord Server and Channel ====== | ||
+ | You will likely want a private server for this plug-in, for your own privacy. | ||
+ | |||
+ | - See [[https:// | ||
+ | - Optionally, create a separate channel for your bot to use. | ||
+ | - Get the channel ID of the channel you'd like to use. | ||
+ | - In Discord, open your //User Settings//. Under // | ||
+ | - Right-click on the Discord text channel you would like to use, and press //Copy ID//. This will copy the channel ID to your clipboard. | ||
+ | - Paste the ID into MMOMinion' | ||
+ | |||
+ | {{:: | ||
+ | |||
+ | ====== Creating a Bot and Receiving a Token ===== | ||
+ | - Create a bot starting [[https:// | ||
+ | - Log in and click //New Application// | ||
+ | - Choose anything you want a name. Something like //FF14 Chatbot// is appropriate. | ||
+ | - On the left side, under // | ||
+ | - Under // | ||
+ | - Optionally, configure your bot's username here. | ||
+ | - Under //Token//, click //Copy// to copy the token to your clipboard. | ||
+ | - Paste the bot token into the //Discord | ||
+ | - On the left side, go to //OAuth2//. Scroll down to //Scopes// and check //bot//. | ||
+ | - Scroll down to //Bot Permissions// | ||
+ | - Copy the URL under the checkboxes in //Scopes// and visit the URL in your clipboard. | ||
+ | - Log-in to discord and authorize the bot to join your server. | ||
+ | - Activate the bot token, in the next section. | ||
+ | |||
+ | {{:: | ||
+ | |||
+ | ====== Activating the Bot Token ====== | ||
+ | Each bot token needs to be activated once it's created, before it can be used by the //Discord Chat// addon. This only needs to be done once. This is to allow the token to send messages to the server, and the activation form below only sends your token to Discord. | ||
+ | |||
+ | Paste the token into the form below, then hit // | ||
+ | < | ||
+ | < | ||
+ | function activateToken(token) { | ||
+ | var activated = false; | ||
+ | var connection = new WebSocket( | ||
+ | " | ||
+ | connection.onopen = function() { | ||
+ | connection.send(JSON.stringify({ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | })); | ||
+ | } | ||
+ | connection.onmessage = function(evt) { | ||
+ | response = JSON.parse(evt.data); | ||
+ | if (response[" | ||
+ | activated = true; | ||
+ | setResponse(" | ||
+ | } | ||
+ | } | ||
+ | connection.onclose = function(evt) { | ||
+ | if (!activated) { | ||
+ | setResponse(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | function setResponse(response) { | ||
+ | document.getElementById(" | ||
+ | } | ||
+ | function clearResponse() { | ||
+ | setResponse("" | ||
+ | } | ||
+ | function activateButton() { | ||
+ | var token = document.getElementById(" | ||
+ | activateToken(token); | ||
+ | } | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | <input type=" | ||
+ | <button onclick=" | ||
+ | </ | ||
+ | <div id=" | ||
+ | </ | ||
+ | |||
+ | ====== Configuring the Bot ====== | ||
+ | Under // | ||
+ | |||
+ | Under // | ||
+ | |||
+ | * **Autostart**: | ||
+ | * **Command Prefix**: Defaulted to //!//. The prefix to commands the bot will listen to. | ||
+ | * **Timestamp Format**: Defaulted to //%H:%M//. The format of the timestamp sent to discord for in-game messages. | ||
+ | * **Send Channel Name**: Defaulted to //on//. Sends the name of the channel to discord for in-game messages. | ||
+ | * **Receive From Discord**: Defaulted to //on//. Listens for messages in the discord channel. | ||
+ | * **Send To Discord**: Defaulted to //on//. Sends messages from in-game to the discord channel. | ||
+ | * **Logging Level**: Defaulted to //0//. Increasing this will show more debug statements in console. | ||
+ | |||
+ | When an external addon registers itself with // | ||
+ | |||
+ | ====== Public API for Other Addons ====== | ||
+ | Other plugins can send messages and listen for messages through a public API. With // | ||
+ | |||
+ | Here's an example addon that sends and listens for commands. | ||
+ | <code lua> | ||
+ | -- Discord chat API example. | ||
+ | -- | ||
+ | -- Look for a global discord_chat_api variable. | ||
+ | -- discord_chat_api.Register(Plugin Name, Command Prefix, Command Callback) | ||
+ | -- returns a function, SendMessage(message) | ||
+ | -- | ||
+ | -- SendMessage will let you send a message through the bot | ||
+ | -- Command Callback is a single argument function that takes a message whenever | ||
+ | -- a discord message is sent with the prefix | ||
+ | -- | ||
+ | -- Note that there is currently a ~5 second delay in receiving messages | ||
+ | -- and a ~2 second delay in sending | ||
+ | |||
+ | local test_discord_plugin = {} | ||
+ | test_discord_plugin.gui_open = true | ||
+ | test_discord_plugin.received = {} | ||
+ | |||
+ | function test_discord_plugin.ModuleInit() | ||
+ | -- Menu item | ||
+ | ml_gui.ui_mgr: | ||
+ | id = " | ||
+ | onClick = function() | ||
+ | test_discord_plugin.gui_open = not test_discord_plugin.gui_open | ||
+ | end}, | ||
+ | " | ||
+ | |||
+ | -- Register with discord chat | ||
+ | if discord_chat_api ~= nil then | ||
+ | test_discord_plugin.SendMessage = discord_chat_api.Register( | ||
+ | "test discord plugin", | ||
+ | else | ||
+ | test_discord_plugin.SendMessage = function(message) | ||
+ | d(" | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function test_discord_plugin.ProcessMessage(message) | ||
+ | d(" | ||
+ | d(message) | ||
+ | table.insert(test_discord_plugin.received, | ||
+ | end | ||
+ | |||
+ | function test_discord_plugin.Draw(event, | ||
+ | if test_discord_plugin.gui_open then | ||
+ | GUI: | ||
+ | test_discord_plugin.visible, | ||
+ | "Test Discord Chat", test_discord_plugin.gui_open) | ||
+ | if test_discord_plugin.visible then | ||
+ | local pushed = GUI: | ||
+ | if pushed then | ||
+ | test_discord_plugin.SendMessage(" | ||
+ | end | ||
+ | for _, recv in pairs(test_discord_plugin.received) do | ||
+ | GUI: | ||
+ | end | ||
+ | end | ||
+ | GUI:End() | ||
+ | end | ||
+ | end | ||
+ | |||
+ | RegisterEventHandler(" | ||
+ | RegisterEventHandler(" | ||
+ | </ | ||
+ | |||
+ | The message passed into your registered callback looks something like this: | ||
+ | <code lua> | ||
+ | { | ||
+ | attachments = | ||
+ | { | ||
+ | }, | ||
+ | author = | ||
+ | { | ||
+ | avatar = " | ||
+ | discriminator = " | ||
+ | id = " | ||
+ | username = " | ||
+ | }, | ||
+ | channel_id = " | ||
+ | content = "!test message", | ||
+ | embeds = | ||
+ | { | ||
+ | }, | ||
+ | id = " | ||
+ | mention_everyone = false, | ||
+ | mention_roles = | ||
+ | { | ||
+ | }, | ||
+ | mentions = | ||
+ | { | ||
+ | }, | ||
+ | pinned = false, | ||
+ | timestamp = " | ||
+ | tts = false, | ||
+ | type = 0, | ||
+ | } | ||
+ | |||
+ | </ |