-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (54 loc) · 2.16 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
import re
import threading
from telegram.ext import CommandHandler, CallbackQueryHandler, Application, MessageHandler, filters, ConversationHandler
from handlers.essensial_handlers import start, help
from handlers.notice_handlers import new_other_notice, PROSSESS_NOTICE, SELECT_NOTICE_TYPE, prossess_notice, select_notice_type
from handlers.callback_query_handlers import callback_query_handler
from handlers.message_handlers import handle_message
from decouple import config
tk = config('token')
bot_link = config('bot_link')
from functions import verify
from handlers.gate_way_handlers import pay_failed, pay_sucsess
from flask import Flask, render_template, request
flask_app = Flask(__name__)
@flask_app.route('/callback', methods=['GET'])
def callback():
authority = request.args.get('Authority')
status = request.args.get('Status')
if status == 'OK':
result = verify(authority)
pay_sucsess(authority, result["RefID"])
return render_template('callback.html', ref_id=result["RefID"], status=status)
else:
ref_id = pay_failed(authority)
return render_template('callback.html', ref_id=ref_id, status=status)
@flask_app.route('/', methods=['GET'])
def index():
return render_template('home.html')
# if __name__ == "__main__":
# flask_app.run()
def main():
app= Application.builder().token(tk).build()
thread = threading.Thread(target=flask_app.run)
thread.start()
conv_handler = ConversationHandler(
entry_points=[
MessageHandler(filters.Regex(re.compile(r'^آگهی جدید$', re.IGNORECASE)), new_other_notice)
],
states={
SELECT_NOTICE_TYPE: [MessageHandler(filters.TEXT & ~filters.COMMAND, select_notice_type)],
PROSSESS_NOTICE: [MessageHandler(filters.ALL, prossess_notice)],
},
fallbacks=[],
)
app.add_handlers([
CommandHandler('start', start),
CommandHandler('help', help),
conv_handler,
CallbackQueryHandler(callback_query_handler),
MessageHandler(~filters.COMMAND, handle_message),
])
app.run_polling()
if __name__ == "__main__":
main()