def send_lotery_message(state_id, department_type, language, amount): """Send lotery message""" LOGGER.info('"%s": Send lotery message for "%s" department', state_id, department_type) yesterday_professors = database.get_yesterday_professors( state_id, department_type) professor_count = len(yesterday_professors) random_index = random.randint(0, professor_count) - 1 winning_professor = yesterday_professors[random_index] winner = winning_professor.player winner_name = re.sub(r'\[.*]\s', '', winner.name) amount_of_points = database.get_amount_of_points(state_id, department_type, winner.id) LOGGER.info('"%s": candidates "%s", winner "%s" with "%s" points', state_id, professor_count, winner_name, amount_of_points) tg_message = '. '.join([ "The daily department lotery is won by: {:}".format(winner_name), "With {:} points you won $ {:,.0f}".format( amount_of_points, amount_of_points * amount).replace(',', '.'), "Send @bergjnl a message to receive your price.", ]) print(tg_message) TELEGRAM_BOT.sendMessage(chat_id='@vn_lottery', text=tg_message) rr_message = '. '.join([ "De department loterij is gewonnen door: {:}".format(winner_name), "Met {:} punten heb je $ {:,.0f} gewonnen".format( amount_of_points, amount_of_points * amount).replace(',', '.'), "Stuur me een bericht om de prijs te ontvangen.", ]) print(rr_message) api.send_message(language, rr_message)
def run_dialog(commands, main, add, i, dialog_id): # OLD VERSION with app.app_context(): main_account = api.get_sessions(main) add_accounts = api.get_sessions(add) for step, row in enumerate(commands): d = get_dialog_by_id(dialog_id)[0] if not d[7]: print('STOP') return False latency = int(row[1]) msg = row[2] sleep(latency) # If sender is main account session = main_account[0] who = add_accounts[i][1] # If sender is an addition account if int(row[0]) == 2: session = add_accounts[i][0] who = main_account[1] msg, forward, photo = api.get_attachments(session, msg) update_dialog_step(dialog_id, step) print(who, msg, photo, forward) api.send_message(session, who, msg, photo, forward)
def run_dialog(commands, main, add, dialog_id): # NEW VERSION with app.app_context(): for step, row in enumerate(commands): d = get_dialog_by_id(dialog_id)[0] if not d[7]: print('STOP') return False # message aka `row` format: <priority>[<latency>]=<message> # <priority>: in message `main` associated with number 1, `add` with number 2 # <latency>: the pause to wait # <message>: the message itself msg = row[2] sleep(int(row[1])) # main[0] or add[0] is the `session`, by `session` the message is sended # main[1] or add[1] is the `id`, the message is sent to a particular `id`, like in `pyTelegramBotApi` # `if row[0] == '2'`: in commands `main` associated with number 1, `add` with number 2 if row[0] == '2': session = add[0] who = main[1] else: session = main[0] who = add[1] session = add[0] if row[0] == '2' else main[0] who = main[1] if row[0] == '2' else add[1] msg, forward, photo = api.get_attachments(session, msg) update_dialog_step(dialog_id, step) api.send_message(session, who, msg, photo, forward)
def do_second(rows, acc1, accs2, i): for row in rows: latency = int(row[1]) msg = row[2] # If sender is main account session = acc1[0] who = accs2[i][1] # If sender is an addition account if int(row[0]) == 2: session = accs2[i][0] who = acc1[1] sleep(latency) msg, forward, photo = api.get_attachments(session, msg) api.send_message(session, who, msg, photo, forward)
def send_progress_message(state_id, department_type, language): """Update department professors""" LOGGER.info('"%s": Send progress message for "%s" department', state_id, department_type) yesterday_professors = database.get_yesterday_professors( state_id, department_type) if not yesterday_professors: LOGGER.warning('"%s": 0 professor yesterday in "%s" department', state_id, department_type) return yesterday_total = 0 for professor in yesterday_professors: yesterday_total += professor.points institutes = api.get_institutes() uranium_institutes = [] for institute in institutes: if institute['department_type'] == department_type: uranium_institutes.append(institute) if institute['state_id'] == state_id: state_institute = institute top_department = uranium_institutes[0] top_value = math.ceil(top_department['value'] / 10) * 10 points_per_day = round(top_value / 14) msg_current = "Huidige uranium bonus is {} % met {} punten.".format( state_institute['current_bonus'], state_institute['value']) if state_institute['current_bonus'] == 10: msg_required = "Dagelijks zijn er {} punten nodig.".format( points_per_day) else: msg_required = \ "Benodigde punten voor 10 % bonus: {} wat dagelijks {} punten zijn.".format( top_value, points_per_day ) msg_yesterday = \ "Aantal punten gisteren: {}, wat {} % van de benodigde aantal punten is.".format( yesterday_total, round(100 / points_per_day * yesterday_total) ) message = ' '.join([msg_current, msg_required, msg_yesterday]) print(message) api.send_message(language, message)