-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
188 lines (109 loc) · 4.93 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from telegram.ext import (Updater, InlineQueryHandler,Filters,
CommandHandler ,ConversationHandler,MessageHandler)
from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove)
INSERT_BUY_ID, MAKE_SURE, PHOTO_RECIVING = range(3)
def start(update, context):
txt="Hello " + update.effective_chat.first_name + "\nYou are talking to Geektori team \n,if you bought استیکر طرح دلخواه , pleas insert your Buy-ID?"
update.message.reply_text(txt)
return INSERT_BUY_ID
def InsertBuyID(update, context):
reply_keyboard = [["Yes","No"]]
user = update.message.from_user
txt='Are you sure -'+ update.message.text + '- is your Buy-ID'
update.message.reply_text(txt,
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True))
logger.info("Buy-ID %s: %s", user.first_name, update.message.text)
return MAKE_SURE
def MakeSure(update, context):
user = update.message.from_user
txt="Now Please Send Your Picture , the better way is to send it as file "
logger.info(" %s is %s ,sure", user.first_name, update.message.text)
update.message.reply_text(txt, reply_markup=ReplyKeyboardRemove() )
return PHOTO_RECIVING
def PhotoFileReciving(update, context):
try:
obj=context.bot.getFile(file_id=update.message.document.file_id)
obj.download(update.effective_chat.first_name +'.png')
update.message.reply_text('Thanks for Sending me this picture, we will prepare and send it ASP ')
except Exception as e:
print(str(e))
return ConversationHandler.END
def PhotoReciving(update, context):
try:
print("mamad ")
photo_file = update.message.photo[-1].get_file()
photo_file.download(update.effective_chat.first_name +'.png')
update.message.reply_text('Thanks for Sending me this picture, we will prepare and send it ASP ')
except Exception as e:
print(str(e))
return ConversationHandler.END
def cancel(update, context):
user = update.message.from_user
logger.info("User %s canceled the conversation.", user.first_name)
update.message.reply_text('Bye! I hope we can talk again some day.',
reply_markup=ReplyKeyboardRemove())
return ConversationHandler.END
def han(update , context):
han=''
context.bot.send_message(chat_id=update.effective_chat.id,text=dir(han))
def main():
Geektori_bot_token='1251228456:AAGiftOnmBKgC4GlPHRNzkssaTD1XTVOGBY'
updater = Updater(Geektori_bot_token, use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
INSERT_BUY_ID: [MessageHandler(Filters.text, InsertBuyID)],
MAKE_SURE:[MessageHandler(Filters.regex('^(Yes|No)$'), MakeSure)] ,
PHOTO_RECIVING: [
MessageHandler(filters=Filters.document, callback=PhotoFileReciving,
pass_chat_data=True,pass_user_data= True),
MessageHandler(filters=Filters.photo, callback=PhotoReciving,
pass_chat_data=True,pass_user_data= True),
CommandHandler('cancel', cancel)
]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
# dp.add_handler(MessageHandler(filters=Filters.photo, callback=han,
# pass_chat_data=True,pass_user_data= True)
# )
dp.add_handler(conv_handler)
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
import logging
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def error(update, context):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, context.error)
if __name__ == '__main__':
main()
# import requests
# import re
# def get_url():
# contents = requests.get('https://random.dog/woof.json').json()
# url = contents['url']
# return url
# def get_image_url():
# allowed_extension = ['jpg','jpeg','png']
# file_extension = ''
# while file_extension not in allowed_extension:
# url = get_url()
# file_extension = re.search("([^.]*)$",url).group(1).lower()
# return url
# def bop(bot, update):
# url = get_image_url()
# chat_id = update.message.chat_id
# bot.send_photo(chat_id=chat_id, photo=url)
# print("\n\n\n\n")