Added multiple recipient support.

This commit is contained in:
Jeremy Fincher 2004-07-20 07:03:15 +00:00
parent 1cc62cf609
commit 35e2c45f2f

View File

@ -72,6 +72,10 @@ conf.registerGlobalValue(conf.supybot.plugins.Note, 'notifyOnJoinRepeatedly',
notify people of their new messages when they join the channel. That means notify people of their new messages when they join the channel. That means
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."""))
conf.registerUserValue(conf.users.plugins.Note, 'notifyWithNotice',
registry.Boolean(False, """Determines whether the bot will notify users of
new messages with a NOTICE, rather than a PRIVMSG, so their clients won't
open a new query window."""))
class Ignores(registry.SpaceSeparatedListOfStrings): class Ignores(registry.SpaceSeparatedListOfStrings):
List = ircutils.IrcSet List = ircutils.IrcSet
@ -141,52 +145,77 @@ class Note(callbacks.Privmsg):
s = 'You have %s; ' \ s = 'You have %s; ' \
'%s that I haven\'t told you about before now..' % \ '%s that I haven\'t told you about before now..' % \
(utils.nItems('note', unread, 'unread'), unnotified) (utils.nItems('note', unread, 'unread'), unnotified)
irc.queueMsg(ircmsgs.privmsg(msg.nick, s)) maker = ircmsgs.privmsg
if self.userValue('notifyWithNotice', msg.prefix):
maker = ircmsgs.notice
irc.queueMsg(maker(msg.nick, s))
cursor.execute("""UPDATE notes SET notified=1 cursor.execute("""UPDATE notes SET notified=1
WHERE notes.to_id=%s""", id) WHERE notes.to_id=%s""", id)
db.commit() db.commit()
def send(self, irc, msg, args): def getUserId(self, irc, name):
"""<recipient> <text>
Sends a new note to the user specified.
"""
(name, note) = privmsgs.getArgs(args, required=2)
if ircdb.users.hasUser(name): if ircdb.users.hasUser(name):
toId = ircdb.users.getUserId(name) return ircdb.users.getUserId(name)
else: else:
# name must be a nick, we'll try that.
try: try:
hostmask = irc.state.nickToHostmask(name) hostmask = irc.state.nickToHosmtask(name)
toId = ircdb.users.getUserId(hostmask) return ircdb.users.getUserId(hostmask)
except KeyError: except KeyError:
irc.errorNoUser() return None
return
def send(self, irc, msg, args):
"""<recipient>,[<recipient>,[...]] <text>
Sends a new note to the user specified. Multiple recipients may be
specified by separating their names by commas, with *no* spaces
between.
"""
(names, note) = privmsgs.getArgs(args, required=2)
# Let's get the from user.
try: try:
fromId = ircdb.users.getUserId(msg.prefix) fromId = ircdb.users.getUserId(msg.prefix)
senderName = ircdb.users.getUser(fromId).name senderName = ircdb.users.getUser(fromId).name
except KeyError: except KeyError:
irc.errorNotRegistered() irc.errorNotRegistered()
return return
if senderName in self.userValue('ignores', name): # Let's get the publicitousness.
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:
public = 0 public = 0
names = names.split(',')
ids = [self.getUserId(irc, name) for name in names]
badnames = []
if None in ids:
for (id, name) in zip(ids, names):
if id is None:
badnames.append(name)
irc.errorNoUser(name=utils.commaAndify(badnames, And='or'))
return
for name in names:
if senderName in self.userValue('ignores', name):
badnames.append(name)
if badnames:
irc.error('%s %s ignoring notes from you.' % \
(utils.commaAndify(badnames), utils.be(len(badnames))))
return
db = self.dbHandler.getDb() db = self.dbHandler.getDb()
cursor = db.cursor() cursor = db.cursor()
now = int(time.time()) now = int(time.time())
cursor.execute("""INSERT INTO notes VALUES sent = []
(NULL, %s, %s, %s, 0, 0, %s, %s)""", for (name, toId) in zip(names, ids):
fromId, toId, now, public, note) cursor.execute("""INSERT INTO notes VALUES
(NULL, %s, %s, %s, 0, 0, %s, %s)""",
fromId, toId, now, public, note)
cursor.execute("""SELECT id FROM notes WHERE
from_id=%s AND to_id=%s AND added_at=%s""",
fromId, toId, now)
s = 'note %s sent to %s' % (cursor.fetchone()[0], name)
sent.append(s)
db.commit() db.commit()
cursor.execute("""SELECT id FROM notes WHERE irc.reply(utils.commaAndify(sent).capitalize() + '.')
from_id=%s AND to_id=%s AND added_at=%s""",
fromId, toId, now)
id = cursor.fetchone()[0]
irc.reply('Note #%s sent to %s.' % (id, name))
def unsend(self, irc, msg, args): def unsend(self, irc, msg, args):
"""<id> """<id>