[regex_filter] Adapt to Gajim changes
This commit is contained in:
@@ -1,19 +1,16 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# This file is part of Gajim.
|
||||||
|
#
|
||||||
## This file is part of Gajim.
|
# Gajim is free software; you can redistribute it and/or modify
|
||||||
##
|
# it under the terms of the GNU General Public License as published
|
||||||
## Gajim is free software; you can redistribute it and/or modify
|
# by the Free Software Foundation; version 3 only.
|
||||||
## it under the terms of the GNU General Public License as published
|
#
|
||||||
## by the Free Software Foundation; version 3 only.
|
# Gajim is distributed in the hope that it will be useful,
|
||||||
##
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
## Gajim is distributed in the hope that it will be useful,
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# GNU General Public License for more details.
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
#
|
||||||
## GNU General Public License for more details.
|
# You should have received a copy of the GNU General Public License
|
||||||
##
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
## You should have received a copy of the GNU General Public License
|
|
||||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
##
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Regex Filter plugin.
|
Regex Filter plugin.
|
||||||
@@ -32,7 +29,9 @@ from gajim.plugins.helpers import log_calls
|
|||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import ged
|
from gajim.common import ged
|
||||||
from gajim.command_system.framework import CommandContainer, command, doc
|
from gajim.command_system.framework import CommandContainer, command, doc
|
||||||
from gajim.command_system.implementation.hosts import *
|
from gajim.command_system.implementation.hosts import ChatCommands
|
||||||
|
from gajim.command_system.implementation.hosts import GroupChatCommands
|
||||||
|
from gajim.command_system.implementation.hosts import PrivateChatCommands
|
||||||
from gajim.plugins.plugins_i18n import _
|
from gajim.plugins.plugins_i18n import _
|
||||||
|
|
||||||
|
|
||||||
@@ -44,9 +43,8 @@ class RegexFilterPlugin(GajimPlugin):
|
|||||||
self.config_dialog = None
|
self.config_dialog = None
|
||||||
|
|
||||||
self.events_handlers = {
|
self.events_handlers = {
|
||||||
'decrypted-message-received': (ged.PREGUI1,
|
'message-received': (ged.PREGUI1, self._on_message_received),
|
||||||
self._nec_decrypted_message_received),
|
'gc-message-received': (ged.PREGUI1, self._on_gc_message_received),
|
||||||
'gc-message-received': (ged.PREGUI1, self._nec_gc_message_received),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.create_rules()
|
self.create_rules()
|
||||||
@@ -96,20 +94,21 @@ class RegexFilterPlugin(GajimPlugin):
|
|||||||
obj.msgtxt = rule[0].sub(rule[1], obj.msgtxt)
|
obj.msgtxt = rule[0].sub(rule[1], obj.msgtxt)
|
||||||
|
|
||||||
@log_calls('RegexFilterPlugin')
|
@log_calls('RegexFilterPlugin')
|
||||||
def _nec_decrypted_message_received(self, obj):
|
def _on_message_received(self, obj):
|
||||||
self._nec_all(obj)
|
self._nec_all(obj)
|
||||||
|
|
||||||
@log_calls('RegexFilterPlugin')
|
@log_calls('RegexFilterPlugin')
|
||||||
def _nec_gc_message_received(self, obj):
|
def _on_gc_message_received(self, obj):
|
||||||
self._nec_all(obj)
|
self._nec_all(obj)
|
||||||
|
|
||||||
|
|
||||||
class FilterCommands(CommandContainer):
|
class FilterCommands(CommandContainer):
|
||||||
AUTOMATIC = False
|
AUTOMATIC = False
|
||||||
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
|
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
|
||||||
|
|
||||||
@command("add_filter", raw=True)
|
@command("add_filter", raw=True)
|
||||||
@doc(_("Add an incoming filter. First argument is the search regex, "
|
@doc(_("Add an incoming filter. First argument is the search regex, "
|
||||||
"second argument is the replace regex."))
|
"second argument is the replace regex."))
|
||||||
def add_filter(self, search, replace):
|
def add_filter(self, search, replace):
|
||||||
plugin = app.plugin_manager.get_active_plugin('regex_filter')
|
plugin = app.plugin_manager.get_active_plugin('regex_filter')
|
||||||
plugin.add_rule(search, replace)
|
plugin.add_rule(search, replace)
|
||||||
@@ -118,7 +117,7 @@ class FilterCommands(CommandContainer):
|
|||||||
|
|
||||||
@command("remove_filter", raw=True)
|
@command("remove_filter", raw=True)
|
||||||
@doc(_("Remove an incoming filter. Argument is the rule number. "
|
@doc(_("Remove an incoming filter. Argument is the rule number. "
|
||||||
"See /list_rules command."))
|
"See /list_rules command."))
|
||||||
def remove_filter(self, num):
|
def remove_filter(self, num):
|
||||||
plugin = app.plugin_manager.get_active_plugin('regex_filter')
|
plugin = app.plugin_manager.get_active_plugin('regex_filter')
|
||||||
if plugin.remove_rule(num):
|
if plugin.remove_rule(num):
|
||||||
@@ -132,8 +131,10 @@ class FilterCommands(CommandContainer):
|
|||||||
rules = plugin.get_rules()
|
rules = plugin.get_rules()
|
||||||
st = ''
|
st = ''
|
||||||
for num, rule in rules.items():
|
for num, rule in rules.items():
|
||||||
st += _('%(num)s: %(search)s -> %(replace)s') % {'num': num,
|
st += _('%(num)s: %(search)s -> %(replace)s') % {
|
||||||
'search': rule[0], 'replace': rule[1]} + '\n'
|
'num': num,
|
||||||
|
'search': rule[0],
|
||||||
|
'replace': rule[1]} + '\n'
|
||||||
if st:
|
if st:
|
||||||
return st[:-1]
|
return st[:-1]
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user