Added ignores.

This commit is contained in:
Jeremy Fincher 2004-04-30 19:19:59 +00:00
parent 6e6d619f48
commit ea90ba36db
1 changed files with 36 additions and 0 deletions

View File

@ -38,6 +38,7 @@ __revision__ = "$Id$"
import plugins import plugins
import sets
import time import time
import getopt import getopt
import os.path import os.path
@ -72,6 +73,11 @@ conf.registerGlobalValue(conf.supybot.plugins.Note, 'notifyOnJoinRepeatedly',
when they join the channel, the bot will tell them they have unread when they join the channel, the bot will tell them they have unread
messages, even if it's told them before.""")) messages, even if it's told them before."""))
class Ignores(registry.SpaceSeparatedListOfStrings):
List = ircutils.IrcSet
conf.registerUserValue(conf.users.plugins.Note, 'ignores', Ignores([], ''))
class NoteDb(plugins.DBHandler): class NoteDb(plugins.DBHandler):
def makeDb(self, filename): def makeDb(self, filename):
"create Notes database and tables" "create Notes database and tables"
@ -158,9 +164,13 @@ class Note(callbacks.Privmsg):
return return
try: try:
fromId = ircdb.users.getUserId(msg.prefix) fromId = ircdb.users.getUserId(msg.prefix)
senderName = ircdb.users.getUser(fromId).name
except KeyError: except KeyError:
irc.errorNotRegistered() irc.errorNotRegistered()
return return
if senderName in self.userValue('ignores', name):
irc.error('That user has ignored messages from you.')
return
if ircutils.isChannel(msg.args[0]): if ircutils.isChannel(msg.args[0]):
public = 1 public = 1
else: else:
@ -260,6 +270,32 @@ class Note(callbacks.Privmsg):
else: else:
return '#%s (private)' % id return '#%s (private)' % id
def ignore(self, irc, msg, args):
"""[--remove] <user>
Ignores all messages from <user>. If --remove is listed, remove <user>
from the list of users being ignored.
"""
remove = False
while '--remove' in args:
remove = True
args.remove('--remove')
user = privmsgs.getArgs(args)
try:
L = self.userValue('ignores', msg.prefix)
if remove:
try:
L.remove(user)
except (KeyError, ValueError):
irc.error('%r was not in your list of ignores.' % user)
return
else:
L.add(user)
self.setUserValue(msg.prefix, 'ignores', L, setValue=True)
irc.replySuccess()
except KeyError:
irc.errorNoUser()
def list(self, irc, msg, args): def list(self, irc, msg, args):
"""[--{old,sent}] [--{from,to} <user>] """[--{old,sent}] [--{from,to} <user>]