def _set_iksm_session(self, context, iksm_session, update_message_id=None): message = Message(context) first_set = True if context.message.chat.type != 'private': context.send_message(message.setsession_must_private_message) return sp2_user = Splatoon2(iksm_session).get_user() if not sp2_user: context.send_message(message.setsession_set_fail) return user = context.user if user and user.iksm_session != None: first_set = False user.iksm_session = iksm_session user.sp2_user = sp2_user.player if first_set: store.insert_user(user) else: store.update_user(user) if first_set: message_content = message.setsession_set_success else: message_content = message.setsession_update_success if update_message_id: context.edit_message(message_content, update_message_id) else: context.send_message(message_content)
def wrapper(self, update, context, **optional_args): if not update.message: return bot_context = BotContext(update, context) user = bot_context.user if user and user.iksm_session: if not user.sp2_user: sp2_user = Splatoon2(user.iksm_session).get_user() if not sp2_user: bot_context.send_message( Message(bot_context).session_invalid) return user.sp2_user = sp2_user.player store.update_user(user) if optional_args: return func(self, bot_context, **optional_args) else: return func(self, bot_context) else: bot_context.send_message(Message(bot_context).session_invalid)
def wrapper(self, update, context): if not update.message: return bot_context = BotContext(update, context) store.update_user(bot_context.user) return func(self, bot_context)
def _all_user_keep_alive(self, context: CallbackContext): all_users = store.select_all_users() for user in all_users: if not user.iksm_session or user.iksm_session == '': continue # Get last battle detail try: splatoon2 = Splatoon2(user.iksm_session) _ = splatoon2.get_battle_overview() except Splatoon2SessionInvalid: user.iksm_session = '' store.update_user(user) continue except: continue