Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Discord
«  »Last edited
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:
Code: [Select]
IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

* Place libDDiscord64 inside your plugins folder

* Enlist libDDiscord64 in your Server.cfg

* WINDOWS USERS: Place libcurl.dll, LIBEAY32.dll, SSLEAY.dll, zlib1.dll and settings.json inside server directory
* LINUX USERS: Place settings.json inside server directory. If the plugin doesn't load, install SSL; apt-get install libssl-dev

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

* Plugin provided events:
- SQ_onDiscordConnect
- SQ_onDiscordServer
- SQ_onDiscordChannel
- 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?

- 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 this to false and do it inside squirrel events.

- defaultCommands :: The plugin comes with a few built-in commands if this is true:
 -> !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:

* IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

- Functions:
Code: [Select]
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_SetStatus("Status"); // Set Bot's game status

- Events:
Code: [Select]
SQ_onDiscordConnect(string jsonFormattedData)
SQ_onDiscordServer(string jsonFormattedData)
SQ_onDiscordChannel(string jsonFormattedData)
SQ_onDiscordChannelMessage(int serverID, int channelID, int userID, string userName, string message)
SQ_onDiscordQuit()
SQ_onDiscordDisconnect()

- A sample script that implements a custom SQ_onDiscordCommand function/event
Code: [Select]
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

NOTE: Binaries will only be available for x64

- Windows:


Install OpenSSL for Windows

- Linux:


Install OpenSSL for Linux
Code: [Select]
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

Mursaleen5544

  • Newbie
  • Posts: 19
Re: Discord
« Reply #1,  »
Can yOu Make a Video tutorial for that please dude .. Understanding of this is dificult for those whom were waiting for this.

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: Discord
« Reply #2,  »
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

  • Newbie
  • Posts: 4
Re: Discord
« Reply #3,  »
On linux

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

help

AroliS^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 46

DarkRaZoR^

  • Full Member
  • VC:MP Battlefield Head Developer/KF Leader
  • Posts: 208
Re: Discord
« Reply #5,  »Last edited
Doom_Kill3R, excellent work. :)
Would be great if it can output a message to Discord that the bot disconnected.

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: Discord
« Reply #6,  »
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 ;)

DarkRaZoR^

  • Full Member
  • VC:MP Battlefield Head Developer/KF Leader
  • Posts: 208
Re: Discord
« Reply #7,  »
Quote from Doom_Kill3R on March 12th, 05:42 AM
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 ;)
Thanks man, you're the best! :)

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: Discord
« Reply #8,  »
  • 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.

DarkRaZoR^

  • Full Member
  • VC:MP Battlefield Head Developer/KF Leader
  • Posts: 208

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: Discord
« Reply #10,  »
It is used for network communication

Mursaleen Qureshi

  • Newbie
  • Posts: 8
Re: Discord
« Reply #11,  »
Can you make this For 32bit servers too ?

Athanatos

  • Hero Member
  • Romania Cops N Robbers Lead Developer
  • Posts: 796
Re: Discord
« Reply #12,  »
Quote from Mursaleen Qureshi on March 22nd, 02:07 AM
Can you make this For 32bit servers too ?
Stop using ancient hardware.

Doom_Kill3R

  • VC:MP Beta Tester
  • Infinite loops defy infinity by overflowing memory
  • Posts: 1,105
Re: Discord
« Reply #13,  »
  • 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.

Athanatos

  • Hero Member
  • Romania Cops N Robbers Lead Developer
  • Posts: 796
Re: Discord
« Reply #14,  »
I gotta say, great work dude!