Created
January 7, 2017 08:30
-
-
Save satwikkansal/a353e023799ac7a8a5d72781c8cc50e9 to your computer and use it in GitHub Desktop.
This file contains 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 time | |
import random | |
import datetime | |
import telepot | |
""" | |
After **inserting token** in the source code, run it: | |
``` | |
$ python2.7 diceyclock.py | |
``` | |
[Here is a tutorial](http://www.instructables.com/id/Set-up-Telegram-Bot-on-Raspberry-Pi/) | |
teaching you how to setup a bot on Raspberry Pi. This simple bot does nothing | |
but accepts two commands: | |
- `/roll` - reply with a random integer between 1 and 6, like rolling a dice. | |
- `/time` - reply with the current time, like a clock. | |
""" | |
def handle(msg): | |
chat_id = msg['chat']['id'] | |
command = msg['text'] | |
print 'Got command: %s' % command | |
if command == '/roll': | |
bot.sendMessage(chat_id, random.randint(1,6)) | |
elif command == '/time': | |
bot.sendMessage(chat_id, str(datetime.datetime.now())) | |
bot = telepot.Bot('*** INSERT TOKEN ***') | |
bot.message_loop(handle) | |
print 'I am listening ...' | |
while 1: | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment