コード例 #1
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def zufallsspiel(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, /zufallsspiel 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:
            opt = []
            entries = get_playable_entries('games', 'title', update.message.from_user.username)
            for e in entries:
                opt.append(parse_single_db_entry_to_string(e))
            game = opt[randrange(len(opt))]
            update.message.reply_text('Wie wäre es mit ' + game + '?')
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #2
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def csv_import(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, /csv_import 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:
            msg = context.bot.send_message(update.message.chat_id,
                                           'Gib die Daten ein, die du im CSV-Format '
                                           'in die Spiele-Datenbank importieren '
                                           'möchtest.\n'
                                           'Format: Besitzer, Titel, Max. Spielerzahl, '
                                           'Kategorie_1, Kategorie_2, ... '
                                           'Pro Zeile ein Spiel',
                                           reply_markup=ForceReply())
            ForceReplyJobs().add(msg.message_id, "csv")
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #3
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def erweiterungen(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, /erweiterungen 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:
            msg = context.bot.send_message(update.message.chat_id,
                                           'Für welches Grundspiel fragst du?\n'
                                           'Antworte mit /stop, um abzubrechen.',
                                           reply_markup=ForceReply())
            ForceReplyJobs().add(msg.message_id, "expansions_list")
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #4
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def neue_erweiterung(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, /neue_erweiterung 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:
            msg = context.bot.send_message(update.message.chat_id,
                                           'Für welches Spiel hast du eine neue '
                                           'Erweiterung?\n'
                                           'Antworte mit /stop, um abzubrechen.',
                                           reply_markup=ForceReply())
            user_or_household_id = check_household(
                                    update.message.from_user.username)
            ForceReplyJobs().add_with_query(msg.message_id, "expansion_for",
                                            "new_expansion," +
                                            user_or_household_id)
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #5
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
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.')
コード例 #6
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def spiele(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, /spiele 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:
            gamestring = parse_db_entries_to_messagestring(
                search_by_substring(choose_database("datadb"), 'games',
                                    "owner", update.message.from_user.username))
            if len(gamestring) == 0:
                context.bot.send_message(update.message.chat_id,
                                         text="Dass du Spiele hast, wäre mir neu. "
                                         "Wenn es doch der Fall ist, sag mir das mit /neues_spiel!")
            else:
                update.message.reply_text('Du hast folgende Spiele:')
                context.bot.send_message(update.message.chat_id, text=gamestring)
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #7
0
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())
コード例 #8
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
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.')
コード例 #9
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
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.')
コード例 #10
0
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())
コード例 #11
0
def test_termin(context):
    now = datetime.datetime.now()
    plan = GameNight()
    if plan:
        r = re.compile('.{2}/.{2}/.{4}')
        if r.match(plan.date) is not None:
            d = datetime.datetime.strptime(plan.date, '%d/%m/%Y')
            if d < now:
                plan = GameNight()
                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(plan.chat_id, title)
                    context.bot.set_chat_description(plan.chat_id, "")
                except BadRequest:
                    handle_bot_not_admin(context.bot, plan.chat_id)
                plan.clear()
コード例 #12
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
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.')
コード例 #13
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
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.')
コード例 #14
0
ファイル: commands.py プロジェクト: soxidus/Boardgame-Bot
def genrespiel(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, /genrespiel 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:
            update.message.reply_text(
                'Auf welche Kategorie hast du denn heute Lust?',
                reply_markup=generate_findbycategory())
    else:
        update.message.reply_text('Bitte authentifiziere dich zunächst '
                                  'mit /key.')
コード例 #15
0
def auth(update):
    config = configparser.ConfigParser()
    config_path = os.path.dirname(os.path.realpath(__file__))
    config.read(os.path.join(config_path, "config.ini"))
    passphrase = config['Authentication']['password']

    if update.message.text == passphrase:
        try:
            update.message.bot.delete_message(update.message.chat_id,
                                              update.message.message_id)
        except BadRequest:
            handle_bot_not_admin(update.message.bot, update.message.chat_id)
        if not dbf.check_user(update.message.chat_id):
            if update.message.chat_id > 0:
                dbf.add_user_auth(update.message.chat_id,
                                  name=update.message.from_user.username)
                try:
                    msg = update.message.bot.send_message(
                        chat_id=update.message.chat_id,
                        text='Super! Wir dürfen jetzt miteinander reden. '
                        'Noch eine Frage: Wohnst du vielleicht mit einem '
                        '(oder mehreren) '
                        'der Gruppenmitglieder zusammen? '
                        'Wenn ja, wähle unten den (die) '
                        'entsprechenden Alias(e)! '
                        'Wenn nicht, wähle Nein.',
                        reply_markup=generate_household(
                            update.message.from_user.username, first=True))
                    query = "household," + update.message.from_user.username + ","
                    QueryBuffer().add(msg.message_id, query)
                except IndexError:  # first user
                    update.message.bot.send_message(
                        chat_id=update.message.chat_id,
                        text='Super! Wir dürfen jetzt miteinander reden.',
                        reply_markup=ReplyKeyboardRemove())
                    if LogToMessageFilter().ask_chat_type == "private":
                        update.message.bot.send_message(
                            chat_id=update.message.chat_id,
                            text=
                            'Hey, soll ich meine Debug-Nachrichten hier rein schicken?',
                            reply_markup=generate_debug())
            else:
                dbf.add_user_auth(update.message.chat_id)
                update.message.bot.send_message(
                    chat_id=update.message.chat_id,
                    text='Super! Wir dürfen jetzt '
                    'miteinander reden.',
                    reply_markup=ReplyKeyboardRemove())
                if LogToMessageFilter().ask_chat_type == "group":
                    update.message.bot.send_message(
                        chat_id=update.message.chat_id,
                        text=
                        'Hey, soll ich meine Debug-Nachrichten hier rein schicken?',
                        reply_markup=generate_debug())
        else:
            update.message.reply_text(
                "Du musst das Passwort nicht nochmal "
                "eingeben... Rede einfach mit mir!",
                reply_markup=ReplyKeyboardRemove())
    else:
        update.message.reply_text(
            "Schade, das hat leider nicht funktioniert. "
            "Mach es gut!",
            reply_markup=ReplyKeyboardRemove())
        update.message.chat.leave()