-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrybebot.py
More file actions
158 lines (113 loc) · 5.3 KB
/
trybebot.py
File metadata and controls
158 lines (113 loc) · 5.3 KB
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
#!/usr/bin/env python3
import logging
import os
import random
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
import messages
import fbhelper
import convologic
import keyboard
convo = messages.Messages()
db = fbhelper.FirebaseHelper()
kb = keyboard.KeyBoard()
updater = Updater(token='967526375:AAEtE0EXObee7jS-3i7ejXO2NpiG9piHQr4', use_context=True)
dispatcher = updater.dispatcher
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s = %(message)s', level=logging.INFO)
def start_(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=convo.welcome)
def help_(update, context):
chat_id = update.effective_chat.id
context.bot.send_message(chat_id=chat_id, text=convo.help)
db.delete_from_node(chat_id, "post_pending")
def cancel_(update, context):
chat_id = update.effective_chat.id
context.bot.send_message(chat_id=chat_id, text=convo.process_terminated)
db.delete_from_node(chat_id, "post_pending")
def unknown_(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=convo.invalid_command)
def create_post(update, context):
chat_id = update.effective_chat.id
user_input = update.message.text
context.bot.send_message(chat_id=chat_id, text=convo.ask_name, reply_markup=kb.forcereplykb)
db.update_state(chat_id, 0)
db.update_data(chat_id, "command", user_input)
def chat_(update, context):
chat_id = update.effective_chat.id
user_input = update.message
current_command = db.read_data_pending(chat_id, "command")
if current_command == "/checkpost":
convologic.handle_check_post(chat_id, user_input, context)
elif current_command == "/markpost":
convologic.handle_mark_post(chat_id, user_input, context)
elif current_command == "/createpost":
convologic.handle_create_post(chat_id, user_input, context)
else:
if update.effective_chat.id > 0:
# update is from user account
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
else:
print(update)
def check_post(update, context):
chat_id = update.effective_chat.id
user_input = update.message.text
context.bot.send_message(chat_id=chat_id, text=convo.check_post_0, reply_markup=kb.forcereplykb)
context.bot.send_message(chat_id=chat_id, text=convo.check_post_1, reply_markup=kb.forcereplykb)
db.update_data(chat_id, "command", user_input)
db.update_data(chat_id, "state", 0)
def mark_post(update, context):
chat_id = update.effective_chat.id
user_input = update.message.text
context.bot.send_message(chat_id=chat_id, text=convo.mark_post_0, reply_markup=kb.forcereplykb)
context.bot.send_message(chat_id=chat_id, text=convo.mark_post_1, reply_markup=kb.forcereplykb)
db.update_data(chat_id, "command", user_input)
db.update_data(chat_id, "state", 0)
def contact_mod(update, context):
chat_id = update.effective_chat.id
context.bot.send_message(text=convo.contact_us, chat_id=chat_id)
def sticker_(update, context):
sticker_set = context.bot.get_sticker_set(update.message.sticker.set_name)
random_sticker_id = get_random_sticker_id(sticker_set)
context.bot.send_sticker(chat_id=update.effective_chat.id, sticker=random_sticker_id)
def animation_(update, context):
chat_id = update.effective_chat.id
context.bot.send_message(chat_id=chat_id, text=convo.gif_seal_0)
context.bot.send_animation(chat_id=chat_id, animation=convo.gif_seal_id)
context.bot.send_message(chat_id=chat_id, text=convo.gif_seal_1)
def get_random_sticker_id(sticker_set):
sticker_list = sticker_set.stickers
random_sticker_index = random.randint(0, len(sticker_list) - 1)
random_sticker_id = str(sticker_list[random_sticker_index].file_id)
return random_sticker_id
def setup_handlers():
start_handler = CommandHandler('start', start_)
dispatcher.add_handler(start_handler)
cancel_handler = CommandHandler('cancel', cancel_)
dispatcher.add_handler(cancel_handler)
help_handler = CommandHandler('help', help_)
dispatcher.add_handler(help_handler)
create_post_handler = CommandHandler('createpost', create_post)
dispatcher.add_handler(create_post_handler)
check_post_handler = CommandHandler('checkpost', check_post)
dispatcher.add_handler(check_post_handler)
mark_post_handler = CommandHandler('markpost', mark_post)
dispatcher.add_handler(mark_post_handler)
contact_mod_handler = CommandHandler('contactmod', contact_mod)
dispatcher.add_handler(contact_mod_handler)
chat_handler = MessageHandler(Filters.text & (~Filters.command), chat_)
dispatcher.add_handler(chat_handler)
photo_handler = MessageHandler(Filters.photo, chat_)
dispatcher.add_handler(photo_handler)
sticker_handler = MessageHandler(Filters.sticker, sticker_)
dispatcher.add_handler(sticker_handler)
animation_handler = MessageHandler(Filters.animation, animation_)
dispatcher.add_handler(animation_handler)
# put this last or other commands would be skipped!
unknown_handler = MessageHandler(Filters.command, unknown_)
dispatcher.add_handler(unknown_handler)
if __name__ == '__main__':
# main()
setup_handlers()
updater.start_polling()
updater.idle()