def start_umfrage_spiel(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() check = plan.set_poll(update.message.from_user.username) if check < 0: update.message.reply_text('Das war leider nichts. ' 'Dies könnte verschiedene Gründe haben:\n' '(1) Ihr habt kein Datum festgelegt. ' 'Holt das mit /neuer_termin nach.\n' '(2) Du bist nicht zum Spieleabend angemeldet. ' 'Hole das mit /ich nach.\n' '(3) Euch steht kein einziges Spiel zur Verfügung. ' 'Tragt neue Spiele mit /neues_spiel ein!') else: keys = [] for o in plan.poll.options: keys.append([KeyboardButton(o)]) update.message.reply_text('Welches Spiel wollt ihr spielen?', reply_markup=ReplyKeyboardMarkup( keys, one_time_keyboard=True)) elif "private" in update.message.chat.type: update.message.reply_text('Wirklich?! Eine Umfrage nur für dich?\n' 'Starte doch bitte eine Umfrage ' 'im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def ende_umfrage(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() try: check = plan.end_poll(update.message.from_user.username) except AttributeError: update.message.reply_text( 'Das hat leider nicht funktioniert. Scheinbar gibt es ' 'keine Umfrage, die ich beenden könnte.') else: if check < 0: update.message.reply_text( 'Das hat leider nicht funktioniert. Du hast wohl ' 'nicht das Recht zu dieser Aktion.') else: update.message.reply_text( 'Die Umfrage ist beendet. Mit /ergebnis könnt ihr ' 'sehen, wie sie ausgegangen ist.', reply_markup=ReplyKeyboardRemove()) elif "private" in update.message.chat.type: update.message.reply_text('Stopp, das hat hier nichts zu suchen.\n' 'Bitte versuche es im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def endetermin(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() plan.clear() config = configparser.ConfigParser() config_path = os.path.dirname(os.path.realpath(__file__)) config.read(os.path.join(config_path, "config.ini")) title = config['GroupDetails']['title'] try: context.bot.set_chat_title(update.message.chat.id, title) context.bot.set_chat_description(update.message.chat_id, "") except BadRequest: handle_bot_not_admin(context.bot, update.message.chat.id) # since we can delete the Keyboard only via reply # this call is necessary msg = update.message.reply_text( 'Ich habe alles zurückgesetzt.', reply_markup=ReplyKeyboardRemove()) try: context.bot.delete_message(update.message.chat_id, msg.message_id) except BadRequest: handle_bot_not_admin(context.bot, update.message.chat_id) elif "private" in update.message.chat.type: update.message.reply_text('Stopp, das hat hier nichts zu suchen.\n' 'Bitte versuche es im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def expansion_poll_game(update): if "/stop" in update.message.text: update.message.reply_text('Okay, hier ist nichts passiert.', reply_markup=ReplyKeyboardRemove()) else: plan = GameNight() check = plan.set_poll(update.message.from_user.username, game=update.message.text) if check < 0: update.message.reply_text( 'Das war leider nichts. Dies könnte verschiedene Gründe haben:\n\n' '(1) Ihr habt kein Datum festgelegt. Holt das mit ' '/neuer_termin nach.\n' '(2) Du bist nicht zum Spieleabend angemeldet. ' 'Hole das mit /ich nach.\n' '(3) Mir ist nicht bekannt, dass einer der Teilnehmenden eine ' 'Erweiterung für dieses Spiel hat.' 'Wenn das jedoch der Fall ist, sagt mir mit /neue_erweiterung ' 'Bescheid (natürlich im Privatchat)!') else: keys = [] for o in plan.poll.options: keys.append([KeyboardButton(o)]) update.message.reply_text('Welche Erweiterung wollt ihr spielen?', reply_markup=ReplyKeyboardMarkup( keys, one_time_keyboard=True))
def date(update): if "/stop" in update.message.text: update.message.reply_text('Okay, hier ist nichts passiert.', reply_markup=ReplyKeyboardRemove()) else: check = GameNight(update.message.chat.id).set_date(update.message.text) if check < 0: update.message.reply_text( "Melde dich doch einfach mit /ich " "beim festgelegten Termin an.", reply_markup=ReplyKeyboardRemove()) else: config = configparser.ConfigParser() config_path = os.path.dirname(os.path.realpath(__file__)) config.read(os.path.join(config_path, "config.ini")) title = config['GroupDetails']['title'] try: update.message.bot.set_chat_title( update.message.chat.id, title + ': ' + update.message.text) except BadRequest: handle_bot_not_admin(update.message.bot, update.message.chat.id) update.message.reply_text( "Okay, schrei einfach /ich, " "wenn du teilnehmen willst!", reply_markup=ReplyKeyboardRemove())
def ich(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() check = plan.add_participant(update.message.from_user.username) send_message = check_notify("settings", update.message.from_user.username, "notify_participation") handled_unauthorized = False if send_message < 0: # no entry in table, user hasn't talked to bot yet handled_unauthorized = True handle_bot_unauthorized(context.bot, update.message.chat_id, update.message.from_user.first_name) if check < 0: update.message.reply_text( 'Das war leider nichts. Vereinbart erst einmal einen ' 'Termin mit /neuer_termin.') else: try: context.bot.set_chat_description(update.message.chat_id, plan.get_participants()) except BadRequest: handle_bot_not_admin(context.bot, update.message.chat.id) if send_message: if check > 0: text = ('Alles gut, ' + update.message.from_user.first_name + ', ' 'ich weiß schon, dass du am ' + plan.date + ' teilnimmst.') else: # check = 0 text = ('Danke für deine Zusage zum Spieleabend ' + plan.date + ', ' + update.message.from_user.first_name + '!') try: context.bot.send_message(update.message.from_user.id, text) if check == 0 and match('\\d\\d[\\/]\\d\\d[\\/]\\d\\d\\d\\d', str(plan.date)) is not None: context.bot.send_document(update.message.from_user.id, document=open(plan.cal_file, 'rb'), filename=("Spieleabend " + str(plan.date).replace('/', '-') + ".ics")) except Unauthorized: if not handled_unauthorized: # don't send two warnings within the same command handle_bot_unauthorized(context.bot, update.message.chat.id, update.message.from_user.first_name, try_again="/ich") handled_unauthorized = True elif "private" in update.message.chat.type: update.message.reply_text('Stopp, das hat hier nichts zu suchen.\n' 'Bitte versuche es im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def filter(self, message): try: possible_votes = GameNight().poll.options except AttributeError: return False if "group" in message.chat.type: return bool(message.text in possible_votes) else: return False
def nichtich(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() check = plan.remove_participant(update.message.from_user.username) send_message = check_notify("settings", update.message.from_user.username, "notify_participation") handled_unauthorized = False if send_message < 0: # no entry in table, user hasn't talked to bot yet handle_bot_unauthorized(context.bot, update.message.chat_id, update.message.from_user.first_name) handled_unauthorized = True if check < 0 and send_message: try: context.bot.send_message(update.message.from_user.id, 'Danke für deine Absage. ' 'Schade, dass du nicht teilnehmen kannst.') except Unauthorized: if not handled_unauthorized: handle_bot_unauthorized(context.bot, update.message.chat_id, update.message.from_user.first_name, try_again="/nichtich") handled_unauthorized = True elif check >= 0: try: context.bot.set_chat_description(update.message.chat_id, plan.get_participants()) except BadRequest: handle_bot_not_admin(context.bot, update.message.chat.id) if send_message: try: context.bot.send_message(update.message.from_user.id, 'Schade, dass du doch nicht ' 'teilnehmen kannst, ' + update.message.from_user.first_name + '.') except Unauthorized: if not handled_unauthorized: handle_bot_unauthorized(context.bot, update.message.chat_id, update.message.from_user.first_name, try_again="/nichtich") handled_unauthorized = True elif "private" in update.message.chat.type: update.message.reply_text('Stopp, das hat hier nichts zu suchen.\n' 'Bitte versuche es im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def handle_calendar(update, context): selected, date, user_inp_req, stop = telegramcalendar.process_calendar_selection( update, context) if stop: context.bot.send_message(chat_id=update.callback_query.message.chat_id, text='Okay, hier ist nichts passiert.') elif selected: if user_inp_req: msg = context.bot.send_message( chat_id=update.callback_query.message.chat_id, text= 'Okay, wann wollt ihr spielen? Antworte mit /stop, um abzubrechen.', reply_markup=ForceReply()) rep.ForceReplyJobs().add(msg.message_id, "date") elif date: check = GameNight( chat_id=update.callback_query.message.chat_id).set_date( date.strftime("%d/%m/%Y")) if check < 0: context.bot.send_message( chat_id=update.callback_query.message.chat_id, text="Melde dich doch einfach mit /ich " "beim festgelegten Termin an.", reply_markup=ReplyKeyboardRemove()) else: config = configparser.ConfigParser() config_path = os.path.dirname(os.path.realpath(__file__)) config.read(os.path.join(config_path, "config.ini")) title = config['GroupDetails']['title'] try: context.bot.set_chat_title( update.callback_query.message.chat_id, title + ': ' + date.strftime("%d/%m/%Y")) except BadRequest: handle_bot_not_admin(context.bot, update.callback_query.message.chat.id) filename = create_ics_file("Spieleabend", date) GameNight(chat_id=update.callback_query.message.chat_id ).set_cal_file(filename) context.bot.send_message( chat_id=update.callback_query.message.chat_id, text="Okay, schrei einfach /ich, wenn du " "teilnehmen willst!", reply_markup=ReplyKeyboardRemove())
def handle_pollbycategory(update, context): update.callback_query.answer() category = update.callback_query.data.split(";")[1] if category == "stop": context.bot.send_message(chat_id=update.callback_query.message.chat_id, text='Okay, hier ist nichts passiert.', reply_markup=ReplyKeyboardRemove()) shrink_keyboard(update, context, "Abbruch.") elif category == "IGNORE": pass else: # got a category plan = GameNight() check = plan.set_poll(update.callback_query.from_user.username, category=category) if check < 0: context.bot.send_message( chat_id=update.callback_query.message.chat_id, text='Das war leider nichts. ' 'Dies könnte verschiedene Gründe haben:\n' '(1) Ihr habt kein Datum festgelegt. ' 'Holt das mit /neuer_termin nach.\n' '(2) Du bist nicht zum Spieleabend angemeldet. ' 'Hole das mit /ich nach.\n' '(3) Ihr habt gerade kein Spiel dieser Kategorie ' 'zur Verfügung. Sollte ich mich da irren, ' 'tragt das Spiel mit /neues_spiel ein ' '(natürlich im Privatchat).\n' '(4) Ihr habt die Spiele dieser Kategorie, ' 'welche euch zur Verfügung stehen, alle innerhalb ' 'der letzten 14 Tage gespielt. Kommt schon, ' 'es ist mal Zeit für was anderes!\n' '(5) Es läuft schon eine Umfrage.', reply_markup=ReplyKeyboardRemove()) else: keys = [] for o in plan.poll.options: keys.append([KeyboardButton(o)]) context.bot.send_message( chat_id=update.callback_query.message.chat_id, text='Welches Spiel wollt ihr spielen?', reply_markup=ReplyKeyboardMarkup(keys, one_time_keyboard=True)) shrink_keyboard(update, context, category)
def leeren(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: plan = GameNight() plan.clear() config = configparser.ConfigParser() config_path = os.path.dirname(os.path.realpath(__file__)) config.read(os.path.join(config_path, "config.ini")) title = config['GroupDetails']['title'] try: # raises error when no modification or bot not Admin context.bot.set_chat_title(update.message.chat.id, title) context.bot.set_chat_description(update.message.chat_id, "") except BadRequest: handle_bot_not_admin(context.bot, update.message.chat.id) update.message.reply_text('Ich habe alle Termine und ' 'Umfragen zurückgesetzt.', reply_markup=ReplyKeyboardRemove()) elif "private" in update.message.chat.type: update.message.reply_text('Stopp, das hat hier nichts zu suchen!\n' 'Bitte versuche es im Gruppenchat...') else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def ergebnis(update, context): if check_user(update.message.chat_id): plan = GameNight() try: votes = plan.poll.print_votes() except AttributeError: # poll doesn't exist try: votes = plan.old_poll.print_votes() # poll was ended except AttributeError: update.message.reply_text('Leider gibt es derzeit kein ' 'Ergebnis, was ich zeigen kann.') else: update.message.reply_text('Das Ergebnis ist: \n' + votes) else: update.message.reply_text('Das Ergebnis ist: \n' + votes) else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')
def wer(update, context): if check_user(update.message.chat_id): if "group" in update.message.chat.type: try: context.bot.delete_message(update.message.chat_id, update.message.message_id) except BadRequest: handle_bot_not_admin(context.bot, update.message.chat_id) try: context.bot.send_message(update.message.from_user.id, 'Hey, /wer kannst du im Gruppenchat ' 'nicht verwenden. Hier schon!') except Unauthorized: handle_bot_unauthorized(context.bot, update.message.chat_id, update.message.from_user.username, try_again='das Ganze im Privatchat') elif "private" in update.message.chat.type: participants = GameNight().get_participants() update.message.reply_text(participants) else: update.message.reply_text('Bitte authentifiziere dich zunächst ' 'mit /key.')