Discord

Started by DizzasTeR, Mar 05, 2019, 05:39 AM

Previous topic - Next topic

DizzasTeR

This is a discord plugin that I've made just to practice myself over C++ and ofcourse since IRC is a dead meme at this point as well it was cool to have a nice VCMP server-discord communication system.

There is a Read Me file that has instructions and explains the config settings. I'll put the Read Me here as well for quick look:
IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

* Place DDiscord.dll inside your plugins folder
* Place all DLLs in the dll zip file next to server.exe
* Place settings.json next to server.exe and configure as needed
* Enlist DDiscord in your server.cfg

-----------------------------------------------------------------------------------------------------------------------

* Plugin provided events:
- SQ_onDiscordConnect
- SQ_onDiscordServer
- SQ_onDiscordChannelMessage
- SQ_onDiscordQuit
- SQ_onDiscordDisconnect

* Plugin provided functions:
- Discord_SendMessage("Message")
- Discord_SendMesageToChannel(channel_id, "Message")
- Discord_SendMesageToChannelName("Channel-Name", "Message")
- Discord_SetStatus("New Status")

-----------------------------------------------------------------------------------------------------------------------

* Configure settings.json according to your needs, following is explanation for each setting:

- prefix :: The prefix to use for commands, ! means commands start with ! for example: !bot
- token :: This is your bot token
- status :: Sets the status of the bot. Which is the "Currently playing ..." message.

- specialNicks :: If a user has special symbols which VCMP does not support ingame on chat, should these users be allowed to send messages ingame?
- specialMessages :: If a user's message has symbols that VCMP chat does not support, should they be blocked?

- defaultMode :: Toggles defaultMessages, defaultCommands and whether squirrel events are triggered or not.

- defaultMessages :: This plugin has the following events handled inside:
 -> onPlayerJoin
 -> onPlayerPart
 -> onPlayerDeath
 -> onPlayerKill
 -> onPlayerChat

if you want to manually handle these events with your own messages, you can set defaultMode to false and do it inside squirrel events.

- defaultCommands :: The plugin comes with a few built-in commands if defaultMode is ON:
 -> !say - Sends a message from discord to server
 -> !players - Displays the list of players ingame

- channels :: This is an array of channel IDs the plugin will load and send messages to when global messages are sent.

"channels" : [channel_id]

-> channel_id is the id of the channel to load, you can enable Developer Mode on discord, and then right click on channels to get their ID and palce them here.

- Multiple channels can be simply listed by a comma separation:
"channels" : [channel_1_id, channel_2_id]

# Note :: Its fair to just use 1 main channel to send messages to instead of multiple channels at multiple servers to avoid request flood.

This plugin is not the best! I made this personally for myself for very basic tasks like just simply logging out basic player join/quits, chats and kill logs. It was never meant to be very advanced. However I will prefer this any day over the current methods people are using (mysql queries to simulate server messages back and forth, ew!)

This plugin can be as easy as just download, place, config json and you have most of the simple stuff already done and handled, but if you want, you can disable the in-built ones and just do them all yourself squirrel side, both ways can serve.


  • Sample script:
- Functions:
Discord_SendMessage("message"); // Sends a message to all the channels listed in settings.json
Discord_SendMessageToChannel(channel_id, "message"); // Send message to the specific channel
Discord_SendMessageToChannelName("my-channel", "my message"); // Send message to all channels matching this name
Discord_SetStatus("Status"); // Set Bot's game status

- Events:
SQ_onDiscordConnect(string jsonFormattedData)
SQ_onDiscordServer(string jsonFormattedData)
SQ_onDiscordChannelMessage(int serverID, int channelID, int userID, string userName, string message)
SQ_onMemberEdit(string jsonFormattedData, string emptyStringForCompatibility)
SQ_onDiscordQuit()
SQ_onDiscordDisconnect()

- A sample script that implements a custom SQ_onDiscordCommand function/event
function SQ_onDiscordChannelMessage(serverID, channelID, userID, userName, message) {
if(message.slice(0, 1) == "!") {
local noprefixMessage = message.slice(1, message.len());
local str = split(noprefixMessage, " ");
local command = str[0];
local msg = null;
if(str.len() > 1) {
msg = "";
for(local i = 1; i < str.len(); i++) {
msg += str[i];
if(i < str.len()-1)
msg += " ";
}
}
SQ_onDiscordCommand(serverID, channelID, userID, userName, command, msg);
}
}

function SQ_onDiscordCommand(serverID, channelID, userID, username, cmd, msg) {
if(cmd == "t")
Discord_SendMessageToChannel(channelID, "test works");
}


  • Binaries
https://github.com/DizzasTeR/sleepy-discord-vcmp-client/releases

* Do read the release notes to be aware of any important changes to the plugin!

Install OpenSSL for Linux
sudo apt-get install libssl-dev

  • Thanks to
- @Kirollos - I learned how to handle squirrel vm and stacks from his RCON plugin
- @. (SLC) - Ofcourse this bad boy has to be everywhere, no surprise at all
- @Luckshya - Helped me in some API issues and used his CMake files to easily generate binaries for Linux

DizzasTeR

You first have to get your bot connected to your server, you can google search and see how that is done afterwards you take the bot token and place it inside the settings.conf file, run the server and the bot should be getting online.

Mitasubiszi

On linux

Plugin error >> dlopen() 'plugins/DDiscord64.so' failed: plugins/DDiscord64.so: only ET_DYN and ET_EXEC can be loaded
help

AroliS^

a simple guide for making the token and it show how to create a bot to run this plugin - https://github.com/Chikachi/DiscordIntegration/wiki/How-to-get-a-token-and-channel-ID-for-Discord
Lemme love ya

D4rkR420R

#4
Doom_Kill3R, excellent work. :)
Would be great if it can output a message to Discord that the bot disconnected.

DizzasTeR

Hi DarkRazor, I'm working on a better plugin over sleepy-discord library (Because before I had issues getting it to compile but now those are fixed) so I'll probably get that plugin to have more events and functionalities, gotta wait abit though ;)

D4rkR420R

Quote from: Doom_Kill3R on Mar 12, 2019, 05:42 AMHi DarkRazor, I'm working on a better plugin over sleepy-discord library (Because before I had issues getting it to compile but now those are fixed) so I'll probably get that plugin to have more events and functionalities, gotta wait abit though ;)

Thanks man, you're the best! :)

DizzasTeR

  • Update
    • Switched to Sleepy-Discord API
    • Bot status can now be set
    • Configuration file is now more neatly categorized. New format for enlisting channel ids.

Binaries updated on first post, new sample script also updated.
Special thanks to @Luckshya for a great helping hand, first post credits for more information.

D4rkR420R

@Doom_Kill3R , what's the OpenSLL for?

DizzasTeR

It is used for network communication

Mursaleen Qureshi

Can you make this For 32bit servers too ?

NicusorN5

Quote from: Mursaleen Qureshi on Mar 22, 2019, 02:07 AMCan you make this For 32bit servers too ?
Stop using ancient hardware.

DizzasTeR

  • Update
    • Fixed server crash on sending invalid formatted messages
    • Added Discord_SendMessageToChannelName function to send a message to all the server channels with the specified name the bot is connected to

Updated binaries download on first post.

NicusorN5

I gotta say, great work dude!

NicusorN5

Guess what, I need the 32 bit version for a VPS my friend has :/