def morning_check(): CHANNEL = '#space_realtime' shift = schedule.current_shift() if not shift.watchman: # no watchman in schedule, that's weird but whatever return member: Member = shift.watchman.member cm_customers = kocherga.cm.tools.now_stats()['customers'] for customer in cm_customers: if customer.pk == member.cm_customer.pk: logger.info( f'Watchman {member.cm_customer} is present, everything is ok') return inflected = 'готов' if member.gender == 'MALE' else 'готова' bot.send_message( text=f":exclamation: <@{member.slack_id}>, тебя нет в кафе-менеджере.\n" f"Видимо, ты опаздываешь на свою смену. Будь {inflected} ответить на звонок.", channel=CHANNEL, )
def react_send_salaries(message): if not can_pay_salaries(message): message.reply("У вас нет прав на просмотр и выплату зарплат.") return salaries: SalaryContainer = kocherga.money.salaries.calculate_new_salaries( ) kocherga.money.salaries.salaries_to_payments(salaries) bot.send_message(channel=SALARIES_CHANNEL, **salaries_message(salaries))
def send_daily_tasks(): tasks = list(Task.objects.today_tasks()) if not tasks: return channels = set(task.channel for task in tasks) for channel in channels: bot.send_message( text="Таски на сегодня:", channel="#" + channel, attachments=[ task_attachment(task) for task in tasks if task.channel == channel ], )
def roster_check(): # We have a reason to panic if either of the following is true: # - at least 1 empty shift in the next CRITICAL_DAYS days # - at least SHIFTS_THRESHOLD empty shifts in the next TOTAL_DAYS days CRITICAL_DAYS = 2 SHIFTS_THRESHOLD = 6 TOTAL_DAYS = 7 CHANNEL = '#space_staff_shifts' today = datetime.now(TZ).date() d = today empty_total = 0 critical_sent = False while d < today + timedelta(days=TOTAL_DAYS): empty_for_day = 0 day_schedule = schedule.shifts_by_date(d) for shift_type in sorted(day_schedule.keys()): shift = day_schedule[shift_type] if not shift.watchman and not shift.is_night: empty_for_day += 1 if (empty_for_day and d <= today + timedelta(days=CRITICAL_DAYS) and not critical_sent): bot.send_message( text= f":exclamation: Есть пустые смены в ближайшие {CRITICAL_DAYS} дня.", channel=CHANNEL, ) critical_sent = True empty_total += empty_for_day d += timedelta(days=1) if empty_total >= SHIFTS_THRESHOLD: bot.send_message( text= f":exclamation: {empty_total} пустых смен в ближайшие {TOTAL_DAYS} дней.", channel=CHANNEL, )
def morning_events_notification(): bot.send_message(**kocherga.ludwig.watchmen.today_watchmen(), channel="#space_realtime") bot.send_message(**kocherga.ludwig.watchmen.today_watchmen(), channel="#space_bot") bot.send_message(**kocherga.ludwig.events.list_events(), channel="#space_bot")
def ask_for_event_visitors(): logger.debug("ask_for_event_visitors") events = Event.objects.filter(start__gt=datetime.now(TZ) - timedelta(days=1)).all() logger.debug(f"Total events: {len(events)}") events = [ e for e in events if not (e.visitors # already entered or e.asked_for_visitors # already asked or datetime.now(tz=TZ) < e.start + timedelta(minutes=30) # event haven't started yet, let's wait ) ] logger.info(f"Events we should ask about: {len(events)}") if not len(events): return # nothing to ask about for e in events: e.asked_for_visitors = datetime.now(TZ) bot.send_message(**event_visitors_question(e)) e.save()