Skip to content

Instantly share code, notes, and snippets.

@Boot-Error
Created February 22, 2020 03:28
Show Gist options
  • Select an option

  • Save Boot-Error/7f7024cf984f95ca126a83336b846ba4 to your computer and use it in GitHub Desktop.

Select an option

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
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)
web: python main.py
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