|
|
@ -1,4 +1,5 @@ |
|
|
|
from datetime import date |
|
|
|
from datetime import date |
|
|
|
|
|
|
|
from telebot.types import CallbackQuery, Message |
|
|
|
|
|
|
|
|
|
|
|
from bot import Bot |
|
|
|
from bot import Bot |
|
|
|
from community import Community |
|
|
|
from community import Community |
|
|
@ -6,7 +7,7 @@ from community import Community |
|
|
|
|
|
|
|
|
|
|
|
def views(bot: Bot): |
|
|
|
def views(bot: Bot): |
|
|
|
@bot.handle_commands(['/start']) |
|
|
|
@bot.handle_commands(['/start']) |
|
|
|
def handle_start(msg, user, args): |
|
|
|
def handle_start(msg: Message, user, args): |
|
|
|
if msg.chat.type in 'supergroup': |
|
|
|
if msg.chat.type in 'supergroup': |
|
|
|
bot.reply_with_template(msg, 'welcome', community=Community.by_id(msg.chat.id, bot)) |
|
|
|
bot.reply_with_template(msg, 'welcome', community=Community.by_id(msg.chat.id, bot)) |
|
|
|
return |
|
|
|
return |
|
|
@ -20,6 +21,7 @@ def views(bot: Bot): |
|
|
|
bot.poll_user_for_community(user, community) |
|
|
|
bot.poll_user_for_community(user, community) |
|
|
|
else: |
|
|
|
else: |
|
|
|
bot.reply_with_template(msg, 'err_not_a_member', community=community) |
|
|
|
bot.reply_with_template(msg, 'err_not_a_member', community=community) |
|
|
|
|
|
|
|
bot.save_community(community) |
|
|
|
bot.reply_with_template(msg, 'info', start=True) |
|
|
|
bot.reply_with_template(msg, 'info', start=True) |
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_commands(['/help', 'ℹ️ About', 'ℹ️ О боте']) |
|
|
|
@bot.handle_commands(['/help', 'ℹ️ About', 'ℹ️ О боте']) |
|
|
@ -27,7 +29,7 @@ def views(bot: Bot): |
|
|
|
bot.reply_with_template(msg, 'info', start=False) |
|
|
|
bot.reply_with_template(msg, 'info', start=False) |
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_commands(['/request', '📝 Request a meeting', '📝 Запросить встречу']) |
|
|
|
@bot.handle_commands(['/request', '📝 Request a meeting', '📝 Запросить встречу']) |
|
|
|
def request_meeting(msg, user, _args): |
|
|
|
def request_meeting(msg: Message, user, _args): |
|
|
|
if msg.chat.type != 'private': |
|
|
|
if msg.chat.type != 'private': |
|
|
|
bot.reply_with_template(msg, 'err_not_private') |
|
|
|
bot.reply_with_template(msg, 'err_not_private') |
|
|
|
return |
|
|
|
return |
|
|
@ -35,7 +37,7 @@ def views(bot: Bot): |
|
|
|
bot.reply_with_template(msg, 'request_meeting', comm_list=comm_ids_and_names) |
|
|
|
bot.reply_with_template(msg, 'request_meeting', comm_list=comm_ids_and_names) |
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_commands(['/join']) |
|
|
|
@bot.handle_commands(['/join']) |
|
|
|
def join_community(msg, user, args): |
|
|
|
def join_community(msg: Message, user, args): |
|
|
|
# check if it really is a community |
|
|
|
# check if it really is a community |
|
|
|
if msg.chat.type == 'private': |
|
|
|
if msg.chat.type == 'private': |
|
|
|
bot.reply_with_template(msg, 'err_not_community') |
|
|
|
bot.reply_with_template(msg, 'err_not_community') |
|
|
@ -45,15 +47,31 @@ def views(bot: Bot): |
|
|
|
bot.reply_with_template(msg, 'welcome', community=community, join=True) |
|
|
|
bot.reply_with_template(msg, 'welcome', community=community, join=True) |
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_callback('request_meeting') |
|
|
|
@bot.handle_callback('request_meeting') |
|
|
|
def request_meeting_callback(msg, user, args): |
|
|
|
def request_meeting_callback(query: CallbackQuery, user, args): |
|
|
|
community = Community.by_id(int(args), bot) |
|
|
|
community = Community.by_id(int(args), bot) |
|
|
|
if community.can_user_request_a_meeting(user.user_id): |
|
|
|
if community.can_user_request_a_meeting(user.user_id): |
|
|
|
community.polled[user.user_id] = date.today() |
|
|
|
community.polled[user.user_id] = date.today() |
|
|
|
community.pool.append(user.user_id) |
|
|
|
community.pool.append(user.user_id) |
|
|
|
bot.reply_with_template(msg, 'request_meeting_success', community=community) |
|
|
|
bot.reply_with_template(query, 'request_meeting_success', community=community) |
|
|
|
else: |
|
|
|
else: |
|
|
|
bot.reply_with_template(msg, 'request_meeting_failure', community=community) |
|
|
|
bot.reply_with_template(query, 'request_meeting_failure', community=community) |
|
|
|
bot.answer_callback_query(msg.id) |
|
|
|
bot.answer_callback_query(query.id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_callback('dismiss') |
|
|
|
|
|
|
|
def dismiss_callback(query: CallbackQuery, user, _args): |
|
|
|
|
|
|
|
bot.answer_callback_query(query.id, {'en': 'Ok, fine', 'ru': 'ладно'}.get(user.locale, 'Ok')) |
|
|
|
|
|
|
|
bot.delete_message(query.message.chat.id, query.message.message_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_callback('community_add') |
|
|
|
|
|
|
|
def community_add_callback(query: CallbackQuery, user, args): |
|
|
|
|
|
|
|
community = Community.by_id(int(args), bot) |
|
|
|
|
|
|
|
if user.user_id in community.members: |
|
|
|
|
|
|
|
bot.reply_with_template(query, 'community_added', community=community, already_member=True) |
|
|
|
|
|
|
|
elif community.add_member(user.user_id, bot): |
|
|
|
|
|
|
|
bot.reply_with_template(query, 'community_added', community=community, already_member=False) |
|
|
|
|
|
|
|
bot.poll_user_for_community(user, community) |
|
|
|
|
|
|
|
bot.answer_callback_query(query.id) |
|
|
|
|
|
|
|
bot.save_community(community) |
|
|
|
|
|
|
|
|
|
|
|
@bot.handle_commands(['/send_all']) |
|
|
|
@bot.handle_commands(['/send_all']) |
|
|
|
def send_spam(msg, user, _args): |
|
|
|
def send_spam(msg, user, _args): |
|
|
|