mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Fixed new bugs caused by assertions
This commit is contained in:
parent
b5d47aa811
commit
771f07529f
@ -72,6 +72,7 @@ def processConfigFile(filename):
|
||||
import debug
|
||||
import irclib
|
||||
import ircmsgs
|
||||
import ircutils
|
||||
import privmsgs
|
||||
import asyncoreDrivers
|
||||
def reportConfigError(filename, msg):
|
||||
@ -86,7 +87,7 @@ def processConfigFile(filename):
|
||||
for command in self.commands:
|
||||
#debug.printf(irc.nick)
|
||||
#debug.printf(command)
|
||||
msg = ircmsgs.privmsg(irc.nick, command)
|
||||
msg = ircmsgs.privmsg(irc.nick, command, prefix=irc.prefix)
|
||||
irc.queueMsg(msg)
|
||||
|
||||
do377 = do376
|
||||
@ -131,9 +132,10 @@ def processConfigFile(filename):
|
||||
(startup, after376) = tuple(itersplit(lines,lambda s: not s, True))
|
||||
#debug.printf('startup: %r' % startup)
|
||||
#debug.printf('after376: %r' % after376)
|
||||
prefix = ircutils.joinHostmask(nick, ident, 'host')
|
||||
for line in filter(None, startup):
|
||||
if not line.startswith('#'):
|
||||
irc.feedMsg(ircmsgs.privmsg(irc.nick, line))
|
||||
irc.feedMsg(ircmsgs.privmsg(irc.nick, line, prefix=prefix))
|
||||
irc.reset()
|
||||
world.startup = False
|
||||
irc.addCallback(ConfigAfter376(after376))
|
||||
|
179
src/ircmsgs.py
179
src/ircmsgs.py
@ -33,11 +33,13 @@ from fix import *
|
||||
|
||||
import re
|
||||
|
||||
import debug
|
||||
import ircutils
|
||||
|
||||
###
|
||||
# IrcMsg class -- used for representing IRC messages acquired from a network.
|
||||
###
|
||||
|
||||
class IrcMsg(object):
|
||||
"""Class to represent an IRC message.
|
||||
"""
|
||||
@ -49,7 +51,8 @@ class IrcMsg(object):
|
||||
args = msg.args
|
||||
if command: # Must be using command=, args=, prefix= form.
|
||||
if args is not None:
|
||||
assert filter(isValidArgument, args) == []
|
||||
#debug.printf(args)
|
||||
assert filter(ircutils.isValidArgument, args) == args
|
||||
else:
|
||||
args = ()
|
||||
else: # Must be using a string.
|
||||
@ -188,192 +191,200 @@ isNick = ircutils.isNick
|
||||
isChannel = ircutils.isChannel
|
||||
isUserHostmask = ircutils.isUserHostmask
|
||||
|
||||
def pong(payload):
|
||||
def pong(payload, prefix=''):
|
||||
"""Takes a payload and returns the proper PONG IrcMsg."""
|
||||
assert payload, 'PONG requires a payload'
|
||||
return IrcMsg(command='PONG', args=(payload,))
|
||||
return IrcMsg(prefix=prefix, command='PONG', args=(payload,))
|
||||
|
||||
def ping(payload):
|
||||
def ping(payload, prefix=''):
|
||||
"""Takes a payload and returns the proper PING IrcMsg."""
|
||||
assert payload, 'PING requires a payload'
|
||||
return IrcMsg(command='PING', args=(payload,))
|
||||
return IrcMsg(prefix=prefix, command='PING', args=(payload,))
|
||||
|
||||
def op(channel, nick):
|
||||
def op(channel, nick, prefix=''):
|
||||
"""Returns a MODE to op nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '+o', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+o', nick))
|
||||
|
||||
def ops(channel, nicks):
|
||||
def ops(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to op each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
return IrcMsg(command=MODE,
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '+' + ('o'*len(nicks)), nicks))
|
||||
|
||||
def deop(channel, nick):
|
||||
def deop(channel, nick, prefix=''):
|
||||
"""Returns a MODE to deop nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '-o', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-o', nick))
|
||||
|
||||
def deops(channel, nicks):
|
||||
def deops(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to deop each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
return IrcMsg(command=MODE, args=(channel, '-' + ('o'*len(nicks)), nicks))
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '-' + ('o'*len(nicks)), nicks))
|
||||
|
||||
def halfop(channel, nick):
|
||||
def halfop(channel, nick, prefix=''):
|
||||
"""Returns a MODE to halfop nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '+h', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+h', nick))
|
||||
|
||||
def halfops(channel, nicks):
|
||||
def halfops(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to halfop each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(command=MODE, args=(channel, '+' + ('h'*len(nicks)), nicks))
|
||||
|
||||
def dehalfop(channel, nick):
|
||||
def dehalfop(channel, nick, prefix=''):
|
||||
"""Returns a MODE to dehalfop nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '-h', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-h', nick))
|
||||
|
||||
def dehalfops(channel, nicks):
|
||||
def dehalfops(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to dehalfop each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
return IrcMsg(command=MODE, args=(channel, '-' + ('h'*len(nicks)), nicks))
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '-' + ('h'*len(nicks)), nicks))
|
||||
|
||||
def voice(channel, nick):
|
||||
def voice(channel, nick, prefix=''):
|
||||
"""Returns a MODE to voice nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '+v', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+v', nick))
|
||||
|
||||
def voices(channel, nicks):
|
||||
def voices(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to voice each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
return IrcMsg(command=MODE, args=(channel, '+' + ('v'*len(nicks)), nicks))
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '+' + ('v'*len(nicks)), nicks))
|
||||
|
||||
def devoice(channel, nick):
|
||||
def devoice(channel, nick, prefix=''):
|
||||
"""Returns a MODE to devoice nick on channel."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
return IrcMsg(command=MODE, args=(channel, '-v', nick))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-v', nick))
|
||||
|
||||
def devoices(channel, nicks):
|
||||
def devoices(channel, nicks, prefix=''):
|
||||
"""Returns a MODE to devoice each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
return IrcMsg(command=MODE, args=(channel, '-' + ('v'*len(nicks)), nicks))
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '-' + ('v'*len(nicks)), nicks))
|
||||
|
||||
def ban(channel, hostmask):
|
||||
def ban(channel, hostmask, prefix=''):
|
||||
"""Returns a MODE to ban nick on channel."""
|
||||
assert isChannel(channel) and isUserHostmask(hostmask)
|
||||
return IrcMsg(command=MODE, args=(channel, '+b', hostmask))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+b', hostmask))
|
||||
|
||||
def bans(channel, hostmasks):
|
||||
def bans(channel, hostmasks, prefix=''):
|
||||
"""Returns a MODE to ban each of nicks on channel."""
|
||||
assert filter(ircutils.isUserHostmask, hostmasks) == []
|
||||
return IrcMsg(command=MODE,
|
||||
assert filter(isUserHostmask, hostmasks) == hostmasks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '+' + ('b'*len(hostmasks)), hostmasks))
|
||||
|
||||
def unban(channel, hostmask):
|
||||
def unban(channel, hostmask, prefix=''):
|
||||
"""Returns a MODE to unban nick on channel."""
|
||||
assert isChannel(channel) and isUserHostmask(hostmask)
|
||||
return IrcMsg(command=MODE, args=(channel, '-b', hostmask))
|
||||
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-b', hostmask))
|
||||
|
||||
def unbans(channel, hostmasks):
|
||||
def unbans(channel, hostmasks, prefix=''):
|
||||
"""Returns a MODE to unban each of nicks on channel."""
|
||||
assert isChannel(channel) and filter(isUserHostmask, hostmasks) == []
|
||||
return IrcMsg(command=MODE,
|
||||
assert isChannel(channel) and filter(isUserHostmask, hostmasks) ==hostmasks
|
||||
return IrcMsg(prefix=prefix, command=MODE,
|
||||
args=(channel, '-' + ('b'*len(hostmasks)), hostmasks))
|
||||
|
||||
def kick(channel, nick, msg=''):
|
||||
def kick(channel, nick, msg='', prefix=''):
|
||||
"""Returns a KICK to kick nick from channel with the message msg."""
|
||||
assert isChannel(channel) and isNick(nick)
|
||||
if msg:
|
||||
return IrcMsg(command='KICK', args=(channel, nick, msg))
|
||||
return IrcMsg(prefix=prefix, command='KICK', args=(channel, nick, msg))
|
||||
else:
|
||||
return IrcMsg(command='KICK', args=(channel, nick))
|
||||
return IrcMsg(prefix=prefix, command='KICK', args=(channel, nick))
|
||||
|
||||
def kicks(channel, nicks, msg=''):
|
||||
def kicks(channel, nicks, msg='', prefix=''):
|
||||
"""Returns a KICK to kick each of nicks from channel with the message msg.
|
||||
"""
|
||||
assert isChannel(channel) and filter(isNick, nicks) == []
|
||||
assert isChannel(channel) and filter(isNick, nicks) == nicks
|
||||
if msg:
|
||||
return IrcMsg(command='KICK', args=(channel, ','.join(nicks), msg))
|
||||
return IrcMsg(prefix=prefix, command='KICK',
|
||||
args=(channel, ','.join(nicks), msg))
|
||||
else:
|
||||
return IrcMsg(command='KICK', args=(channel, ','.join(nicks)))
|
||||
return IrcMsg(prefix=prefix, command='KICK',
|
||||
args=(channel, ','.join(nicks)))
|
||||
|
||||
def privmsg(recipient, msg):
|
||||
def privmsg(recipient, msg, prefix=''):
|
||||
"""Returns a PRIVMSG to recipient with the message msg."""
|
||||
assert (isChannel(recipient) or isNick(recipient)) and msg
|
||||
return IrcMsg(command='PRIVMSG', args=(recipient, msg))
|
||||
return IrcMsg(prefix=prefix, command='PRIVMSG', args=(recipient, msg))
|
||||
|
||||
def action(recipient, msg):
|
||||
def action(recipient, msg, prefix=''):
|
||||
"""Returns a PRIVMSG ACTION to recipient with the message msg."""
|
||||
assert (isChannel(recipient) or isNick(recipient)) and msg
|
||||
return IrcMsg(command='PRIVMSG', args=(recipient,'\x01ACTION %s\x01'% msg))
|
||||
return IrcMsg(prefix=prefix, command='PRIVMSG',
|
||||
args=(recipient,'\x01ACTION %s\x01'% msg))
|
||||
|
||||
def notice(recipient, msg):
|
||||
def notice(recipient, msg, prefix=''):
|
||||
"""Returns a NOTICE to recipient with the message msg."""
|
||||
assert (isChannel(recipient) or isNick(recipient)) and msg
|
||||
return IrcMsg(command='NOTICE', args=(recipient, msg))
|
||||
return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, msg))
|
||||
|
||||
def join(channel):
|
||||
def join(channel, prefix=''):
|
||||
"""Returns a JOIN to a channel"""
|
||||
assert isChannel(channel)
|
||||
return IrcMsg(command='JOIN', args=(channel,))
|
||||
return IrcMsg(prefix=prefix, command='JOIN', args=(channel,))
|
||||
|
||||
def joins(channels):
|
||||
def joins(channels, prefix=''):
|
||||
"""Returns a JOIN to each of channels."""
|
||||
assert filter(isChannel, channels) == []
|
||||
return IrcMsg(command='JOIN', args=(','.join(channels),))
|
||||
assert filter(isChannel, channels) == channels
|
||||
return IrcMsg(prefix=prefix, command='JOIN', args=(','.join(channels),))
|
||||
|
||||
def part(channel, msg=""):
|
||||
def part(channel, msg='', prefix=''):
|
||||
"""Returns a PART from channel with the message msg."""
|
||||
assert isChannel(channel)
|
||||
if msg:
|
||||
return IrcMsg(command='PART', args=(channel, msg))
|
||||
return IrcMsg(prefix=prefix, command='PART', args=(channel, msg))
|
||||
else:
|
||||
return IrcMsg(command='PART', args=(channel,))
|
||||
return IrcMsg(prefix=prefix, command='PART', args=(channel,))
|
||||
|
||||
def parts(channels, msg=""):
|
||||
def parts(channels, msg='', prefix=''):
|
||||
"""Returns a PART from each of channels with the message msg."""
|
||||
assert filter(isChannel, channels) == []
|
||||
assert filter(isChannel, channels) == channels
|
||||
if msg:
|
||||
return IrcMsg(command='PART', args=(','.join(channels), msg,))
|
||||
return IrcMsg(prefix=prefix, command='PART',
|
||||
args=(','.join(channels), msg,))
|
||||
else:
|
||||
return IrcMsg(command='PART', args=(','.join(channels),))
|
||||
return IrcMsg(prefix=prefix, command='PART',
|
||||
args=(','.join(channels),))
|
||||
|
||||
def quit(msg=''):
|
||||
def quit(msg='', prefix=''):
|
||||
"""Returns a QUIT with the message msg."""
|
||||
if msg:
|
||||
return IrcMsg(command='QUIT', args=(msg,))
|
||||
return IrcMsg(prefix=prefix, command='QUIT', args=(msg,))
|
||||
else:
|
||||
return IrcMsg(command='QUIT')
|
||||
return IrcMsg(prefix=prefix, command='QUIT')
|
||||
|
||||
def topic(channel, topic):
|
||||
def topic(channel, topic, prefix=''):
|
||||
"""Returns a TOPIC for channel with the topic topic."""
|
||||
assert isChannel(channel)
|
||||
return IrcMsg(command='TOPIC', args=(channel, topic))
|
||||
return IrcMsg(prefix=prefix, command='TOPIC', args=(channel, topic))
|
||||
|
||||
def nick(nick):
|
||||
def nick(nick, prefix=''):
|
||||
"""Returns a NICK with nick nick."""
|
||||
assert isNick(nick)
|
||||
return IrcMsg(command='NICK', args=(nick,))
|
||||
return IrcMsg(prefix=prefix, command='NICK', args=(nick,))
|
||||
|
||||
def user(user, ident):
|
||||
def user(user, ident, prefix=''):
|
||||
"""Returns a USER with ident ident and user user."""
|
||||
assert isValidArgument(ident)
|
||||
return IrcMsg(command='USER', args=(ident, '0', '*', user))
|
||||
return IrcMsg(prefix=prefix, command='USER', args=(ident, '0', '*', user))
|
||||
|
||||
def who(hostmaskOrChannel):
|
||||
def who(hostmaskOrChannel, prefix=''):
|
||||
"""Returns a WHO for the hostmask or channel hostmaskOrChannel."""
|
||||
assert isChannel(hostmaskOrChannel) or isUserHostmask(hostmaskOrChannel)
|
||||
return IrcMsg(command='WHO', args=(hostmaskOrChannel,))
|
||||
return IrcMsg(prefix=prefix, command='WHO', args=(hostmaskOrChannel,))
|
||||
|
||||
def whois(nick):
|
||||
def whois(nick, prefix=''):
|
||||
"""Returns a WHOIS for nick."""
|
||||
assert isNick(nick)
|
||||
return IrcMsg(command='WHOIS', args=(nick,))
|
||||
|
||||
def invite(channel, nick):
|
||||
def invite(channel, nick, prefix=''):
|
||||
"""Returns an INVITE for nick."""
|
||||
assert isNick(nick)
|
||||
return IrcMsg(command='INVITE', args=(channel, nick))
|
||||
return IrcMsg(prefix=prefix, command='INVITE', args=(channel, nick))
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user