From ea15fd93b7c197372182f365f6cf90868ee87b9d Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 13:48:37 +0200 Subject: [PATCH 01/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 416ed60..81bb3b4 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,4 @@ Please read [```CONTRIBUTING.md```](https://github.com/Crazy-Marvin/2048Telegram ## License -This project is licensed under the MIT License - see the [```LICENSE```](https://github.com/Crazy-Marvin/cats_n_dogs/blob/master/LICENSE) file for details +This project is licensed under the MIT License - see the [```LICENSE```](https://github.com/Crazy-Marvin/cats_n_dogs/blob/master/LICENSE) file for details. From c56f0066751672152a4d5213d8021fb30a73a20c Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 13:51:17 +0200 Subject: [PATCH 02/12] Update Snyk Badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81bb3b4..2d85200 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Pull requests](https://img.shields.io/github/issues-pr/Crazy-Marvin/2048TelegramBot.svg?style=flat)](https://github.com/Crazy-Marvin/2048TelegramBot/pulls) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3ead43c44bc4405ebea91f61ff2c45e6)](https://www.codacy.com/gh/Crazy-Marvin/2048TelegramBot?utm_source=github.com&utm_medium=referral&utm_content=Crazy-Marvin/2048TelegramBot&utm_campaign=Badge_Grade) [![codecov](https://codecov.io/gh/Crazy-Marvin/2048TelegramBot/branch/master/graph/badge.svg)](https://codecov.io/gh/Crazy-Marvin/2048TelegramBot) -[![Known Vulnerabilities](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot/badge.svg?targetFile=bot.py)](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot?targetFile=bot.py) +[![Known Vulnerabilities](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot/badge.svg?targetFile=bot/requirements.txt)](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot?targetFile=bot/requirements.txt) [![Website](https://img.shields.io/website?url=https%3A%2F%2Fpoopjournal.rocks%2F2048%2F)](https://poopjournal.rocks/2048/) # 2048 on Telegram From c7904a39e07069bfcf8ad2ff5874a970a9181a09 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 17:31:38 +0200 Subject: [PATCH 03/12] Update README.md --- bot/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/README.md b/bot/README.md index 148360b..54b41e7 100644 --- a/bot/README.md +++ b/bot/README.md @@ -1,11 +1,11 @@ -# installation +# Installation To install, unpack this archive in a folder. - - Install python 3.7 on your system and make it available. + - Install Python 3 on your system and make it available. - In a commandline create a virtual environment: ```bash -python37 -m venv venv +python3 -m venv venv . venv/bin/activate # in *nix environments ./venv/scripts/activate pip install -r requirements.txt @@ -24,6 +24,8 @@ pip install -r requirements.txt - splash.png ``` +![File Structure](https://user-images.githubusercontent.com/15004217/80312097-a859ba00-87e3-11ea-85bf-4cef4d0f1ca3.PNG) + - The file config.json will need the following content: ```json @@ -46,4 +48,4 @@ Or on windows ./venv/scripts/python -m gamebot ``` -For a persistent setup i would recommend a crontab, or a systemd service. \ No newline at end of file +For a persistent setup I would recommend a crontab or a systemd service. From 90595c5cfd2deca75be26fdebb452be8e48f6103 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 17:43:59 +0200 Subject: [PATCH 04/12] Update README.md --- bot/README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bot/README.md b/bot/README.md index 54b41e7..977a95a 100644 --- a/bot/README.md +++ b/bot/README.md @@ -1,3 +1,19 @@ +# Botfather + +Start a chat with [@Botfather](https://t.me/botfather) to receive your personal token. +Follow the instructions by him. + +Those are the supported [commands](https://core.telegram.org/bots#commands): + +``` +start - Start +play2048 - Play 2048 😁 +help - How to play +about - Info about the bot +source - View the source code +legal - See Terms of Service and Privacy Policy +``` + # Installation To install, unpack this archive in a folder. @@ -43,7 +59,7 @@ Run the following command # in this directory ./venv/bin/python -m gamebot ``` -Or on windows +Or on Windows ``` ./venv/scripts/python -m gamebot ``` From ce82a2e4ffc8c4efa6252e568adbe9a0cef2307f Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 17:45:40 +0200 Subject: [PATCH 05/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d85200..ba0a4cf 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ _TODO_ The setup consists of two parts. One webserver that hosts the game, and one normal server that hosts the bot. - The game itself is located in the ```game``` folder and needs to be put on any webserver -- The bot can be found in `bot` and has installation instructions in its README +- The bot can be found in `bot` and has installation instructions in its [```README```](https://github.com/Crazy-Marvin/2048TelegramBot/blob/master/bot/README.md) ## Contributing From 107302a5b0019c51894b7bd48d95b374ea7e14fd Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 18:13:25 +0200 Subject: [PATCH 06/12] Update README.md --- bot/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/README.md b/bot/README.md index 977a95a..be5fbfb 100644 --- a/bot/README.md +++ b/bot/README.md @@ -14,6 +14,8 @@ source - View the source code legal - See Terms of Service and Privacy Policy ``` +You can inform the Botfather about them for auto-completion but that is optional. + # Installation To install, unpack this archive in a folder. From b66d0edce4acc3ed7b74ada0a8fca9c4361d2da4 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 21:50:04 +0200 Subject: [PATCH 07/12] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ba0a4cf..1ea8bc1 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ This [Telegram](https://telegram.org/) game/bot lets you play the 2048 game with [Play here](https://t.me/twothousandfortyeightbot?game=twothousandfortyeight) -## Screenshots +## Screenshot -_TODO_ +![2048TelegramBot_Screenshot](https://user-images.githubusercontent.com/15004217/80318026-840fd480-8807-11ea-89e3-487170376a14.jpg) ## Setup The setup consists of two parts. One webserver that hosts the game, and one normal server that hosts the bot. -- The game itself is located in the ```game``` folder and needs to be put on any webserver +- The game itself is located in the ```game``` folder and needs to be put on any webserver, preferrably [GitHub Pages](https://pages.github.com/) - The bot can be found in `bot` and has installation instructions in its [```README```](https://github.com/Crazy-Marvin/2048TelegramBot/blob/master/bot/README.md) ## Contributing @@ -34,6 +34,7 @@ Please read [```CONTRIBUTING.md```](https://github.com/Crazy-Marvin/2048Telegram - [2048](https://play2048.co/) by [Gabriele Cirulli](https://gabrielecirulli.com/) - [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) +- [Python Configlib](https://github.com/romangraef/configlib) ## License From e1b29faa1c5aeb4cf494ba8613e409b8699de945 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sun, 26 Apr 2020 21:54:28 +0200 Subject: [PATCH 08/12] Update README.md --- bot/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot/README.md b/bot/README.md index be5fbfb..d93cf08 100644 --- a/bot/README.md +++ b/bot/README.md @@ -50,11 +50,15 @@ pip install -r requirements.txt { "token": "the token provided by the botfather", "game_name": "the short name of the game as given in the botfather", - "game_url": "the http adress of the game html", + "game_url": "the http(s) adress of the game html without trailing slash", "bot_url": "the ip/hostname of this bot. this is not a webadress, so don't prefix it with http://. it should be in the form of 127.0.0.1 or google.com" } ``` +Here you can see the ```game_name```: + +![game_name](https://user-images.githubusercontent.com/15004217/80318150-45c6e500-8808-11ea-966d-162a3f549287.PNG) + # Running Run the following command ```bash From d4a517de46d346eda91749398074810493583128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Gr=C3=A4f?= Date: Sat, 2 May 2020 00:36:03 +0200 Subject: [PATCH 09/12] Healthchecks --- bot/README.md | 39 ++++++++------------------------------ bot/gamebot/__main__.py | 2 ++ bot/gamebot/bot.py | 2 +- bot/gamebot/config.py | 1 + bot/gamebot/healthcheck.py | 18 ++++++++++++++++++ 5 files changed, 30 insertions(+), 32 deletions(-) create mode 100644 bot/gamebot/healthcheck.py diff --git a/bot/README.md b/bot/README.md index d93cf08..4c94d6f 100644 --- a/bot/README.md +++ b/bot/README.md @@ -1,29 +1,11 @@ -# Botfather - -Start a chat with [@Botfather](https://t.me/botfather) to receive your personal token. -Follow the instructions by him. - -Those are the supported [commands](https://core.telegram.org/bots#commands): - -``` -start - Start -play2048 - Play 2048 😁 -help - How to play -about - Info about the bot -source - View the source code -legal - See Terms of Service and Privacy Policy -``` - -You can inform the Botfather about them for auto-completion but that is optional. - -# Installation +# installation To install, unpack this archive in a folder. - - Install Python 3 on your system and make it available. + - Install python 3.7 on your system and make it available. - In a commandline create a virtual environment: ```bash -python3 -m venv venv +python37 -m venv venv . venv/bin/activate # in *nix environments ./venv/scripts/activate pip install -r requirements.txt @@ -42,32 +24,27 @@ pip install -r requirements.txt - splash.png ``` -![File Structure](https://user-images.githubusercontent.com/15004217/80312097-a859ba00-87e3-11ea-85bf-4cef4d0f1ca3.PNG) - - The file config.json will need the following content: ```json { "token": "the token provided by the botfather", "game_name": "the short name of the game as given in the botfather", - "game_url": "the http(s) adress of the game html without trailing slash", - "bot_url": "the ip/hostname of this bot. this is not a webadress, so don't prefix it with http://. it should be in the form of 127.0.0.1 or google.com" + "game_url": "the http adress of the game html", + "bot_url": "the ip/hostname of this bot. this is not a webadress, so don't prefix it with http://. it should be in the form of 127.0.0.1 or google.com", + "healthchecks_url": "a healthchecks.io url or null" } ``` -Here you can see the ```game_name```: - -![game_name](https://user-images.githubusercontent.com/15004217/80318150-45c6e500-8808-11ea-966d-162a3f549287.PNG) - # Running Run the following command ```bash # in this directory ./venv/bin/python -m gamebot ``` -Or on Windows +Or on windows ``` ./venv/scripts/python -m gamebot ``` -For a persistent setup I would recommend a crontab or a systemd service. +For a persistent setup i would recommend a crontab, or a systemd service. \ No newline at end of file diff --git a/bot/gamebot/__main__.py b/bot/gamebot/__main__.py index fc09ebf..a551642 100644 --- a/bot/gamebot/__main__.py +++ b/bot/gamebot/__main__.py @@ -1,7 +1,9 @@ from .bot import bot from .server import run as run_server +from .healthcheck import run as run_healthcheck if __name__ == '__main__': run_server() + run_healthcheck() bot.start_polling() bot.idle() diff --git a/bot/gamebot/bot.py b/bot/gamebot/bot.py index 894e79e..c318018 100644 --- a/bot/gamebot/bot.py +++ b/bot/gamebot/bot.py @@ -78,7 +78,7 @@ def inline_handler(update: Update, ctx: CallbackContext): def get_score_url(uuid): - return "http://" + config.bot_url + ":8123/report?uuid=" + uuid + "&score=" + return "//" + config.bot_url + "/report?uuid=" + uuid + "&score=" @CallbackQueryHandler diff --git a/bot/gamebot/config.py b/bot/gamebot/config.py index fd921be..c139769 100644 --- a/bot/gamebot/config.py +++ b/bot/gamebot/config.py @@ -6,6 +6,7 @@ class Config(BaseConfig): game_name: str game_url: str bot_url: str + healthchecks_url: str config = Config.get_instance() diff --git a/bot/gamebot/healthcheck.py b/bot/gamebot/healthcheck.py new file mode 100644 index 0000000..1e56a19 --- /dev/null +++ b/bot/gamebot/healthcheck.py @@ -0,0 +1,18 @@ +from threading import Thread +from time import sleep + +import requests + +from .config import config + + +def target(): + while True: + requests.get(config.healthchecks_url) + sleep(60) + + +def run(): + if config.healthchecks_url: + t = Thread(target=target, daemon=True, name="Healthchecks thread") + t.start() From 560d3724142ae20857f5c528932315d875150735 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sat, 2 May 2020 21:07:32 +0200 Subject: [PATCH 10/12] Add healthchecks.io Badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ea8bc1..e60b279 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3ead43c44bc4405ebea91f61ff2c45e6)](https://www.codacy.com/gh/Crazy-Marvin/2048TelegramBot?utm_source=github.com&utm_medium=referral&utm_content=Crazy-Marvin/2048TelegramBot&utm_campaign=Badge_Grade) [![codecov](https://codecov.io/gh/Crazy-Marvin/2048TelegramBot/branch/master/graph/badge.svg)](https://codecov.io/gh/Crazy-Marvin/2048TelegramBot) [![Known Vulnerabilities](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot/badge.svg?targetFile=bot/requirements.txt)](https://snyk.io/test/github/Crazy-Marvin/2048TelegramBot?targetFile=bot/requirements.txt) -[![Website](https://img.shields.io/website?url=https%3A%2F%2Fpoopjournal.rocks%2F2048%2F)](https://poopjournal.rocks/2048/) +[![Website](https://img.shields.io/website?url=https%3A%2F%2F2048.poopjournal.rocks%2F)](https://2048.poopjournal.rocks/) +![healthchecks.io](https://img.shields.io/endpoint?url=https%3A%2F%2Fhealthchecks.io%2Fbadge%2F396c7d03-faf7-4562-9f83-1194d0%2FkXtEcp9g.shields) # 2048 on Telegram From 331970071923b10dead6109530d78da4c64cf9c9 Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sat, 2 May 2020 21:19:29 +0200 Subject: [PATCH 11/12] Add Paragraph About (Optional) Monitoring --- bot/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bot/README.md b/bot/README.md index 58a0a30..d69723d 100644 --- a/bot/README.md +++ b/bot/README.md @@ -72,3 +72,9 @@ Or on Windows ``` For a persistent setup I would recommend a crontab or a systemd service. + +# Monitoring + +You can monitor the bot using a service like [Healthchecks.io](https://healthchecks.io/) or [Cronitor](https://cronitor.io/) to get notified when the bot stops working. + +![healthchecks](https://user-images.githubusercontent.com/15004217/80873676-887e3680-8cba-11ea-8616-5b189453dbec.PNG) From f9772ea003b784dee6dfedc68bb147a05a86cd5d Mon Sep 17 00:00:00 2001 From: CrazyMarvin Date: Sat, 2 May 2020 21:21:48 +0200 Subject: [PATCH 12/12] Update CODE_OF_CONDUCT.md --- .github/CODE_OF_CONDUCT.md | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 8b13789..a92313a 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -1 +1,78 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at marvin@poopjournal.rocks. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq +