hiddenglovework / gloveworks_screenshot_bot

I have autism
0 stars 1 forks source link
bot discord python

🤖gloveworks_screenshot_bot

About

This is a discord screenshot bot specifically for the Counter Strike Community: Gloveworks

result


Purpose

Gloveworks hosts a monthly contest where the top player can receive a prize. However, there have been times where it has been uncertain who was the top player on the last day of the month at exactly 7 PM PST. That's what this bot aims to solve! This Discord Bot will take a screenshot of a website on the last day of the month at 7 PM PST. It also allows you to request a screenshot on demand.


Prerequisite


How does it work?

The python script is what activates the bot, but the python libraries is what makes the magic happen

The docker image is just a nice way to package all of the dependencies that is required by the python script, and also freeze the software such that Gloveworks can dependently rely on this bot. It uses an existing docker image seleniarm/standalone-chromium, which is a modified Debian Linux image that supports automation capabilities inside docker.


Create and invite your own discord bot

  1. Log into the discord developer portal: https://discord.com/developers/applications login

  2. Create new application, name it whatever you want, and agree to the ToS createapp

  3. Once the page refreshes, go to OAuth2, and click on URL Generator oauthpage

  4. Under "Scopes", checkbox "bot" scopes

  5. Under "Role Permissions", checkbox "Send Messages" and "Attach Files" permissions

  6. Scroll to the bottom, copy the Generated URL and paste it into an address bar in your browser generatedurl

  7. Invite it to your server invitetoserver

  8. Head back to the Discord Developer Page and configure the bots username, and click "Reset" token configurethebotname Remember the token, the bot will need it to come online! If you forget it, you will have to regenerate it!

  9. On the Discord server, modify the channel permissions for the bot's role channelpermissions

Congratulations you just created and invited your own discord bot!


How to run on your PC

You can run the python script directly on your PC. Note that you will need to have chromium and chromium-chromedriver installed and added to the PATH.

python3 discord_screenshot_bot.py [-c|--config] <config-file>

NOTE: If you already added the discord bot token and channel ID as environment variables, you don't need to specify the config file. It will default to use the environment variables.


How to run in a Docker container

Build the image

./run.sh -c <config-file> [-b|--build]

NOTE: Because of the way flags are parsed, the -b flag needs to be at the end. This is due to the fact that the parser is looking for a flag-value pair

With config file

TOKEN = "<bot_token>"
ID = "<channel_id>" # "692925474032320542"
IMAGE = "<docker_image_name>" # "hiddenglovework/ss-discordbot:v1.0.0"
CONTAINER_NAME = "<container_name>" # "gw-discord-ss-bot"

NOTE: Make sure to include the space around the = and wrap all values in double quotes (the config parsing is very basic)

./run.sh [-c | --config] <config_file_path>

NOTE: for more information on the script run: ./run.sh --help

With flags

Run ./ruin.sh --help for more information on what flags are needed.


How to kill the docker image

docker stop <docker_container_id>

# or

docker stop <docker_container_name>

NOTE: To find the container id, run [sudo] docker ps.


How to test the discord bot:

# in the discord channel where the bot is active type this message:
@<insert_bot_name> !screenshot <insert_url>

Help (Feature Requests/Bug fixes)

Troubleshoot: modify the run.sh script to not run the docker container as "-d" detach mode but instead "--it" interactive mode and replace gw-discord-ss-bot with /bin/bash

Contact Hidden through gloveworks and forward me any logs. I will do my best to troubleshoot it