A Discord bot written in Python for the great MMORPG we all know and love named Medivia (Based on Tibia).
This discord bot uses Rapptz's discord.py.
This bot is used to show what players are online in Medivia based on lists of players you care about.
This discord bot has one cog which contains all the code for the medivia commands.
This is the main entrypoint of the bot.
This file contains the following:
- Imports the token the bot will use to authenticate to discord
- Cycles through the bot's statuses (what game it shows the bot is playing in discord)
- Prints the bot is ready when the
python main.py
is run- 'Running
n
nBot is ready ...'.
- 'Running
- Loads all the cogs found in the 'cogs' folder
This file has all the commands the bot provides for Medivia.
- get_lists
- new_list
- remove_list
- add_member
- get_member
- remove_member
Lastly, there is a @tasks.loop
which is set to run every 60 seconds which is the main workhorse of the bot.
This loop runs the medivia_online
function which pulls the online players from the Medivia website and compares that lists to the lists created for your discord via the above commands.
If there are any updates, it will update the channel associated with the list being checked.
When the bot is run and the Medivia discord commands are run, the results of the lists/members added/removed are stored in the config
directory.
These files will be named after the discord server. The contents of the file look like this:
{
"Bullet Club": {
"id": 00000000, # the ID of the discord server this json file is for
"channels": {
"Public Enemy": {
"id": "00000000", # the ID of the channel to send to
"members": [
"Black Panther",
"Orall",
"Alf",
"Tookas Cryx"
]},
"Watch the Throne": {
"id": "00000000", # the ID of the channel to send to
"members": [
"Etrius",
"Sudden'slayer",
"Hasley",
]}
}
}
}
Secondly, when the Medivia website is checked for online users, a file is updated with the latest online members for each list. The file is named after the discord server plus _saved
. This is used so every minute the Medivia online list is checked that it won't update each discord channel each time. It will verify the last online list and only update if there are changes from this list.
Install the required python packages:
pip install beautifulsoup4 discord.py
Add your token as an environmental variable
export TOKEN='xxx'
Run the python app
python main.py
From the root directory of this repo, run the following commands:
To run in Alpine:
docker build -t discord-medivia-pybot -f Dockerfile-alpine .
docker run -d --name discord-medivia-pybot discord-medivia-pybot
To run in Ubuntu:
docker build -t discord-medivia-pybot -f Dockerfile-ubuntu .
docker run -d --name discord-medivia-pybot discord-medivia-pybot
Run the following command to check logs:
docker logs discord-medivia-pybot
Command prefix:
med.
Commands:
All commands are specific to the discord server the command is ran against.
- Lists
get_lists
- Description:
- Returns all the list for this discord server
- Parameters:
- This command does not have any parameters
- Example:
med.get_lists
- Description:
new_list
- Description:
- Creates a new list
- Parameters:
- listName:
- The name to give the list that will be created
- channelId:
- The ID of the channel the list should be posted to
- listName:
- Example:
med.new_lists Friends 1234567
med.new_lists "Watch the Throne" 1234567
- Description:
remove_list
- Description:
- Removes the specified list
- Parameters:
- listName
- The name of the list to remove
- listName
- Example:
med.remove_list Friends
med.remove_list "Watch the Throne"
- Description:
- Members
add_member
- Description:
- Adds the specified member(s) to the specified list
- Parameters:
- listName
- The name of the list to add the member(s) to
- *members
- The member(s) to add to the list
- listName
- Example:
med.add_member Friends "Beardtopia"
med.add_member "Inner Circle" "Beardtopia" "Silenus" "Listen Lady"
- Description:
remove_member
- Description:
- Removes the specified member(s) from the specified list
- Parameters:
- listName
- The name of the list to remove the member(s) to
- *members
- The member(s) to remove from the list
- listName
- Example:
med.remove_member Friends "Beardtopia"
med.remove_member "Inner Circle" "Beardtopia" "Silenus" "Listen Lady"
- Description:
get_members
- Description:
- Returns all the members of the specified list
- Parameters:
- listName
- The name of the list to return member(s) from
- listName
- Example:
med.remove_member Friends
med.remove_member "Inner Circle"
- Description: