def notifications(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = ("❗ Argument must be 1 or -1, " "e.g. /notifications 1, /notifications -1") if context.args: try: value = int(context.args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if abs(value) == 1: if value == -1: db.unset_notifications(uid) value = "disabled" else: db.set_notifications(uid) value = "enabled" msg = ut.text_format("Current notifications status", value) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: status = ('enabled' if db.get_notifications(uid) == 1 else 'disabled') msg = ut.text_format("Current notifications status", status) db.dec_strikes(uid) ut.send(update, msg)
def _timezone(args, uid, msg): try: datetime.strptime(args[0], "%H:%M") except ValueError: try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1: db.unset_timezone(uid) msg = ut.text_format("Current timezone", "disabled") db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: hour, minutes = map(int, args[0].split(':')) bot_hour, bot_minutes = map( int, datetime.now().strftime("%H:%M").split(':')) tz_hour = hour - bot_hour tz_minutes = minutes - bot_minutes db.set_timezone(uid, tz_hour, tz_minutes) tz = ut.normalize_timezone(tz_hour, tz_minutes) msg = ( f"{ut.text_format('Bot hour', f'{bot_hour:02}:{bot_minutes:02}')}\n\n" # noqa f"{ut.text_format('Current timezone', f'{tz}')}") db.dec_strikes(uid) return msg
def train_screen(): global menu font = util.get_font("titles") font2 = util.get_font("normal") text_wait, wait_rect =\ util.text_format("WAIT", font, 75, util.white) text_wait2, wait_rect2 =\ util.text_format("Training model....", font2, 35, util.white) text_wait3, wait_rect3 =\ util.text_format("Using backend: BigML", font2, 20, util.white) while menu == util.TRAINING_SCREEN: screen.fill(util.blue) screen.blit(text_wait, (util.WIDTH / 2 - (wait_rect[2] / 2), 60)) screen.blit(text_wait2, (util.WIDTH / 2 - (wait_rect2[2] / 2), 220)) screen.blit(text_wait3, (util.WIDTH / 2 - (wait_rect3[2] / 2), 270)) pygame.display.update() clock.tick(util.FPS)
def _refill(args, uid, msg, current, max_resin): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < max_resin: db.inc_resin(uid, value) msg = ut.text_format("Current resin", current + value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _spend(args, uid, msg, current): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < current: db.dec_resin(uid, value) msg = ut.text_format("Current resin", current - value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _set_resin(args, uid, msg): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < ut.RESIN_MAX: db.set_resin(uid, value) msg = ut.text_format("Current resin", value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _warnings(args, uid, msg): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1 or 0 < value < ut.RESIN_MAX: if value == -1: value = "disabled" db.unset_warn(uid) else: db.set_warn(uid, value) msg = ut.text_format("Current warning threshold", value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _track(args, bot, uid, msg): try: datetime.strptime(args[0], "%M:%S") except ValueError: try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1: th.del_thread(uid) msg = ut.text_format("Current tracking status", "disabled") db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: minutes, seconds = map(int, args[0].split(':')) timer = minutes * 60 + seconds th.new_thread(bot, uid, timer) msg = "Bot timer synchronized." db.dec_strikes(uid) return msg
def game_menu(game): global menu # Selected menu option selected = util.SELECTED_AUTO font = util.get_font("titles") pygame.display.set_caption("Pygame ML games") while menu == util.MENU_PONG or menu == util.MENU_RACING: for event in pygame.event.get(): menu, selected = games_menu_event(event, menu, selected, game) # Menu options text screen.fill(util.blue) title, title_rect =\ util.text_format(util.GAME_NAMES[game], font, 80, util.yellow) text_auto, auto_rect =\ util.text_format("Auto Play", font, 75, util.black) text_train, start_rect =\ util.text_format("Train again", font, 75, util.black) text_quit, quit_rect =\ util.text_format("Back to menu", font, 75, util.black) # Selected menu option in white if selected == util.SELECTED_AUTO: text_auto, auto_rect =\ util.text_format("Auto Play", font, 75, util.white) if selected == util.SELECTED_TRAIN: text_train, start_rect =\ util.text_format("Train again", font, 75, util.white) if selected == util.SELECTED_BACK: text_quit, quit_rect =\ util.text_format("Back to menu", font, 75, util.white) # Draws text screen.blit(title, (util.WIDTH / 2 - (title_rect[2] / 2), 80)) screen.blit(text_auto, (util.WIDTH / 2 - (auto_rect[2] / 2), 230)) screen.blit(text_train, (util.WIDTH / 2 - (start_rect[2] / 2), 290)) screen.blit(text_quit, (util.WIDTH / 2 - (quit_rect[2] / 2), 350)) pygame.display.update() clock.tick(util.FPS)
def main_menu(): global menu selected = util.SELECTED_PONG # Menu selected option pygame.display.set_caption("Pygame ML games") while menu == util.MENU_MAIN: # Check events for event in pygame.event.get(): menu, selected = main_menu_event(event, pygame, menu, selected) # Main Menu UI screen.fill(util.blue) font = util.get_font("titles") # Menu options text title, title_rect =\ util.text_format("Pygame ML games", font, 80, util.yellow) text_pong, pong_rect =\ util.text_format("Pong", font, 75, util.black) text_racing, racing_rect =\ util.text_format("Racing", font, 75, util.black) text_quit, quit_rect =\ util.text_format("Quit", font, 75, util.black) # Selected menu option in white if selected == util.SELECTED_PONG: text_pong, pong_rect =\ util.text_format("Pong", font, 75, util.white) elif selected == util.SELECTED_RACING: text_racing, racing_rect =\ util.text_format("Racing", font, 75, util.white) elif selected == util.SELECTED_QUIT: text_quit, quit_rect =\ util.text_format("Quit", font, 75, util.white) # Draw all texts screen.blit(title, (util.WIDTH / 2 - (title_rect[2] / 2), 80)) screen.blit(text_pong, (util.WIDTH / 2 - (pong_rect[2] / 2), 220)) screen.blit(text_racing, (util.WIDTH / 2 - (racing_rect[2] / 2), 290)) screen.blit(text_quit, (util.WIDTH / 2 - (quit_rect[2] / 2), 360)) pygame.display.update() clock.tick(util.FPS)