Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MessageParser: Add support for global triggers.

  • Loading branch information...
commit a565b7f7d7c24c0b18e293be21287fcd534b030e 1 parent d3da0c2
@ProgVal authored
Showing with 29 additions and 24 deletions.
  1. +29 −24 plugins/MessageParser/plugin.py
View
53 plugins/MessageParser/plugin.py
@@ -115,7 +115,8 @@ def getDb(self, channel):
return db
def _updateRank(self, channel, regexp):
- if self.registryValue('keepRankInfo', channel):
+ subfolder = None if channel == 'global' else channel
+ if self.registryValue('keepRankInfo', subfolder):
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("""SELECT usage_count
@@ -156,13 +157,17 @@ def doPrivmsg(self, irc, msg):
if callbacks.addressed(irc.nick, msg): #message is direct command
return
actions = []
- db = self.getDb(channel)
- cursor = db.cursor()
- cursor.execute("SELECT regexp, action FROM triggers")
- results = cursor.fetchall()
+ results = []
+ for channel in (channel, 'global'):
+ db = self.getDb(channel)
+ cursor = db.cursor()
+ cursor.execute("SELECT regexp, action FROM triggers")
+ # Fetch results and prepend channel name or 'global'. This
+ # prevents duplicating the following lines.
+ results.extend(map(lambda x: (channel,)+x, cursor.fetchall()))
if len(results) == 0:
return
- for (regexp, action) in results:
+ for (channel, regexp, action) in results:
for match in re.finditer(regexp, msg.args[1]):
if match is not None:
thisaction = action
@@ -176,7 +181,7 @@ def doPrivmsg(self, irc, msg):
@internationalizeDocstring
def add(self, irc, msg, args, channel, regexp, action):
- """[<channel>] <regexp> <action>
+ """[<channel>|global] <regexp> <action>
Associates <regexp> with <action>. <channel> is only
necessary if the message isn't sent on the channel
@@ -212,11 +217,11 @@ def add(self, irc, msg, args, channel, regexp, action):
else:
irc.error(_('That trigger is locked.'))
return
- add = wrap(add, ['channel', 'something', 'something'])
+ add = wrap(add, ['channelOrGlobal', 'something', 'something'])
@internationalizeDocstring
def remove(self, irc, msg, args, channel, optlist, regexp):
- """[<channel>] [--id] <regexp>]
+ """[<channel>|global] [--id] <regexp>]
Removes the trigger for <regexp> from the triggers database.
<channel> is only necessary if
@@ -248,13 +253,13 @@ def remove(self, irc, msg, args, channel, optlist, regexp):
cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,))
db.commit()
irc.replySuccess()
- remove = wrap(remove, ['channel',
+ remove = wrap(remove, ['channelOrGlobal',
getopts({'id': '',}),
'something'])
@internationalizeDocstring
def lock(self, irc, msg, args, channel, regexp):
- """[<channel>] <regexp>
+ """[<channel>|global] <regexp>
Locks the <regexp> so that it cannot be
removed or overwritten to. <channel> is only necessary if the message isn't
@@ -273,11 +278,11 @@ def lock(self, irc, msg, args, channel, regexp):
cursor.execute("UPDATE triggers SET locked=1 WHERE regexp=?", (regexp,))
db.commit()
irc.replySuccess()
- lock = wrap(lock, ['channel', 'text'])
+ lock = wrap(lock, ['channelOrGlobal', 'text'])
@internationalizeDocstring
def unlock(self, irc, msg, args, channel, regexp):
- """[<channel>] <regexp>
+ """[<channel>|global] <regexp>
Unlocks the entry associated with <regexp> so that it can be
removed or overwritten. <channel> is only necessary if the message isn't
@@ -296,11 +301,11 @@ def unlock(self, irc, msg, args, channel, regexp):
cursor.execute("UPDATE triggers SET locked=0 WHERE regexp=?", (regexp,))
db.commit()
irc.replySuccess()
- unlock = wrap(unlock, ['channel', 'text'])
+ unlock = wrap(unlock, ['channelOrGlobal', 'text'])
@internationalizeDocstring
def show(self, irc, msg, args, channel, optlist, regexp):
- """[<channel>] [--id] <regexp>
+ """[<channel>|global] [--id] <regexp>
Looks up the value of <regexp> in the triggers database.
<channel> is only necessary if the message isn't sent in the channel
@@ -323,13 +328,13 @@ def show(self, irc, msg, args, channel, optlist, regexp):
return
irc.reply("The action for regexp trigger \"%s\" is \"%s\"" % (regexp, action))
- show = wrap(show, ['channel',
+ show = wrap(show, ['channelOrGlobal',
getopts({'id': '',}),
'something'])
@internationalizeDocstring
def info(self, irc, msg, args, channel, optlist, regexp):
- """[<channel>] [--id] <regexp>
+ """[<channel>|global] [--id] <regexp>
Display information about <regexp> in the triggers database.
<channel> is only necessary if the message isn't sent in the channel
@@ -362,13 +367,13 @@ def info(self, irc, msg, args, channel, optlist, regexp):
time.localtime(int(added_at))),
usage_count,
locked and _("locked") or _("not locked"),))
- info = wrap(info, ['channel',
+ info = wrap(info, ['channelOrGlobal',
getopts({'id': '',}),
'something'])
@internationalizeDocstring
def list(self, irc, msg, args, channel):
- """[<channel>]
+ """[<channel>|global]
Lists regexps present in the triggers database.
<channel> is only necessary if the message isn't sent in the channel
@@ -387,11 +392,11 @@ def list(self, irc, msg, args, channel):
s = [ "\"%s\" (%d)" % (regexp[0], regexp[1]) for regexp in regexps ]
separator = self.registryValue('listSeparator', channel)
irc.reply(separator.join(s))
- list = wrap(list, ['channel'])
+ list = wrap(list, ['channelOrGlobal'])
@internationalizeDocstring
def rank(self, irc, msg, args, channel):
- """[<channel>]
+ """[<channel>|global]
Returns a list of top-ranked regexps, sorted by usage count
(rank). The number of regexps returned is set by the
@@ -411,11 +416,11 @@ def rank(self, irc, msg, args, channel):
return
s = [ "#%d \"%s\" (%d)" % (i+1, regexp[0], regexp[1]) for i, regexp in enumerate(regexps) ]
irc.reply(", ".join(s))
- rank = wrap(rank, ['channel'])
+ rank = wrap(rank, ['channelOrGlobal'])
@internationalizeDocstring
def vacuum(self, irc, msg, args, channel):
- """[<channel>]
+ """[<channel>|global]
Vacuums the database for <channel>.
See SQLite vacuum doc here: http://www.sqlite.org/lang_vacuum.html
@@ -433,7 +438,7 @@ def vacuum(self, irc, msg, args, channel):
cursor.execute("""VACUUM""")
db.commit()
irc.replySuccess()
- vacuum = wrap(vacuum, ['channel'])
+ vacuum = wrap(vacuum, ['channelOrGlobal'])
MessageParser = internationalizeDocstring(MessageParser)
Class = MessageParser
Please sign in to comment.
Something went wrong with that request. Please try again.