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