Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gajim
gajim-plugins
Commits
d81c4721
Commit
d81c4721
authored
13 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
new regex filter plugin
parent
ea470f89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
regex_filter/__init__.py
+1
-0
1 addition, 0 deletions
regex_filter/__init__.py
regex_filter/manifest.ini
+9
-0
9 additions, 0 deletions
regex_filter/manifest.ini
regex_filter/regex_filter.py
+136
-0
136 additions, 0 deletions
regex_filter/regex_filter.py
with
146 additions
and
0 deletions
regex_filter/__init__.py
0 → 100644
+
1
−
0
View file @
d81c4721
from
regex_filter
import
RegexFilterPlugin
This diff is collapsed.
Click to expand it.
regex_filter/manifest.ini
0 → 100644
+
9
−
0
View file @
d81c4721
[info]
name:
Regex
Filter
short_name:
regex_filter
version:
0.1
description:
Filter
incoming
messages
using
regex.
authors:
Yann
Leboulanger
<asterix@lagaule.org>
homepage:
http://gajim.org
This diff is collapsed.
Click to expand it.
regex_filter/regex_filter.py
0 → 100644
+
136
−
0
View file @
d81c4721
# -*- coding: utf-8 -*-
## 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
## 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
## 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/>.
##
'''
Regex Filter plugin.
:author: Yann Leboulanger <asterix@lagaule.org>
:since: 23th September 2011
:copyright: Copyright (2011) Yann Leboulanger <asterix@lagaule.org>
:license: GPLv3
'''
import
re
from
plugins
import
GajimPlugin
from
plugins.helpers
import
log
,
log_calls
from
common
import
gajim
from
common
import
ged
from
command_system.framework
import
CommandContainer
,
command
,
doc
from
command_system.implementation.hosts
import
*
class
RegexFilterPlugin
(
GajimPlugin
):
@log_calls
(
'
RegexFilterPlugin
'
)
def
init
(
self
):
self
.
description
=
_
(
'
Regex Filter Plugin.
'
)
self
.
config_dialog
=
None
self
.
events_handlers
=
{
'
decrypted-message-received
'
:
(
ged
.
PREGUI1
,
self
.
_nec_decrypted_message_received
),
'
gc-message-received
'
:
(
ged
.
PREGUI1
,
self
.
_nec_gc_message_received
),
}
self
.
rules
=
{}
self
.
create_rules
()
@log_calls
(
'
RegexFilterPlugin
'
)
def
activate
(
self
):
FilterCommands
.
enable
()
@log_calls
(
'
RegexFilterPlugin
'
)
def
deactivate
(
self
):
FilterCommands
.
disable
()
@log_calls
(
'
RegexFilterPlugin
'
)
def
create_rules
(
self
):
for
num
,
c
in
self
.
config
.
items
():
self
.
rules
[
int
(
num
)]
=
[
re
.
compile
(
c
[
0
],
re
.
MULTILINE
),
c
[
1
]]
@log_calls
(
'
RegexFilterPlugin
'
)
def
add_rule
(
self
,
search
,
replace
):
if
self
.
rules
:
num
=
max
(
self
.
rules
.
keys
())
+
1
else
:
num
=
0
self
.
config
[
str
(
num
)]
=
[
search
,
replace
]
self
.
create_rules
()
@log_calls
(
'
RegexFilterPlugin
'
)
def
remove_rule
(
self
,
num
):
if
num
in
self
.
config
:
del
self
.
config
[
num
]
self
.
create_rules
()
return
True
return
False
@log_calls
(
'
RegexFilterPlugin
'
)
def
get_rules
(
self
):
return
self
.
config
@log_calls
(
'
RegexFilterPlugin
'
)
def
_nec_all
(
self
,
obj
):
if
not
obj
.
msgtxt
:
return
rules_num
=
self
.
rules
.
keys
()
rules_num
.
sort
()
for
num
in
rules_num
:
rule
=
self
.
rules
[
num
]
obj
.
msgtxt
=
rule
[
0
].
sub
(
rule
[
1
],
obj
.
msgtxt
)
@log_calls
(
'
RegexFilterPlugin
'
)
def
_nec_decrypted_message_received
(
self
,
obj
):
self
.
_nec_all
(
obj
)
@log_calls
(
'
RegexFilterPlugin
'
)
def
_nec_gc_message_received
(
self
,
obj
):
self
.
_nec_all
(
obj
)
class
FilterCommands
(
CommandContainer
):
AUTOMATIC
=
False
HOSTS
=
ChatCommands
,
PrivateChatCommands
,
GroupChatCommands
@command
(
"
add_filter
"
,
raw
=
True
)
@doc
(
_
(
"
Add an incoming filter. First argument is the search regex, second argument is the replace regex.
"
))
def
add_filter
(
self
,
search
,
replace
):
plugin
=
gajim
.
plugin_manager
.
get_active_plugin
(
'
regex_filter
'
)
plugin
.
add_rule
(
search
,
replace
)
return
_
(
'
Added rule to replace %s by %s
'
%
(
search
,
replace
))
@command
(
"
remove_filter
"
,
raw
=
True
)
@doc
(
_
(
"
Remove an incoming filter. Argument is the rule number. See /list_rules command.
"
))
def
remove_filter
(
self
,
num
):
plugin
=
gajim
.
plugin_manager
.
get_active_plugin
(
'
regex_filter
'
)
if
plugin
.
remove_rule
(
num
):
return
_
(
'
Rule number %s removed
'
%
num
)
return
_
(
'
Rule number %s does not exist
'
%
num
)
@command
(
"
list_filters
"
)
@doc
(
_
(
"
List incoming filters.
"
))
def
list_filters
(
self
):
plugin
=
gajim
.
plugin_manager
.
get_active_plugin
(
'
regex_filter
'
)
rules
=
plugin
.
get_rules
()
st
=
''
for
num
,
rule
in
rules
.
items
():
st
+=
_
(
'
%(num)s: %(search)s -> %(replace)s
'
)
%
{
'
num
'
:
num
,
'
search
'
:
rule
[
0
],
'
replace
'
:
rule
[
1
]}
+
'
\n
'
if
st
:
return
st
[:
-
1
]
else
:
return
_
(
'
No rule defined
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment