Created
February 22, 2020 03:28
-
-
Save Boot-Error/7f7024cf984f95ca126a83336b846ba4 to your computer and use it in GitHub Desktop.
Simple rock paper scissors telegram bot in python. The bot http://t.me/raukpawparscizors_bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bottle | |
| import requests | |
| import os | |
| TOKEN = os.environ.get("TELEGRAM_TOKEN") | |
| def rps_ai(move): | |
| if move == 'rock': | |
| return 'paper' | |
| elif move == 'paper': | |
| return 'scissors' | |
| elif move == 'scissors': | |
| return 'rock' | |
| else: | |
| return 'Hi! I play rock paper scissors' | |
| def sendMessage(chat_id, text): | |
| r = requests.post("https://api.telegram.org/bot{token}/sendMessage".format(token=TOKEN), | |
| data={"chat_id": chat_id, "text": text}) | |
| return r.status_code == 200 | |
| def handle_update(): | |
| update = bottle.request.json | |
| update_id = update['update_id'] | |
| message = update['message'] | |
| chat_id = message['chat']['id'] | |
| text = message['text'] | |
| sendMessage(chat_id, rps_ai(text)) | |
| return "" | |
| if __name__ == "__main__": | |
| app = bottle.Bottle() | |
| app.route("/update", "POST", handle_update) | |
| app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)), debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web: python main.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| requests==2.22.0 | |
| bottle==0.12.18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment