Exemple #1
0
def handle(raw_msg):

    msg = MessageParser.Message(raw_msg)

    persondb.addPerson(msg.mfrom)  # logs every person!

    if msg.chat.type == "private":
        log.debug("private message received")

        #chatsdb.addChat(msg.chat)
        chatid = msg.chat.id

        # add the user
        usersdb.addUser(msg.mfrom, chatid)
        user = usersdb.getUser(msg.mfrom)

        # received a message user is supposedly active
        user.isActive = True

        if user.accepted_terms == False:
            log.debug("handle privacy policy")
            Handle.handle_privacy_policy(bot, usersdb, user, msg.content)
        else:

            # flag to send main menu
            send_main_menu = True

            # check the content if there is piped some request
            send_main_menu = Handle.handle_content(msg.content, bot, user,
                                                   categoriesdb, mediavotedb)

            # analyize content
            if msg.content.type == "text" and send_main_menu:
                # log the messages to the bot
                text = msg.content.text
                log_msg = text if len(text) < 244 else text[:241] + "..."
                log_msg = log_msg.encode("utf-8").decode(
                    "ascii", "backslashreplace")
                log.debug("Message: " + log_msg)

                # handle the requests
                send_main_menu = Handle.handle_private_text(
                    msg.content.text, bot, user, usersdb, categoriesdb,
                    mediavotedb)

            if send_main_menu:
                Handle.send_main_menu(bot, user)

        #chatsdb.update()
        usersdb.update()
        categoriesdb.update()
        mediavotedb.update()

    persondb.update()