def store_lang(update, context, query): lang_code = LANGUAGES[query.data] with client.transaction(): user_key = client.key(USER, query.from_user.id) user = client.get(key=user_key) user[LANGUAGE] = lang_code client.put(user) context.user_data[LANGUAGE] = lang_code _ = set_lang(update, context) query.message.edit_text(_("Your language has been set to {}").format(query.data))
def update_stats(update, task): user_key = client.key(USER, update.effective_message.from_user.id) with client.transaction(): user = client.get(key=user_key) if user is None: user = datastore.Entity(user_key) user[task] = 1 else: if task in user: user[task] += 1 else: user[task] = 1 client.put(user)
def get_lang(update, context, query=None): if context.user_data is not None and LANGUAGE in context.user_data: lang = context.user_data[LANGUAGE] else: if query is None: user_id = update.effective_message.from_user.id else: user_id = query.from_user.id user_key = client.key(USER, user_id) user = client.get(key=user_key) if user is None or LANGUAGE not in user: lang = "en_GB" else: lang = user[LANGUAGE] if lang == "en": lang = "en_GB" context.user_data[LANGUAGE] = lang return lang