Jump to content

Yoshi_E

[DiscordBot] BEC RCon Discord bot (Python)

Recommended Posts

Discord Bot
Github: https://github.com/Yoshi-E/ArmaRconDiscordBot

 

The Discord module currently support these commands:

Current features:

  • addBan Ban offline player
  • admins lists current admins on the server
  • banPlayer Ban online player
  • changePassword Changes the RCon password
  • command Sends a custom command to the server
  • getBEServerVersion Gets the current version of the BE server
  • getBans Lists most recent bans
  • getChat Sends a custom command to the server
  • getMissions Gets a list of all Missions
  • goVote Users can vote for the mission selection.
  • kickPlayer Kicks a player who is currently on the server
  • loadBans (Re)load the BE ban list from bans.txt
  • loadMission Loads a mission
  • loadScripts Loads the 'scripts.txt' file without the need to restart...
  • loadEvents Loads Events 
  • lock Locks the server. No one will be able to join
  • maxPing Changes the MaxPing value. 
  • monitords Shows performance information in the dedicated server console. Interval 0 means to stop monitoring.
  • players lists current players on the server
  • reassign Shuts down the server after mission ends
  • removeBan Removes a ban 
  • restart Restart mission with current player slot selection
  • restartM Shuts down and restarts the server after mission ends
  • restartServer Shuts down and restarts the server immediately
  • say Sends a global message
  • sayPlayer Sends a message to a specific player
  • shutdown Shutdowns the Server
  • shutdownM Shuts down the server after mission ends
  • unlock Unlocks the Server

Special commands:

  • status Current connection status
  • debug Toggles RCon debug mode
  • getChat Returns most recent chat messages
  • checkAFK Checks if a player is AFK by testing if he responds in chat.
  • players+ Lists all players with their Flag and BEID
  • addKeyWord Add a keyword to triggers a DM to you. (Use „\_“ as space)
  • removeKeyWord Removes a keyword
  • listKeyWords Lists all your keywords
  • setNotification Mute the bot, or tell him to send those messages only when you are online.
  • streamChat streams all messages from the arma 3 server into the channel where you used the command. (Is persistent)
  • stopStream Stops the stream
  • start Starts the arma Server Binary
  • stop Stops the arma Server (only works on Windows for now)

 

Additional features are:

  • Easy setup using a web-based settings menu
  • Discord: Notification on configurable keywords
  • User database for username, BEID, IP and last-seen
    • The EPM Rcon database can be imported
  • Automatic warning if users with possible multiple accounts are attempting to connect
  • Display the current player count in the status of the bot.
  • Announce when a joins or leaves the server
  • Announce new bans

 

Works on all platforms! (Windows, Linux, MacOSX)

License: https://creativecommons.org/licenses/by-nc-sa/4.0/

 

How it looks in Discord:

P0JvSqf.png

 

 

 

API Used:

  Reveal hidden contents

 

  • Like 6
  • Thanks 1

Share this post


Link to post
Share on other sites

The API now comes as a package! Version 0.1.0 has been released!
You can directly install it with:

pip install git+https://github.com/Yoshi-E/Python-BEC-RCon.git

Then simply import it with

  Quote

 

import bec_rcon

rcon_client = bec_rcon.ARC("192.168.0.1", "MyPassword", 2302)

 

 

Many new commands have been added, together with some additional tweaks.
Added detailed documentation on the API.

  • Thanks 1

Share this post


Link to post
Share on other sites

This would be great to have at least the same functionality like in a Zupa Bot https://bot.devzupa.be/ (this current link just an example. Web version of a bot not working now. Just a standalone version.) For me - my favorite feature is to see the country flag of a player.

This is a commands list https://bot.devzupa.be/commands

Share this post


Link to post
Share on other sites
  On 6/24/2019 at 9:33 AM, varrkan_ua said:

This would be great to have at least the same functionality like in a Zupa Bot

Other than the player+ (wich is now added) all commands and many more are supported.

 

 

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

 

bec_rcon API has been updated to 0.1.1 (fixed loadMission)

Update with:

pip install git+https://github.com/Yoshi-E/Python-BEC-RCon.git -U

Discord module has been updated:

  • getChat Returns most recent chat messages
  • checkAFK Checks if a player is AFK by testing if he responds in chat, does he not, he gets kicked
  • players+ Lists all players with their Flag and BEID
  • loadEvents Loads Events 

  • Like 3

Share this post


Link to post
Share on other sites

is it possible to start a server with this bot?

Share this post


Link to post
Share on other sites
  On 7/22/2019 at 7:37 PM, SantoJ said:

is it possible to start a server with this bot?

no. But could be added if you run the python script on your server.

Share this post


Link to post
Share on other sites
  On 7/24/2019 at 9:10 AM, Dedmen said:

no. But could be added if you run the python script on your server.

I already figured out a simple solution for his problem on Discord with him.

https://pastebin.com/i4nhrnLB

the same commands are also in the main bot too.

 

 

 


The discord bot is now a proper standalone Discord bot, rather than just a Cogs module.

Improved code structure.

 

Added new commands:

Get a notification when a player types specific keywords on the server:

addKeyWord Add a keyword to triggers a DM to you. (Use „\_“ as space)

removeKeyWord Removes a keyword

listKeyWords Lists all your keywords

setNotification Mute the bot, or tell him to send those messages only when you are online.

 

streamChat streams all messages from the arma 3 server into the channel where you used the command. (Is persistent)

stopStream Stops the stream

 

The following commands are disabled until configured:

start Starts the arma Server Binary

stop Stops the arma Server (only works on Windows for now)

 

In the Core Module you can also configure the channels the bots listens to now. Useful if you have multiple instances of the same bot.

  • Like 2

Share this post


Link to post
Share on other sites

please update packages !!!!!!!

python3.6 ((((((

many mistakes

  Reveal hidden contents

Share this post


Link to post
Share on other sites

@VitalyTurboVaz packages updated

 

Rcon Module (0.1.6):

  • Bugs fixes
  • Added UTF-8 Support

Discord Module:

  • Updated requirements
  • Bug fixes
  • Added UTF-8 Support
  • Added "rcon_custom" module (inactive by default): Posts a message whenever a user was banned / unbanned.
  • Like 1

Share this post


Link to post
Share on other sites

OS Windows Server Standart 2019

 

Install Python3.6+ --->>>>Install python-3.6.8-amd64.exe

Clone the git https://github.com/Yoshi-E/ArmaRconDiscordBot.git

Run pip install -r requirements.txt to install required modules

Run the bot.py once, it will quickly terminate itself, as you still have to configure some settings:

Configure the bot: The files are created upon the first launch

In /modules/core/config.json you have to enter a Discord Bot Token

In /modules/core/permissions.json you can setup the permissions for the bot. (WIP)

In /modules/rcon/rcon_cfg.json you have to enter your Battleye RCon details. Read more about it here: Battleye Rcon.

Now you should be good to go! Just start the bot.py!

 

  Reveal hidden contents

 

Share this post


Link to post
Share on other sites
  On 4/19/2020 at 7:38 PM, VitalyTurboVaz said:

  obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 7 column 25 (char 153)

 

You cant use "\" in the config file, python / json doesnt like it. Replace all of them with "/".

So e.g. instead of "D:\Server\arma\Arma3server_x64" write  "D:/Server/arma/Arma3server_x64" 

 

If you need further troubleshoot, we can write on discord (https://discordapp.com/invite/YhBUUSr) or here in Forum DM.

  • Like 1

Share this post


Link to post
Share on other sites

this also works!!!!

rcon_cfg.json ---->>>>>

"start_server": "'C:\\Games\\ArmA3\\A3Master\\arma3server_x64.exe'

Question.

give commands !monitords 15

the bot answers ----->>>> Restart the mission with new player slot selection

I do not see server performance

in the log (A3Master.log ---->>>

 

 

// GLOBAL SETTINGS
hostname            = "name server";
password             = "";
passwordAdmin          = "****************";
serverCommandPassword = "***********";
logFile                = "A3Master.log";
verifySignatures       = 2;
BattlEye            = 1;                  )

 

of the recording server there is---->>>

16:29:30 Player y**** disconnected.
16:29:30 BattlEye Server: Player #12 y**** disconnected
16:32:12 Server load: FPS 30, memory used: 1683 MB, out: 1608 Kbps, in: 156 Kbps, NG:0, G:512, BE-NG:0, BE-G:0, Players: 9 (L:0, R:0, B:0, G:9, D:0)
16:32:27 Server load: FPS 32, memory used: 1683 MB, out: 1070 Kbps, in: 72 Kbps, NG:0, G:0, BE-NG:0, BE-G:0, Players: 9 (L:0, R:0, B:0, G:9, D:0)
16:32:42 Server load: FPS 37, memory used: 1685 MB, out: 1008 Kbps, in: 89 Kbps, NG:0, G:520, BE-NG:0, BE-G:0, Players: 9 (L:0, R:0, B:0, G:9, D:0)
16:32:57 Server load: FPS 39, memory used: 1689 MB, out: 936 Kbps, in: 81 Kbps, NG:0, G:0, BE-NG:0, BE-G:0, Players: 9 (L:0, R:0, B:0, G:9, D:0)

 

how to make output data to a discord channel from the log?

Share this post


Link to post
Share on other sites
  On 4/30/2020 at 8:58 PM, VitalyTurboVaz said:

how to make output data to a discord channel from the log?

 

The command "monitords" does this now by default (displays the performance for the next 5 seconds)

Share this post


Link to post
Share on other sites

Two problems that I did not solve.

1. The output of the server performance to the text channel discord.

I give the command to the bot:

!monitords 15

Bot is responsible:

Restart the mission with new player slot selection

 

2. Ban players.


On the first question, I wanted to ask what log the bot parses.

On the second question - >>>

I give the command to the bot
!help banplayer
Bot is responsible
![banPlayer|banplayer] <player_id> [time=0] [message...]
I give the command to the bot
!addBan 76561198***7183** time=60
Bot is responsible
banPlayer has caused the following error:
Converting to "int" failed for parameter "time".

 

PS There was a problem with the certificate. Unexpectedly, after several weeks of work.

https://gist.github.com/marschhuynh/31c9375fc34a3e20c2d3b9eb8131d8f3

 

 

Share this post


Link to post
Share on other sites
  On 5/24/2020 at 4:20 PM, VitalyTurboVaz said:

1. The output of the server performance to the text channel discord

Make sure you are using the latest version (from today).

with "!monitords" (no number) you should get the performance displayed in discord (only 5 times). The erroneous message was also corrected.

 

 

  Quote

On the first question, I wanted to ask what log the bot parses.

The bot takes a list of all log files (*.log and *.rpt) files in the given directory and sorts them by name.
Then it takes the most recent one as the current log to read from. The current log file should be displayed in the console.

 

 

  Quote

![banPlayer|banplayer] <player_id> [time=0] [message...]
!addBan 76561198***7183** time=60

The commands do not support value assignments, simply leave the "time=".
time = 0 simply means the default value is 0 --> which is a permanent ban.
 

!addBan 0123456789 60 You are a bad boy

 

  Quote

There was a problem with the certificate. Unexpectedly, after several weeks of work.

I am not sure what you mean

Share this post


Link to post
Share on other sites

Launched, but does not work, although it connects to the discord!
 

  Reveal hidden contents

 

Share this post


Link to post
Share on other sites
  On 5/25/2020 at 1:20 PM, VitalyTurboVaz said:

Launched, but does not work, although it connects to the discord!

A yes, my bad, there were some not used packages in there. Should be good now.

Share this post


Link to post
Share on other sites

Hi!

 

I setup the https://github.com/Yoshi-E/ArmaRconDiscordBot and it works really nice when typing commands! Thanks!

I would like to know however, can i use the https://github.com/Yoshi-E/ArmaRconDiscordBot to send Discord notifications when a player connects and disconnects to the server?
I would like to output that to a specific Discord channel for players to see.

 

Do I need https://github.com/Yoshi-E/Python-BEC-RCon to do this?

Share this post


Link to post
Share on other sites
  On 6/11/2020 at 12:24 PM, Raymond John Clarke said:

I would like to know however, can i use the https://github.com/Yoshi-E/ArmaRconDiscordBot to send Discord notifications when a player connects and disconnects to the server?
I would like to output that to a specific Discord channel for players to see.

 

Do I need https://github.com/Yoshi-E/Python-BEC-RCon to do this?

 

The rcon module is already included in the bot.
https://github.com/Yoshi-E/ArmaRconDiscordBot/blob/master/modules/rcon/module.py#L311-L329

The variable "message" contains the message produced by rcon.

 

For example message = "16:53:53 | (Side) Max: opfor here at kali" 

or message =

"16:27:52 | Player #6 Max disconnected"

"16:59:23 | Player #8 Max (77.21.253.123:17228) connected"

 

you would need a simple regex or if statements to filter them out.

 

Edit: The out comment else block in that code is not quite correct. Connect messages contain a „:“ therefore the split condition there is wrong for what your are planing to do

 

 

to send the message to a specific channel simply do this:

0123456789 here is the channel id.
You can copy the channel id by right clicking a channel directly from discord, if you have the developer mode enabled in the discord settings (Appearance --> Advanced --> Developer mode). 

channel = self.bot.get_channel(0123456789)
await channel.send("Player {} connected".format("Max"))

 

 

Currently I'm refactoring the entire structure, soonish custom stuff can be easily added in extra modules.

Edited by Yoshi_E
  • Like 1

Share this post


Link to post
Share on other sites
  On 6/11/2020 at 5:10 PM, Yoshi_E said:

 

The rcon module is already included in the bot.
https://github.com/Yoshi-E/ArmaRconDiscordBot/blob/master/modules/rcon/module.py#L311-L329

The variable "message" contains the message produced by rcon.

 

For example message = "16:53:53 | (Side) Max: opfor here at kali" 

or message =

"16:27:52 | Player #6 Max disconnected"

"16:59:23 | Player #8 Max (77.21.253.123:17228) connected"

 

you would need a simple regex or if statements to filter them out.

 

Edit: The out comment else block in that code is not quite correct. Connect messages contain a „:“ therefore the split condition there is wrong for what your are planing to do

 

 

to send the message to a specific channel simply do this:

0123456789 here is the channel id.
You can copy the channel id by right clicking a channel directly from discord, if you have the developer mode enabled in the discord settings (Appearance --> Advanced --> Developer mode). 

channel = self.bot.get_channel(0123456789)
await channel.send("Player {} connected".format("Max"))

 

 

Currently I'm refactoring the entire structure, soonish custom stuff can be easily added in extra modules.

 

Thanks!

 

So if i understand this correctly ( keeping in mind i am not a coder / developer at all )

channel = self.bot.get_channel(0123456789)

await channel.send("Player {} connected".format("Max"))

 

This means that only if a player named "Max" connects to the server it will output this to the given channel?

I actually want it to output any connect and disconnects from any players to the given channel.

 

Also, could you please guide me on exactly where i need to add this part in the module.py?

Share this post


Link to post
Share on other sites

@Raymond John Clarke I added it as a module, simply update to the latest version, and you should be able to enable the module "modules/rcon_join_msg" it in the settings. 
Some settings require the bot to be restart after change. Setting menu is still WIP.

Share this post


Link to post
Share on other sites

Wow wow wow!! I am super impressed!!
It works perfectly and dummy proof as well now hehe. 🙂

 

Thank you so very very much! I wish i was clever enough to do this myself, but hey, I'm glad there are people like you!

Share this post


Link to post
Share on other sites

@Yoshi_E
I have 2 things that you can maybe assist me with 🙂

One problem I have is that when the server restarts, cmd says:

 

"Reconnecting to BEC Rcon"

 

It never connects BEC automatically so the Bot no longer works until i restart the Bot again.

Any way to set it to try connecting every few seconds perhaps?

2nd thing, the player join and leave msg works great, but some players asked that I rather remove it as it shows the players public IP address. They are worried about ddos attacks and hacks.

Can I set it to only show the name and not the IP as well?

 

Thanks for all the replies!

Share this post


Link to post
Share on other sites
  On 6/15/2020 at 7:17 AM, Raymond John Clarke said:

@Yoshi_E
I have 2 things that you can maybe assist me with 🙂

One problem I have is that when the server restarts, cmd says:

 

"Reconnecting to BEC Rcon"

 

It never connects BEC automatically so the Bot no longer works until i restart the Bot again.

Any way to set it to try connecting every few seconds perhaps?

2nd thing, the player join and leave msg works great, but some players asked that I rather remove it as it shows the players public IP address. They are worried about ddos attacks and hacks.

Can I set it to only show the name and not the IP as well?

 

Thanks for all the replies!

Just as side note here.. I actually use this for Dayz.
So my BEC will output this when a player connects for example:

 

(2020-06-15 | 14:02:40) : Player #3 PlayerName (79.512.1.151:2000) connected

 

I only want it to show: Player #3 PlayerName connected

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×