def welcome(message): new_frichtle = Frichtle.from_json({ "user_id": message.from_user.id, "admin": False, "master": False, "name": "Neuling", "username": message.from_user.username }) if new_frichtle.user_id == meta.lucas_user_id: new_frichtle.admin = True new_frichtle.master = True if new_frichtle.username is not None: text = 'Willkommen @{} beim Frichtle Bot!'.format( new_frichtle.username) else: text = "Willkommen beim Frichtle Bot!" bot.reply_to(message, text) db.add_frichtle(new_frichtle) msg = bot.send_message( message.chat.id, text= "Bitte gib deinen Namen, unter dem dich die anderen erkennen: 😉", ) bot.register_next_step_handler(msg, process_name_reply)
def f040(message): t = message.text t = t.replace("exec", "").strip() try: for table in ["frichtle", "events", "surveys"]: if t[:len(table)] == table: file_name = f"vault/{table}.json" with open(file_name, "r") as f: exec(f"{table} = json.load(f)") exec(t.replace(",", "\"")) with open(file_name, "w") as f: exec(f"json.dump({table}, f, indent=4)") bot.reply_to(message, text="Successful.") break else: exec(t) except Exception as e: bot.reply_to(message, text=str(e))
def show_instrument(message): instrument = get_instrument(message.from_user.id) if instrument == 'Passiv': text = 'Du bist passives Mitglied.' else: text = 'Du spielst {}'.format(instrument) bot.reply_to(message, text)
def request_id_event_reminder(message): events = events_that_need_reminder() if events: bot.send_message( message.chat.id, text= "Bitte wähle eine Event ID für die du einen Reminder verschicken möchstes " "(Mehrfachwahl möglich):", reply_markup=markups.inline.ask_for_event( command="remind_which_event", events=events)) else: bot.reply_to(message, text="Es stehen keine Rückmeldungen aus.")
def show_users(message, reply=True): frichtle = get_frichtle() if not isinstance(frichtle, list): frichtle = [frichtle] s = "" for f in frichtle: s += f.get_inline_str() if f.master: s += " (Master)" elif f.admin: s += " (Admin)" s += "\n" if reply: bot.reply_to(message, s) else: bot.send_message(message.chat.id, text=s)
def process_command(message): if message.text == "0": bot.send_message(message.chat.id, text="Command Eingabe beendet.", reply_markup=markups.menu.master()) return elif message.text == "hints": bot.send_message(message.chat.id, text=meta.sql_command_hints) else: success, res = execute_sql_command(message.text) if success: if res: text = res else: text = "<NO RETURN VALUE>" bot.reply_to(message, text=text) else: bot.reply_to(message, text="ERROR: " + res) sql_command(message)
def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs): if inline_message: user_id = inline_message.chat.id else: user_id = (initial_message or user_message or call).from_user.id if call: inline_message = call.message surveys = util.database.get_survey() if len(surveys) == 0: bot.reply_to(initial_message, text="Es gibt keine Umfragen.") return if 'survey_id' not in kwargs.keys(): text = "Wähle eine Umfrage aus, die du schließen möchtest:" markup = InlineKeyboardMarkup(row_width=1) buttons = list( InlineKeyboardButton(text=s.get_inline_str(), callback_data=self.command + json.dumps({'survey_id': s.survey_id})) for s in surveys) markup.add(*tuple(buttons)) markup.add(InlineKeyboardButton("Abbrechen", callback_data="abort")) msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup) self.store[user_id]['inline_message'] = msg return if 'sure' not in kwargs.keys(): survey = database.get_survey(survey_id=kwargs.get('survey_id')) text = "Bist du sicher, dass du folgende Umfrage schließen möchtest?\n\n" + survey.get_detail_str( ) markup = InlineKeyboardMarkup(row_width=2) markup.add( InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'sure': True})), InlineKeyboardButton(text="Nein", callback_data=self.command + json.dumps({'sure': False}))) markup.add( InlineKeyboardButton(text="Abbrechen", callback_data="abort")) bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) return if not kwargs['sure']: text = "Schade, dann ist wohl etwas schiefgegangen... Bitte versuche es ggfs erneut." else: text = "Okay, die Umfrage wurde geschlossen. Antworten können nicht mehr geändert werden." util.database.close_survey(survey_id=kwargs['survey_id']) bot.edit_message_text(inline_message=inline_message, text=text) self.store[user_id] = dict() self.store[user_id]['data'] = dict() self.store[user_id]['inline_message'] = None return
def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs): if inline_message: user_id = inline_message.chat.id else: user_id = (initial_message or user_message or call).from_user.id if user_message: bot.delete_message(chat_id=user_message.chat.id, message_id=user_message.message_id) if call: inline_message = call.message if initial_message: bot.reply_to(initial_message, text=meta.new_event_guide) if kwargs.get('done', False): # send sure reply markup if kwargs.get('sure') is None: event = self.store[user_id]['event'] text = "Der Termin ist lautet:\n" + event.get_detail_str() + "\n\nSoll er gespeichert werden?" markup = InlineKeyboardMarkup(row_width=2) markup.add(InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'sure': True}))) markup.add(InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'done': None, 'property': None}))) bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) return if kwargs.get('send_notice') is None: if not kwargs.get('sure'): self.store[user_id]['property'] = None self.__call__(call=call) return else: event = self.store[user_id]['event'] database.save_event(event) text = "Okay, der Termin wurde erstellt.\n" \ "Möchtest du alle wissen lassen, sodass sie zu oder absagen können?" markup = InlineKeyboardMarkup(row_width=2) markup.add( InlineKeyboardButton(text="Ja", callback_data=self.command + json.dumps({'send_notice': True})), InlineKeyboardButton(text="Nein", callback_data=self.command + json.dumps({'send_notice': False}))) bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) return if not kwargs.get('send_notice'): text = "Okay, es werden keine Nachrichten versandt." else: text = "Okay, es wurden Nachrichten an alle versandt." util.functions.send_new_event_alert(by=util.database.get_frichtle(user_id=user_id), event=self.store[user_id]['event']) bot.edit_message_text(inline_message=inline_message, text=text) self.store[user_id] = dict() self.store[user_id]['data'] = dict() self.store[user_id]['inline_message'] = None return if kwargs.get('property') is None: e = self.store[user_id].get('event', Event()) e.event_id = util.database.get_new_event_id() self.store[user_id]['event'] = e text = "Aktuell sieht der Termin folgendermaßen aus:\n" + e.get_detail_str() + "\n\nBitte wähle aus, um zu Daten einzugeben:" markup = InlineKeyboardMarkup(row_width=2) buttons = [] for i, v in enumerate(meta.event_col_names_display): buttons.append(InlineKeyboardButton(text=v, callback_data=self.command + json.dumps({'property': meta.event_col_names[i]}))) buttons.append(InlineKeyboardButton(text="Fertig", callback_data=self.command + json.dumps({'done': True, 'property': ''}))) buttons.append(InlineKeyboardButton(text="Abbrechen", callback_data="abort")) markup.add(*tuple(buttons)) if inline_message: msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) elif call: msg = bot.edit_message_text(call=call, text=text, reply_markup=markup) else: msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup) self.store[user_id]['inline_message'] = msg return if kwargs['property'] == "dress": if kwargs.get('value') is None: text = "Okay, bitte wähle ein Outfit:" markup = InlineKeyboardMarkup(row_width=2) markup.add(*tuple([InlineKeyboardButton(text=s, callback_data=self.command + json.dumps( {'value': s} )) for s in meta.dresses] + [InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'property': None, 'value': None}))])) bot.edit_message_text(text=text, inline_message=inline_message, reply_markup=markup) else: event = self.store[user_id]['event'] event.dress = kwargs.pop('value') self.store[user_id]['data'].pop('value') self.store[user_id]['data'].pop('property') self.__call__(call=call) return else: prop_display = meta.event_col_names_display[meta.event_col_names.index(kwargs.get('property'))] text = "Okay, gib '{}' ein:".format(prop_display) hint = meta.event_col_names_hints.get(kwargs['property']) if hint is not None: text += "\n{}".format(hint) msg = bot.edit_message_text(inline_message=inline_message, text=text) bot.register_next_step_handler(msg, self.property_reply) return
def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs): if inline_message: user_id = inline_message.chat.id else: user_id = (initial_message or user_message or call).from_user.id surveys = util.database.get_survey() if len(surveys) == 0: bot.reply_to(message=initial_message, text="Es gibt aktuell keine Umfragen.") del self.store[user_id] return if call: inline_message = call.message if user_message: bot.delete_message(chat_id=user_message.chat.id, message_id=user_message.message_id) if kwargs.get('survey_id', None) is None: text = "Welche Umfrage möchtest du anzeigen?" buttons = [] for s in surveys: if util.database.check_survey_response( user_id=user_id, survey_id=s.survey_id) is None: replace = "Unbeantwortet: " else: replace = "" buttons.append( InlineKeyboardButton( text=s.get_inline_str().replace("Umfrage: ", replace), callback_data=self.command + json.dumps({'survey_id': s.survey_id}))) markup = InlineKeyboardMarkup(row_width=1) markup.add(*tuple(buttons)) markup.add(InlineKeyboardButton("Beenden", callback_data="end")) if inline_message: msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) else: msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup) self.store[user_id]['inline_message'] = msg return survey = util.database.get_survey(survey_id=kwargs['survey_id']) if kwargs.get('edit', None) is None: text = survey.get_detail_str() res = survey.results[user_id] buttons = [] if res is None: text += "\n\nDu hast noch nicht geantwortet." buttons.append( InlineKeyboardButton(text="Jetzt antworten", callback_data=self.command + json.dumps({'edit': True}))) else: text += "\n\nDu hast mit '{}' geantwortet".format(res) if survey.active: buttons.append( InlineKeyboardButton(text="Ändern", callback_data=self.command + json.dumps({'edit': True}))) if not survey.active: text += "\nDie Umfrage ist geschlossen." buttons.append( InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'survey_id': None}))) markup = InlineKeyboardMarkup(row_width=2) markup.add(*tuple(buttons)) bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) return if kwargs["edit"] and self.store[user_id]["data"].get( "response", None) is None: self.store[user_id]["data"]["response"] = [None] * len( survey.questions) res = kwargs.pop("res", None) if res is not None: self.store[user_id]["data"]["response"][res[0]] = res[1] i = 0 while i < len(survey.questions): if self.store[user_id]["data"]["response"][i] is None: break i += 1 if i < len(survey.questions): text = survey.get_detail_str( question=i) + "\n\nWie lautet deine Antwort?" if isinstance(survey.questions[i]["answers"], list): buttons = [] for r in survey.questions[i]["answers"]: buttons.append( InlineKeyboardButton(text=r, callback_data=self.command + json.dumps({'res': [i, r]}))) markup = InlineKeyboardMarkup(row_width=2) markup.add( *tuple(buttons), InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'edit': None}))) elif survey.questions[i]["answers"].lower() == 'count': page = kwargs.get('page', 1) markup = markups.inline.show_numbers(command=self.command, return_name='res', question=i, page=page) else: # free reply text = survey.get_detail_str( ) + "\n\nOkay, gib deine Antwort ein:" msg = bot.edit_message_text(inline_message=inline_message, text=text) bot.register_next_step_handler(msg, self.survey_reply, question=i) return if i < len(survey.questions): bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) return util.database.set_response_to_survey( survey_id=kwargs['survey_id'], user_id=user_id, response=self.store[user_id]["data"]["response"]) final_answer = " ".join( [str(r) for r in self.store[user_id]["data"]["response"]]) text = f"\n\nDu hast mit '{final_answer}' geantwortet." text += "\n Wähle neue Umfrage aus:" buttons = [] for s in surveys: if util.database.check_survey_response( user_id=user_id, survey_id=s.survey_id) == '': replace = "Unbeantwortet: " else: replace = "" buttons.append( InlineKeyboardButton(text=s.get_inline_str().replace( "Umfrage: ", replace), callback_data=self.command + json.dumps({'survey_id': s.survey_id}))) markup = InlineKeyboardMarkup(row_width=1) markup.add(*tuple(buttons)) markup.add(InlineKeyboardButton("Beenden", callback_data="end")) self.store[user_id]['data'].update({ 'survey_id': None, 'edit': None, 'res': None, "response": None }) bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup)
def main(self, initial_message=None, user_message=None, call=None, inline_message=None, **kwargs): if inline_message: user_id = inline_message.chat.id else: user_id = (initial_message or user_message or call).from_user.id if call: inline_message = call.message buttons = [] markup = None events = util.database.get_event() if len(events) == 0: bot.reply_to(initial_message, text="Es gibt aktuell keine Termine.") return if kwargs.get('event_id') is None: text = "Wähle einen Termin aus:" markup = InlineKeyboardMarkup(row_width=1) buttons = list( InlineKeyboardButton(text=s.get_inline_str(), callback_data=self.command + json.dumps({'event_id': s.event_id})) for s in database.get_event()) markup.add(*tuple(buttons)) markup.add(InlineKeyboardButton("Beenden", callback_data="end")) if inline_message: msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) else: msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup) self.store[user_id]['inline_message'] = msg return event = util.database.get_event(event_id=kwargs['event_id']) text = util.functions.get_event_summary(**kwargs) if not kwargs.get('detail', False): # erinnerung if kwargs['event_id'] in [s.event_id for s in util.database.events_that_need_reminder()] and \ not self.store[user_id].get('sent_reminder', False): buttons.append( InlineKeyboardButton(text="Erinnern", callback_data=self.command + json.dumps({'remind': True}))) # detail if not kwargs.get('detail', False) and any( s['attendance'] >= 2 for s in util.database.get_event_attendance(event=event)): buttons.append( InlineKeyboardButton(text="Details", callback_data=self.command + json.dumps({'detail': True}))) # back button if kwargs.get('detail', False): dump = {'detail': False} else: dump = {'event_id': None} buttons.append( InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps(dump))) markup = InlineKeyboardMarkup(row_width=2) markup.add(*tuple(buttons)) if kwargs.get('remind', False): util.functions.send_reminder_for(from_user_id=user_id, _id=kwargs['event_id']) self.store[user_id]['sent_reminder'] = True text = "Es wurden Erinnerungen versandt." dump = {'remind': False, 'detail': False} markup = InlineKeyboardMarkup(row_width=1) markup.add( InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps(dump))) if markup is None and kwargs['detail']: markup = InlineKeyboardMarkup() markup.add( InlineKeyboardButton(text="Zurück", callback_data=self.command + json.dumps({'detail': False}))) if inline_message: msg = bot.edit_message_text(inline_message=inline_message, text=text, reply_markup=markup) else: msg = bot.send_message(initial_message.chat.id, text=text, reply_markup=markup) self.store[user_id]['inline_message'] = msg return
def f026(message): bot.reply_to(message, text=meta.invite_link_base + pw_manager.generate())