joaoricardo000 / whatsapp-bot-seed

A small python framework to create a whatsapp bot, with regex-callback message routing.
726 stars 245 forks source link

is there a way to disable reacting on personal messages? #69

Closed e0xify closed 8 years ago

e0xify commented 8 years ago

like said in the title i want the bot not to react on private messages to avoid abuse and stuff. is there a way to disable recieving private messages or ignore them and only use groups?

Thanks

ghost commented 8 years ago

In router.py, replace this:

@ProtocolEntityCallback("message")
def on_message(self, message):
    "Executes on every received message"
    self.toLower(message.ack())  # Auto ack
    self.toLower(message.ack(True))  # Auto ack (double blue check symbol)
    # Routing only text type messages, for now ignoring other types. (media, audio, location...)
    if message.getType() == 'text':
        self.route(message)

with this:

@ProtocolEntityCallback("message")
def on_message(self, message):
    "Executes on every received message"
    self.toLower(message.ack())  # Auto ack
    self.toLower(message.ack(True))  # Auto ack (double blue check symbol)
    # Routing only text type messages, for now ignoring other types. (media, audio, location...)
    if message.getType() == 'text':
        if not message.isGroupMessage():
            import config
            if not any(message.getFrom().replace("@s.whatsapp.net", "") in s for s in config.admins):
                logging.info("%s is trying to run \"%s\" via private chat." % (message.getFrom().replace("@s.whatsapp.net", ""), message.getBody()))
                return
        self.route(message)