async def react(m: MessageEvent): """ Reacts to callback buttons """ logging.info( f'{m.object.user_id}[{m.object.peer_id}] PAYLOAD {m.object.payload}') pl = m.object.payload p_id = m.object.peer_id e = None # Event data u = await get_user( p_id ) # Cannot be None since user gets keyboard after being added to local database g = None if u is None: e = await sb_builder( '❗ Зарегистрируйтесь.\nКоманда со списком групп: /группы') await bp.api.messages.send_message_event_answer( m.object.event_id, m.object.user_id, m.object.peer_id, e) stats.cincr() return elif u.is_banned: return g = u.group_peer_id # Just to make things shorter if pl == bt_cl_td.payload: await bp.api.messages.send(peer_id=m.object.peer_id, message=classes.get_classes(g, as_list=False), random_id=0) # Random ID can be 0 for bots elif pl == bt_cl_tmrw.payload: await bp.api.messages.send(peer_id=m.object.peer_id, message=classes.get_classes(g, 1, as_list=False), random_id=0) elif pl == bt_cl_now.payload: e = await sb_builder(classes.get_class(g)) elif pl == bt_cl_next.payload: e = await sb_builder(classes.get_class(g, 1)) elif pl == bt_week.payload: e = await sb_builder(classes.get_cur_week_text()) elif pl == bt_timetable.payload: e = await sb_builder(classes.time_to_next(g)) elif pl == bt_exam.payload: e = await sb_builder(await exams.get_next_exam(m.object.peer_id, 1)) await bp.api.messages.send_message_event_answer(m.object.event_id, m.object.user_id, m.object.peer_id, e) stats.cincr()
def test_get_after_classes(self): """ Must return no classes """ result = get_class(p=0, custom_time=[17, 51], custom_day=self.custom_day) self.assertEqual(result, '❌ Больше пар нет')
def test_get_last_class(self): """ Must return last class (6th) """ result = get_class(p=0, custom_time=[17, 40], custom_day=self.custom_day) self.assertEqual(result[2:], 'Пара 6 (в 16:30):\n71')
def test_get_third_class(self): """ Must return 3rd class """ result = get_class(p=0, custom_time=[13, 00], custom_day=self.custom_day) self.assertEqual(result[2:], 'Пара 3 (в 12:00):\n41')
def test_get_class_after_second_class_during_break(self): """ Must return 3rd class """ result = get_class(p=0, custom_time=[11, 51], custom_day=self.custom_day) self.assertEqual(result[2:], 'Пара 3 (в 12:00):\n41')
def test_get_first_class(self): """ Must return 1st class """ result = get_class(p=0, custom_time=[9, 15], custom_day=self.custom_day) self.assertEqual(result[2:], 'Пара 1 (в 9:00):\n21')
def test_get_next_class_after_last(self): """ Must return no classes """ result = get_class( p=0, modifier=1, custom_time=[17, 51], # Last class has just ended custom_day=self.custom_day) self.assertEqual(result, '❌ Больше пар нет')
def test_get_next_class_after_first(self): """ Must return 3rd class """ result = get_class( p=0, modifier=1, custom_time=[10, 21], # Time is 10:21, 1st class has just ended custom_day=self.custom_day) self.assertEqual(result[2:], 'Пара 3 (в 12:00):\n41')
def test_get_next_class_before_first(self): """ Must return 2nd class """ result = get_class(p=0, modifier=1, custom_time=[8, 59], custom_day=self.custom_day) # Everything before first class start time is first class. # If it's 8:59, but 1st class starts at 9:00 it still counts as 1st class self.assertEqual(result[2:], 'Пара 2 (в 10:30):\n31')
def test_get_next_class_last(self): """ Must return last class message """ result = get_class( p=0, modifier=1, custom_time=[ 17, 49 ], # It's last class for today, so nothing comes after it custom_day=self.custom_day) self.assertEqual(result, '❌ Сейчас последняя пара, дальше ничего нет')
async def send_class_next(ans: Message): """ Send next class """ await ans.answer( classes.get_class((await get_user(ans.peer_id)).group_peer_id, 1))
async def send_class_now(ans: Message): """ Send current class """ await ans.answer( classes.get_class((await get_user(ans.peer_id)).group_peer_id))