forked from samruddhag1/weOsumbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
86 lines (67 loc) · 2.81 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
#using python-telegram-bot modules
import telegram
from telegram.ext import Updater
#States
VERIFYAMOUNT,VERIFYPERSON = range(2)
END = -1
def askAmount(bot , update):
text = "How much?"
bot.sendMessage(chat_id=update.message.chat_id, text=text)
print ('asked amount')
return VERIFYAMOUNT
def askPerson(bot, update):
text = "Who's e (he/she/whatever)?"
bot.sendMessage(chat_id=update.message.chat_id, text=text)
print ('asked person')
def verifyAmount(bot, update):
str_amt=update.message.text
print('verify_caught')
try :
amount = eval(str_amt)
print (amount)
text = 'The amount is {}'.format(amount)
bot.sendMessage(chat_id=update.message.chat_id, text=text)
askPerson(bot, update)
return VERIFYPERSON
except:
try_again = "Sorry, could not read a *valid* amount!!\nWhats valid? Try something you would type in a calci.\n"
try_again+= "You can also type _/cancel_ to abort"
bot.sendMessage(chat_id=update.message.chat_id, text = try_again, parse_mode=telegram.ParseMode.MARKDOWN)
return VERIFYAMOUNT
pass
#def verifyPerson(bot, update):
def cancel(bot, update):
text = 'Ok. Going back to my world.'
bot.sendMessage(chat_id=update.message.chat_id, text=text)
return -1
def echo(bot ,update):
bot.sendMessage(chat_id=update.message.chat_id, text = update.message.text+' You!')
def askContact(bot,update):
contact_keyboard = telegram.KeyboardButton(text="send_contact", request_contact=True)
custom_keyboard = [[ contact_keyboard ]]
reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
bot.sendMessage(chat_id=update.message.chat_id, text="Would mind to share location and contact with me ?",reply_markup=reply_markup)
######Temp for Testing Only######
updater = Updater(token='292385752:AAFCJrNmm_x47FFk_VzJqQFToDnZ7BdQKCU')
dispatcher = updater.dispatcher
from telegram.ext import CommandHandler
from telegram.ext import ConversationHandler
from telegram.ext import MessageHandler , Filters
cancel_handler = CommandHandler('cancel',cancel)
iosum_handler = CommandHandler('iosum',askAmount)
verifyAmount_handler = MessageHandler([Filters.text ], verifyAmount)
iosumconv_handler = ConversationHandler([iosum_handler],{VERIFYAMOUNT: [verifyAmount_handler]},[cancel_handler] )
echo_handler = MessageHandler([Filters.text], echo)
contact_handler = CommandHandler('contact',askContact)
#.add_handler(iosum_handler)
dispatcher.add_handler(iosumconv_handler)
dispatcher.add_handler(contact_handler)
#dispatcher.add_handler(cancel_handler)
#dispatcher.add_handler(verifyAmount_handler)
#dispatcher.add_handler(echo_handler)
updater.start_polling()
#updater.idle()
#updater.stop()
print('Bye')
#################################