def handle_hometown(self, bot: Bot, update: Update, user_data): message = update.message # type: Message if message.location: hometown = get_city(message.location.latitude, message.location.longitude) else: hometown = message.text user = User.update_or_create( attributes={"telegram_user_id": message.from_user.id}, values={ "telegram_username": message.from_user.username, "hometown": hometown }) text = "Okay. Du wohnst in <strong>%s</strong>.\n\n" % hometown opportunities = Opportunity.for_city(user.hometown) if opportunities.count() == 0: text += "Aktuell sind keine Bestellmöglichkeiten verfügbar. Ich werde dich benachrichtigen, wenn es soweit ist." else: text += "@marudor kommt an folgenden Tagen in deine Stadt:\n" for op in opportunities: text += "<strong>%s</strong>: Bestelle mit /order_%s\n" % ( op.date.strftime("%d.%m.%Y"), op.id) if "new_user" in user_data: del user_data["new_user"] text += self.generate_command_intro() update.message.reply_text(text, parse_mode=ParseMode.HTML, reply_markup=ReplyKeyboardRemove()) return self.END
def start_existing_user(self, bot: Bot, update: Update, user): t_user = update.effective_user opportunities = Opportunity.for_city(user.hometown) if t_user.username: text = "Willkommen zurück, @%s\n\n" % t_user.username else: text = "Willkommen zurück.\n\n" if opportunities.count() > 0: text += "@marudor kommt an folgenden Tagen in deine Stadt:" else: text += "@marudor hat keine Besuche in <strong>%s</strong> für die nächste Zeit geplant." % user.hometown for op in opportunities: text += "\n%s - Bestelle mit /order_%u" % ( op.date.strftime("%d.%m.%Y"), op.id) text += self.generate_command_intro() update.message.reply_text(text, parse_mode=ParseMode.HTML) return self.END