first
This commit is contained in:
58
handlers/AdminActionsHandler.py
Normal file
58
handlers/AdminActionsHandler.py
Normal file
@ -0,0 +1,58 @@
|
||||
from bot.Handler import Handler
|
||||
from telegram.constants import ParseMode
|
||||
from bot import FIRST
|
||||
from bot.keyboards.VacancyNotificationToAdminKeyboard import VacancyNotificationToAdminKeyboard
|
||||
from bot.msg.AdminNotifMsg import AdminNotifMsg
|
||||
from itguild_api import client
|
||||
|
||||
|
||||
class AdminActionsHandler(Handler):
|
||||
@staticmethod
|
||||
async def admin_respond_to_vacancy(update, context):
|
||||
query = update.callback_query
|
||||
query.answer()
|
||||
|
||||
command, params = Handler.load_callback_query(query.data)
|
||||
print(command, params)
|
||||
|
||||
admins = client.tgBot.get_admins()
|
||||
recipient = client.tgBot.get_dialog(params['dialog_id'])
|
||||
post = client.tgParsing.get_by_id(params['ig_post_id'])
|
||||
anm = AdminNotifMsg()
|
||||
|
||||
for admin in admins:
|
||||
if admin['status'] == 2:
|
||||
reply_markup = VacancyNotificationToAdminKeyboard()
|
||||
reply_markup.add_option("post", post)
|
||||
reply_markup.add_option("recipient", admin)
|
||||
msg = anm.get_msg({'admin': admin, 'post': post, 'recipient': recipient, 'recipient_respond': True})
|
||||
await context.bot.send_message(chat_id=admin['dialog_id'], text=msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup.create_keyboard())
|
||||
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text="<b>Отклик отправлен</b>", parse_mode=ParseMode.HTML)
|
||||
|
||||
return FIRST
|
||||
|
||||
@staticmethod
|
||||
async def request_sent(update, context):
|
||||
query = update.callback_query
|
||||
# query.answer()
|
||||
|
||||
data = query.data
|
||||
command, params = Handler.load_callback_query(data)
|
||||
|
||||
user = client.tgBot.get_dialog(update.effective_chat.id)
|
||||
post = client.tgParsing.get_by_id(params['ig_post_id'])
|
||||
|
||||
reply_markup = VacancyNotificationToAdminKeyboard()
|
||||
reply_markup.add_option("post", post)
|
||||
reply_markup.add_option("recipient", user)
|
||||
|
||||
client.tgParsing.update({'id': int(post['id']), 'status': 5})
|
||||
post['status'] = 5
|
||||
|
||||
msg = AdminNotifMsg()
|
||||
text = msg.get_msg({"post": post, "admin": user, "status": "Запрос отправлен"})
|
||||
|
||||
await query.edit_message_text(text=text, parse_mode=ParseMode.HTML, reply_markup=reply_markup.create_keyboard())
|
||||
|
||||
return FIRST
|
36
handlers/AdminHandler.py
Normal file
36
handlers/AdminHandler.py
Normal file
@ -0,0 +1,36 @@
|
||||
from bot.Handler import Handler
|
||||
from db.services.BookingService import BookingService
|
||||
from db.services.ChatService import ChatService
|
||||
from bot import FIRST
|
||||
|
||||
|
||||
class AdminHandler(Handler):
|
||||
|
||||
@staticmethod
|
||||
def accept_booking(update, context):
|
||||
query = update.callback_query
|
||||
query.answer()
|
||||
|
||||
variant = query.data
|
||||
command, book_id = variant.split("=")
|
||||
|
||||
book = BookingService.get_booking_by_id(book_id)
|
||||
BookingService.edit(book, "status", BookingService.STATUS_ACCEPTED)
|
||||
|
||||
context.bot.send_message(chat_id=book.chat_id, text="Администратор принял заявку")
|
||||
|
||||
admin = ChatService.get_by_chat_id(update.effective_chat.id)
|
||||
|
||||
name = "Неизвестный"
|
||||
if hasattr(admin, "username"):
|
||||
name = admin.username
|
||||
elif hasattr(admin, "first_name"):
|
||||
name = admin.first_name
|
||||
|
||||
admins = ChatService.get_admins()
|
||||
|
||||
for admin in admins:
|
||||
context.bot.send_message(chat_id=admin.chat_id,
|
||||
text="Администратор {name} принял заявку.".format(name=name))
|
||||
|
||||
return FIRST
|
35
handlers/AuthHandler.py
Normal file
35
handlers/AuthHandler.py
Normal file
@ -0,0 +1,35 @@
|
||||
from bot.Handler import Handler
|
||||
from bot import SET_DATE_STEP, SET_TABLE_STEP, REQUEST_CODE_STEP, FIRST, AUTH_FINISH, config
|
||||
from bot.keyboards.DateToBookingKeyboard import DateToBookingKeyboard
|
||||
from bot.keyboards.FirstStepKeyboard import FirstStepKeyboard
|
||||
from bot.keyboards.GetTableListKeyboard import GetTableListKeyboard
|
||||
from itguild_api import client
|
||||
from bot.DaMsg import DaMsg
|
||||
|
||||
|
||||
class AuthHandler(Handler):
|
||||
|
||||
@staticmethod
|
||||
async def request_code(update, context):
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text="Введите код:")
|
||||
|
||||
return REQUEST_CODE_STEP
|
||||
|
||||
@staticmethod
|
||||
async def add_user_at_dialog(update, context):
|
||||
msg = DaMsg(update.effective_message)
|
||||
|
||||
user = client.tgBot.get_user({'token': msg.text})
|
||||
|
||||
if "error" in user:
|
||||
reply_markup = FirstStepKeyboard()
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text="Пользователь не найден. Проверте верность введенного кода.",
|
||||
reply_markup=reply_markup.create_keyboard())
|
||||
else:
|
||||
dialog = client.tgBot.set_user_at_dialog({'dialog_id': update.effective_chat.id, 'user_id': user['id']})
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text="Авторизация прошла успешно.")
|
||||
|
||||
print(user)
|
||||
return FIRST
|
31
handlers/BookingHandler.py
Normal file
31
handlers/BookingHandler.py
Normal file
@ -0,0 +1,31 @@
|
||||
from bot.Handler import Handler
|
||||
from bot import SET_DATE_STEP, SET_TABLE_STEP
|
||||
from bot.keyboards.DateToBookingKeyboard import DateToBookingKeyboard
|
||||
from bot.keyboards.GetTableListKeyboard import GetTableListKeyboard
|
||||
|
||||
|
||||
class BookingHandler(Handler):
|
||||
|
||||
@staticmethod
|
||||
def booking_vip(update, context):
|
||||
query = update.callback_query
|
||||
query.answer()
|
||||
|
||||
reply_markup = DateToBookingKeyboard()
|
||||
query.edit_message_text(
|
||||
'Выберите удобную дату:', reply_markup=reply_markup.create_keyboard()
|
||||
)
|
||||
|
||||
return SET_DATE_STEP
|
||||
|
||||
@staticmethod
|
||||
def booking_table(update, context):
|
||||
query = update.callback_query
|
||||
query.answer()
|
||||
|
||||
reply_markup = GetTableListKeyboard()
|
||||
query.edit_message_text(
|
||||
'Выберите удобный стол:', reply_markup=reply_markup.create_keyboard()
|
||||
)
|
||||
|
||||
return SET_TABLE_STEP
|
13
handlers/CopyFromMainChannelHandler.py
Normal file
13
handlers/CopyFromMainChannelHandler.py
Normal file
@ -0,0 +1,13 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class CopyFromMainChannelHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
text = "{text} \n\n {bot_link}".format(text=update.effective_message.text,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.send_message(chat_id=bot.config['NEW_MAIN_CHANNEL_ID'], text=text, parse_mode=ParseMode.HTML)
|
14
handlers/CopyFromMainChannelPhotoHandler.py
Normal file
14
handlers/CopyFromMainChannelPhotoHandler.py
Normal file
@ -0,0 +1,14 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class CopyFromMainChannelPhotoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
text = "{text} \n\n {bot_link}".format(text=update.effective_message.caption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.send_message(chat_id=bot.config['NEW_MAIN_CHANNEL_ID'], text=text, parse_mode=ParseMode.HTML)
|
14
handlers/CopyFromMainChannelVideoHandler.py
Normal file
14
handlers/CopyFromMainChannelVideoHandler.py
Normal file
@ -0,0 +1,14 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class CopyFromMainChannelVideoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
text = "{text} \n\n {bot_link}".format(text=update.effective_message.caption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.send_message(chat_id=bot.config['NEW_MAIN_CHANNEL_ID'], text=text, parse_mode=ParseMode.HTML)
|
15
handlers/CopyFromTestChannelHandler.py
Normal file
15
handlers/CopyFromTestChannelHandler.py
Normal file
@ -0,0 +1,15 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class CopyFromTestChannelHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
print(update)
|
||||
print(context)
|
||||
context.bot.copy_message(from_chat_id=update.effective_chat.id,
|
||||
chat_id=1078162189,
|
||||
message_id=update.effective_message.message_id,
|
||||
parse_mode=ParseMode.HTML)
|
25
handlers/MainChannelDaLinkHandler.py
Normal file
25
handlers/MainChannelDaLinkHandler.py
Normal file
@ -0,0 +1,25 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class MainChannelDaLinkHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.text is not None:
|
||||
text = update.effective_message.text
|
||||
s = re.search("(?P<url>https?://[^\s]+)", text)
|
||||
if s is not None:
|
||||
link = s.group("url")
|
||||
domain = urlparse(link).netloc
|
||||
if domain == bot.config['MAP_DOMAIN']:
|
||||
final_text = "{text}".format(
|
||||
text="<a href='{link}'>🗺 Смотреть на карте</a>".format(link=link))
|
||||
update.effective_message.text = final_text
|
||||
|
||||
context.bot.editMessageText(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
text=final_text, parse_mode=ParseMode.HTML)
|
17
handlers/MainChannelHandler.py
Normal file
17
handlers/MainChannelHandler.py
Normal file
@ -0,0 +1,17 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
from bot.DaMsg import DaMsg
|
||||
|
||||
|
||||
class MainChannelHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
da_msg = DaMsg(update.effective_message)
|
||||
text = "{text} \n\n {bot_link}".format(text=da_msg.stylizedText,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageText(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
text=text, parse_mode=ParseMode.HTML)
|
18
handlers/MainChannelPhotoHandler.py
Normal file
18
handlers/MainChannelPhotoHandler.py
Normal file
@ -0,0 +1,18 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
from bot.DaMsg import DaMsg
|
||||
|
||||
|
||||
class MainChannelPhotoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
da_msg = DaMsg(update.effective_message)
|
||||
text = "{text} \n\n {bot_link}".format(text=da_msg.stylizedCaption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageCaption(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
caption=text, parse_mode=ParseMode.HTML)
|
16
handlers/MainChannelVideoHandler.py
Normal file
16
handlers/MainChannelVideoHandler.py
Normal file
@ -0,0 +1,16 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class MainChannelVideoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['MAIN_CANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
text = "{text} \n\n {bot_link}".format(text=update.effective_message.caption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageCaption(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
caption=text, parse_mode=ParseMode.HTML)
|
40
handlers/SetRoleHandler.py
Normal file
40
handlers/SetRoleHandler.py
Normal file
@ -0,0 +1,40 @@
|
||||
from bot.Handler import Handler
|
||||
from db.services.ChatService import ChatService
|
||||
from bot import SET_EMAIL_STEP
|
||||
from bot.DaMsg import DaMsg
|
||||
from bot.msg.SetEmailMsg import SetEmailMsg
|
||||
|
||||
|
||||
class SetRoleHandler(Handler):
|
||||
|
||||
@staticmethod
|
||||
async def set_partner(update, context):
|
||||
chat = ChatService.get_by_chat_id(update.effective_chat.id)
|
||||
ChatService.edit(chat, "status", 20)
|
||||
|
||||
msg = SetEmailMsg(update.effective_message)
|
||||
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=msg.get_msg())
|
||||
|
||||
return SET_EMAIL_STEP
|
||||
|
||||
@staticmethod
|
||||
async def set_developer(update, context):
|
||||
chat = ChatService.get_by_chat_id(update.effective_chat.id)
|
||||
ChatService.edit(chat, "status", 10)
|
||||
|
||||
msg = SetEmailMsg(update.effective_message)
|
||||
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=msg.get_msg())
|
||||
|
||||
return SET_EMAIL_STEP
|
||||
|
||||
@staticmethod
|
||||
async def set_email(update, context):
|
||||
chat = ChatService.get_by_chat_id(update.effective_chat.id)
|
||||
msg = DaMsg(update.effective_message)
|
||||
ChatService.edit(chat, "email", msg.text)
|
||||
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text="Спасибо)")
|
||||
|
||||
return SET_EMAIL_STEP
|
16
handlers/SuperAdminHandler.py
Normal file
16
handlers/SuperAdminHandler.py
Normal file
@ -0,0 +1,16 @@
|
||||
from bot.DaMsg import DaMsg
|
||||
from bot.Handler import Handler
|
||||
from bot import config, FIRST
|
||||
from itguild_api import client
|
||||
|
||||
class SuperAdminHandler(Handler):
|
||||
|
||||
@staticmethod
|
||||
async def super_admin_text(update, context):
|
||||
if int(update.effective_chat.id) == int(config['SUPER_ADMINS']):
|
||||
all = client.tgBot.get_all()
|
||||
for user in all:
|
||||
if int(user['dialog_id']) != int(config['SUPER_ADMINS']):
|
||||
await context.bot.send_message(chat_id=user['dialog_id'], text=update.effective_message.text)
|
||||
|
||||
return FIRST
|
25
handlers/TestChannelDaLinkHandler.py
Normal file
25
handlers/TestChannelDaLinkHandler.py
Normal file
@ -0,0 +1,25 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class TestChannelDaLinkHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.text is not None:
|
||||
text = update.effective_message.text
|
||||
s = re.search("(?P<url>https?://[^\s]+)", text)
|
||||
if s is not None:
|
||||
link = s.group("url")
|
||||
domain = urlparse(link).netloc
|
||||
if domain == bot.config['MAP_DOMAIN']:
|
||||
final_text = "{text}".format(
|
||||
text="<a href='{link}'>🗺 Смотреть на карте</a>".format(link=link))
|
||||
update.effective_message.text = final_text
|
||||
|
||||
context.bot.editMessageText(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
text=final_text, parse_mode=ParseMode.HTML)
|
19
handlers/TestChannelHandler.py
Normal file
19
handlers/TestChannelHandler.py
Normal file
@ -0,0 +1,19 @@
|
||||
import emoji
|
||||
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
from bot.DaMsg import DaMsg
|
||||
|
||||
|
||||
class TestChannelHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
da_msg = DaMsg(update.effective_message)
|
||||
text = "{text} \n\n {bot_link}".format(text=da_msg.stylizedText,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageText(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
text=text, parse_mode=ParseMode.HTML)
|
18
handlers/TestChannelPhotoHandler.py
Normal file
18
handlers/TestChannelPhotoHandler.py
Normal file
@ -0,0 +1,18 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
from bot.DaMsg import DaMsg
|
||||
|
||||
|
||||
class TestChannelPhotoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
da_msg = DaMsg(update.effective_message)
|
||||
text = "{text} \n\n {bot_link}".format(text=da_msg.stylizedCaption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageCaption(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
caption=text, parse_mode=ParseMode.HTML)
|
16
handlers/TestChannelVideoHandler.py
Normal file
16
handlers/TestChannelVideoHandler.py
Normal file
@ -0,0 +1,16 @@
|
||||
from bot.DaHandler import DaHandler
|
||||
from telegram import ParseMode
|
||||
import bot
|
||||
|
||||
|
||||
class TestChannelVideoHandler(DaHandler):
|
||||
|
||||
def handler(self, update, context):
|
||||
if bot.config['TEST_CHANNEL_ID'] == str(update.effective_chat.id):
|
||||
if update.effective_message.caption is not None:
|
||||
text = "{text} \n\n {bot_link}".format(text=update.effective_message.caption,
|
||||
bot_link="👉 <a href='https://t.me/prosmi_bot'>Предложить новость</a>")
|
||||
|
||||
context.bot.editMessageCaption(chat_id=update.effective_chat.id,
|
||||
message_id=update.effective_message.message_id,
|
||||
caption=text, parse_mode=ParseMode.HTML)
|
Reference in New Issue
Block a user