Beispiel #1
0
def comment_cmd(bot, update, args):
    user_id = update.message.from_user.id
    chat_id = update.message.chat_id
    first_name = update.message.from_user.first_name
    last_name = update.message.from_user.last_name
    username = update.message.from_user.username
    db = DBwrapper.get_instance()
    lang_id = db.get_lang_id(user_id)

    state_handler = StateHandler.get_instance()
    user = state_handler.get_user(user_id)

    if user.get_state() == UserState.IDLE:
        if len(args) > 1:
            text = " ".join(args)
            logger.debug("New comment! {}!".format(user_id))

            bot.sendMessage(chat_id=chat_id, text=translate("userComment", lang_id))
            for admin_id in db.get_admins():
                bot.sendMessage(admin_id,
                                "New comment:\n\n{}\n\n{} | {} | {} | @{} | {}".format(text, user_id, first_name,
                                                                                       last_name, username,
                                                                                       lang_id))
            user.set_state(UserState.IDLE)
        else:
            # The user just wrote "/comment" -> Ask him to send a message
            logger.debug("Add {} to comment_list!".format(user_id))

            keyboard = [[InlineKeyboardButton(text=translate("cancel", lang_id), callback_data="cancel_comment")]]
            reply_markup = InlineKeyboardMarkup(keyboard)

            bot.sendMessage(chat_id=chat_id, text=translate("sendCommentNow", lang_id), reply_markup=reply_markup)
            user.set_state(UserState.COMMENTING)
Beispiel #2
0
def stop_cmd(bot, update):
    user_id = update.message.from_user.id
    state_handler = StateHandler.get_instance()
    user = state_handler.get_user(user_id)

    user.set_state(UserState.IDLE)

    chat_id = update.message.chat_id
    game_handler.gl_remove(chat_id)
Beispiel #3
0
def cancel_cmd(bot, update):
    user_id = update.effective_user.id
    message_id = update.effective_message.message_id
    callback_query_id = update.callback_query.id
    chat_id = update.effective_chat.id

    state_handler = StateHandler.get_instance()
    user = state_handler.get_user(user_id)

    if user.get_state() == UserState.COMMENTING:
        db = DBwrapper.get_instance()
        lang_id = db.get_lang_id(user_id)

        user.set_state(UserState.IDLE)
        bot.editMessageText(chat_id=chat_id, message_id=message_id, text=translate("cancelledMessage", lang_id))
        bot.answerCallbackQuery(callback_query_id=callback_query_id, text=translate("cancelledMessage", lang_id))
Beispiel #4
0
def game_commands(bot, update):
    if update.message is None:
        logger.warning(
            "game_commands error happened again! Update: {}".format(update))

    text = update.effective_message.text
    chat_id = update.effective_message.chat_id
    user = update.effective_user
    user_id = user.id
    first_name = user.first_name
    last_name = user.last_name
    username = user.username
    db = DBwrapper.get_instance()
    lang_id = db.get_lang_id(user_id)

    state_handler = StateHandler.get_instance()
    user = state_handler.get_user(user_id)

    if user.get_state() == UserState.COMMENTING:
        # User wants to comment!
        bot.sendMessage(chat_id, text=translate("userComment", lang_id))
        for admin_id in db.get_admins():
            admin_message = "New comment:\n\n{}\n\n{} | {} | {} | @{} | {}".format(
                text, user_id, first_name, last_name, username, lang_id)
            bot.sendMessage(admin_id, text=admin_message)

        user.set_state(UserState.IDLE)
        return

    if not db.is_user_saved(user_id):
        logger.info("New user - {}".format(user_id))
        db.add_user(user_id, "en", first_name, last_name, username)

        if chat_id > 0:
            # ask user for language if it's a private chat:
            language_cmd(bot, update)

        return

    # check if user already has got a game (in the same chat):
    # TODO multiplayer games
    game = game_handler.get_game_by_chatid(chat_id)
    if game is not None:
        logger.debug(
            "Game already existing. Forwarding text '{}' to game".format(text))
        game.analyze_message(update)
Beispiel #5
0
 def untick(title):
     """unticks a task"""
     description = control.ItemHandler.getProperty(title, "description")
     due_date = control.ItemHandler.getProperty(title, "due_date")
     deadline = control.ItemHandler.getProperty(title, "deadline")
     children = control.ItemHandler.getProperty(title, "children")
     completion_date = control.ItemHandler.getProperty(
         title, "completion_date")
     change.ItemChanger.changeTask(
         title=title,
         description=description,
         due_date=due_date,
         deadline=deadline,
         children=children,
         state=StateHandler.getAppropriateState(title),
         completion_date=completion_date,
         readback=False)
     print(bc.col.OKGREEN + f"Unticked: {title}" + bc.col.ENDC)
Beispiel #6
0
def start_cmd(bot, update):
    message = update.effective_message
    chat_id = message.chat_id
    eff_user = update.effective_user
    user_id = eff_user.id
    message_id = message.message_id
    first_name = eff_user.first_name
    last_name = eff_user.last_name
    username = eff_user.username
    db = DBwrapper.get_instance()

    state_handler = StateHandler.get_instance()
    user = state_handler.get_user(user_id)

    if not db.is_user_saved(user_id):
        logger.info("New user: {}".format(user_id))
        db.add_user(user_id, "en", first_name, last_name, username)
        if chat_id > 0:
            # ask user for language:
            language_cmd(bot, update)
            return

    # check if user already has got a game (in the same chat):
    game_index = game_handler.get_index_by_chatid(chat_id)
    if game_index is None:
        user.set_state(UserState.PLAYING)
        logger.debug("Creating a game")
        lang_id = db.get_lang_id(user_id)
        bj = BlackJackGame(chat_id, user_id, lang_id, first_name, game_handler,
                           message_id, send_message)
        game_handler.add_game(bj)
    else:
        logger.debug("Game already existing. Starting game!")
        game = game_handler.get_game_by_index(game_index)

        if game.players[0].user_id == user_id:
            game.start_game()
        else:
            message.reply_text(
                "Only the creator ({}) can start the game".format(
                    game.players[0].first_name))