Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#14935 closed enhancement

receiving-chat-msg doesn't seem to catch system messages

Reported by: mcepl Owned by:
Milestone: Component: libpurple
Version: 2.7.9 Keywords:
Cc:

Description

I have on IRC (especially the internal company one) tons of messages like "tpelka|mtg je teď znám jako tpelka|lunch" (key phrase is a Czech translation of "is now known as"). I would like to avoid them, so I tried to create this simple python script:

# -*- coding: utf-8 -*-
"""
Script for filtering incoming chat messages in Pidgin.

Copyright (c) 2011, Matěj Cepl <mcepl-at-redhat-dot-com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

import re
import logging
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop

__author__ = "Matěj Cepl <mcepl|at|redhat|dot|com>"
__version__ = "0.0.1"

HIDE_CHAT_RE=re.compile(r'(\S+) je teď znám jako (\S+)', re.UNICODE)
logging.basicConfig(level=logging.DEBUG)

def should_allow_chat_message(account, sender, message, conversation, flags):
    loggin.debug("in conversation %s sender %s (flags %s, RE=%s) is saying:\n%s",
        conversation, sender, flags, HIDE_CHAT_RE.search(unicode(message)),
        message)
    return not HIDE_CHAT_RE.search(unicode(message))

if __name__=="__main__":
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus() 
        
        bus.add_signal_receiver(should_allow_chat_message,
                                dbus_interface="im.pidgin.purple.PurpleInterface",
                                signal_name="ReceivingChatMsg")
        loop = gobject.MainLoop()
        loop.run()

However, even when it is running it doesn't show ANY system messages (flags in the log are either 1 or 2, never anything more than that).

Change History (3)

comment:1 Changed 7 years ago by datallah

  • Status changed from new to pending

As I mentioned in IRC, the "writing-chat-msg" signal should do what you're looking for.

comment:2 Changed 7 years ago by trac-robot

  • Status changed from pending to closed

This ticket was closed automatically by the system. It was previously set to a Pending status and hasn't been updated within 14 days.

comment:3 Changed 7 years ago by mcepl

Even when using writing-chat-msg and I can see that regular expression matches incoming messages, they are still not cancelled:

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Script for filtering incoming chat messages in Pidgin.

Copyright (c) 2011, Matěj Cepl <mcepl-at-redhat-dot-com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from __future__ import absolute_import, unicode_literals, print_function
import re
import logging
import dbus, dbus.mainloop.glib, gobject

__author__ = "Matěj Cepl <mcepl|at|redhat|dot|com>"
__version__ = "0.0.2"

HIDE_CHAT_RE = re.compile(r'(\S+) je teď znám jako (\S+)', re.UNICODE)
logging.basicConfig(level=logging.DEBUG)

def should_cancel_chat_message(account, sender, message, conversation, flags):
    """Callback function for writing-chat-msg signal.
    
    According to http://developer.pidgin.im/doxygen/dev/html\
    /conversation-signals.html#writing-chat-msg callback returns:
            TRUE if the message should be canceled, or FALSE otherwise.
    """
    res = bool(HIDE_CHAT_RE.search(unicode(message)))
    logging.debug("in conversation %s sender %s (flags %s, RE=%s) is saying:\n%s",
        conversation, sender, flags, res, message)
    return res

if __name__ == "__main__":
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        bus = dbus.SessionBus()

        bus.add_signal_receiver(should_cancel_chat_message,
                                dbus_interface="im.pidgin.purple.PurpleInterface",
                                signal_name="WritingChatMsg")
        loop = gobject.MainLoop()
        loop.run()
Note: See TracTickets for help on using tickets.
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!