mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
Fixed lacking irc.error and irc.reply in PrivmsgRegexp; pulled reply functionality into its own function.
This commit is contained in:
parent
3a6c557fd0
commit
25d4f1238e
@ -46,7 +46,6 @@ import ircmsgs
|
|||||||
import ircutils
|
import ircutils
|
||||||
|
|
||||||
import debug
|
import debug
|
||||||
import world
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Privmsg: handles privmsg commands in a standard fashion.
|
# Privmsg: handles privmsg commands in a standard fashion.
|
||||||
@ -77,6 +76,18 @@ def canonicalName(command):
|
|||||||
"""
|
"""
|
||||||
return command.translate(string.ascii, '\t -_').lower()
|
return command.translate(string.ascii, '\t -_').lower()
|
||||||
|
|
||||||
|
def reply(msg, s):
|
||||||
|
"""Makes a reply to msg with the payload s"""
|
||||||
|
if ircutils.funkyArgument(s):
|
||||||
|
s = repr(s)
|
||||||
|
if ircutils.isChannel(msg.args[0]):
|
||||||
|
m = ircmsgs.privmsg(msg.args[0], '%s: %s' % (msg.nick, s))
|
||||||
|
else:
|
||||||
|
m = ircmsgs.privmsg(msg.nick, s)
|
||||||
|
if len(m) > 450:
|
||||||
|
m = reply(msg, 'My reponse would\'ve been too long.')
|
||||||
|
return m
|
||||||
|
|
||||||
class RateLimiter:
|
class RateLimiter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lastRequest = {}
|
self.lastRequest = {}
|
||||||
@ -229,16 +240,7 @@ class IrcObjectProxy:
|
|||||||
if isinstance(self.irc, self.__class__):
|
if isinstance(self.irc, self.__class__):
|
||||||
self.irc.reply(msg, s)
|
self.irc.reply(msg, s)
|
||||||
else:
|
else:
|
||||||
if ircutils.funkyArgument(s):
|
self.irc.queueMsg(reply(msg, s))
|
||||||
s = repr(s)
|
|
||||||
if ircutils.isChannel(msg.args[0]):
|
|
||||||
m = ircmsgs.privmsg(msg.args[0], '%s: %s' % (msg.nick, s))
|
|
||||||
else:
|
|
||||||
m = ircmsgs.privmsg(msg.nick, s)
|
|
||||||
if len(m) > 511 - len(self.irc.prefix):
|
|
||||||
self.reply(msg, 'My response would\'ve been too long.')
|
|
||||||
else:
|
|
||||||
self.irc.queueMsg(m)
|
|
||||||
else:
|
else:
|
||||||
self.args[self.counter] = s
|
self.args[self.counter] = s
|
||||||
self.evalArgs()
|
self.evalArgs()
|
||||||
@ -260,6 +262,9 @@ class IrcObjectProxy:
|
|||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return getattr(self.irc, attr)
|
return getattr(self.irc, attr)
|
||||||
|
|
||||||
|
## def __setattr__(self, attr, value):
|
||||||
|
## setattr(self.irc, attr, value)
|
||||||
|
|
||||||
|
|
||||||
class Privmsg(irclib.IrcCallback):
|
class Privmsg(irclib.IrcCallback):
|
||||||
"""Base class for all Privmsg handlers."""
|
"""Base class for all Privmsg handlers."""
|
||||||
@ -311,6 +316,24 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
IrcObjectProxy(irc, msg, Tokenizer().tokenize(s))
|
IrcObjectProxy(irc, msg, Tokenizer().tokenize(s))
|
||||||
|
|
||||||
|
|
||||||
|
class IrcObjectProxyRegexp:
|
||||||
|
def __init__(self, irc):
|
||||||
|
self.irc = irc
|
||||||
|
|
||||||
|
def error(self, msg, s):
|
||||||
|
self.irc.queueMsg(reply(msg, 'Error: ' + s))
|
||||||
|
|
||||||
|
def reply(self, msg, s):
|
||||||
|
self.irc.queueMsg(reply(msg, s))
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
print attr
|
||||||
|
return getattr(self.irc, attr)
|
||||||
|
|
||||||
|
## def __setattr__(self, attr, value):
|
||||||
|
## setattr(self.irc, attr, value)
|
||||||
|
|
||||||
|
|
||||||
class PrivmsgRegexp(Privmsg):
|
class PrivmsgRegexp(Privmsg):
|
||||||
"""A class to allow a person to create regular expression callbacks.
|
"""A class to allow a person to create regular expression callbacks.
|
||||||
|
|
||||||
@ -355,4 +378,5 @@ class PrivmsgRegexp(Privmsg):
|
|||||||
debug.debugMsg(s)
|
debug.debugMsg(s)
|
||||||
m = r.search(msg.args[1])
|
m = r.search(msg.args[1])
|
||||||
if m:
|
if m:
|
||||||
|
irc = IrcObjectProxyRegexp(irc)
|
||||||
self.callCommand(value, (irc, msg, m))
|
self.callCommand(value, (irc, msg, m))
|
||||||
|
Loading…
Reference in New Issue
Block a user