import app import command_interface as commands from schedule_tools import get_schedule def today_default_command(message): chat_id = message['message']['chat']['id'] if not app.db.schedules.users_groups.count_documents({'chat_id': chat_id}): return 'Set your study group (//setgroup)' return get_schedule( app.db.schedules.date.find_one({'name': 'curr_day'})['curr_day'], app.db.schedules.date.find_one({'name': 'curr_week'})['curr_week'], app.db.schedules.users_groups.find_one({'chat_id': chat_id})['group']) today_default = commands.Command() today_default.description = "get today's schedule for your group" today_default.keys = [r'/today\s*'] today_default.handle = today_default_command
import app import command_interface as commands from schedule_tools import get_schedule def tomorrow_default_command(message): chat_id = message['message']['chat']['id'] if not app.db.schedules.users_groups.count_documents({'chat_id': chat_id}): return 'Set your study group (//setgroup)' day = (app.db.schedules.date.find_one({'name': 'curr_day'})['curr_day'] + 1) % 7 week = ( app.db.schedules.date.find_one({'name': 'curr_week'})['curr_week'] + (day == 0)) % 4 + (day == 0) return get_schedule( day, week, app.db.schedules.users_groups.find_one({'chat_id': chat_id})['group']) tomorrow_default = commands.Command() tomorrow_default.description = "get tomorrow's schedule for your group" tomorrow_default.keys = [r'/tomorrow\s*'] tomorrow_default.handle = tomorrow_default_command
import app import command_interface as commands from schedule_tools import get_schedule def today_command(message): group_number = message['message']['text'].split()[-1] return get_schedule( app.db.schedules.date.find_one({'name': 'curr_day'})['curr_day'], app.db.schedules.date.find_one({'name': 'curr_week'})['curr_week'], group_number) today = commands.Command() today.description = "get today's schedule for group_number" today.keys = [r'/today +\d+\s*'] today.handle = today_command
import time import command_interface as commands def ping_command(message): return 'pong ({} ms)'.format( int((time.time() - message['message']['date']) * 1e3)) ping = commands.Command() ping.description = 'get ping' ping.keys = [r'/ping\s*'] ping.handle = ping_command
import app import command_interface as commands def setgroup_command(message): chat_id = message['message']['chat']['id'] group_number = message['message']['text'].split()[-1] if not app.db['schedules']['groups'].count_documents({'name': group_number}): return 'Incorrect group number' # if not app.db['schedules']['users_groups'].find({'chat_id': chat_id}): # app.db['schedules']['users_groups'].insert_one({ # 'char_id' : chat_id, # 'group' : group_number # }) # else: app.db['schedules']['users_groups'].update_one( {'chat_id': chat_id}, {'$set':{'group': group_number}}, upsert=True ) return 'Set successfully' setgroup = commands.Command() setgroup.description = 'set your study group' setgroup.keys = [r'/setgroup \d+\s*'] setgroup.handle = setgroup_command
import app import command_interface as commands from schedule_tools import get_schedule def tomorrow_command(message): group_number = message['message']['text'].split()[-1] day = (app.db.schedules.date.find_one({'name': 'curr_day'})['curr_day'] + 1) % 7 week = ( app.db.schedules.date.find_one({'name': 'curr_week'})['curr_week'] + (day == 0)) % 4 + (day == 0) return get_schedule(day, week, group_number) tomorrow = commands.Command() tomorrow.description = "get tomorrow's schedule for group_number" tomorrow.keys = [r'/tomorrow +\d+\s*'] tomorrow.handle = tomorrow_command