This is a Telegram bot for tracking a poker player income. it provides an easy interface for a player to insert his data, which stored in a mysql database.
- Edit config.py with your db access credentials.
- Contact @botfather on telegram to create a new bot. you will get username and a token.
- Create 'credentials.py' containing your bot credentials. ie :
echo "bot_username = 'my_bot_username'" >> ./credentials.py
echo "token = 'my_bot_token'" >> ./credentials.py
The bot is running inside a docker container which provides an isolated environment with all necessary libs. To build the image :
$ ./build-local-image.sh
- Start mysql if necessary (This will start a local dockem with mysql)
$ cd mysql && ./start-mysql.sh
- start the container:
$ # start like this:
$ ./start-gamesbot.sh
$ # or restart like this:
$ ./stop-gamesbot.sh && ./start-gamesbot.sh
-
Install Chocolatey (windows package manager* NOTE: you can skip this and install MySQL directly)
first, open a PowerShell window by right-click and choose 'Run as administrator'. A PowerShell blue window will open, follow this:# check execution policy PS > Get-ExecutionPolicy # If the above returns Restricted, then run Set-ExecutionPolicy AllSigned: PS > Set-ExecutionPolicy AllSigned # Then install Chocolatey PS > Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
-
Install MySQL database Open a new PowerShell window as described before (must be a NEW PowerShell window) and install MySQL:
PS > choco install mysql
-
Create the database and users
TODO: describe the procedure, tables will be created by the bot. currently need to create a db named db_gamesbot with user and password that has permissions over the database. the actions can be retrieved from looking at docker and docker-compose files
-
Install python3 and dependencies
TODO: describe procedure. basically creating a python3 venv and installing the libs from requirements.txt
-
Create config.py file with DB credentials
# Main configuration db_host = 'localhost' db_name = 'db_gamesbot' db_user = 'user' db_password = 'password'
-
Starting the bot ( untested )
PS > python3.exe games-boy.py
The database is hosted on the same host (in my case) and running with docker-compose, all details in mysql/ folder
$ mysql -h127.0.0.1 -uroot -p
mysql> CREATE DATABASE db_gamesbot;
mysql> CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'pass1';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%';
mysql> CREATE USER 'viewer'@'%' IDENTIFIED WITH mysql_native_password BY 'pass2';
mysql> GRANT SELECT, SHOW VIEW ON *.* TO 'viewer'@'%';
mysql> # TODO: alter root user password to 'pass1'
mysql> FLUSH PRIVILEGES;
NOTE: there is a backup cron job for this in mysql/backup-cron.sh
$ mysqldump -h127.0.0.1 -uroot -p'pass1' db_gamesbot > ./db_gamesbot.sql
$ mysql -h127.0.0.1 -uroot -p'pass1' db_gamesbot < ./db_gamesbot.sql