Update of /cvsroot/pybot/pybot/pybot
In directory sc8-pr-cvs1:/tmp/cvs-serv22909/pybot
Modified Files:
misc.py
Added Files:
locals.py
Log Message:
* pybot/misc.py,modules/help.py,modules/*: Now regular
expressions are using a single space, and misc.regexp()
and mm.register_help() convert them to \s+ and \s*.
* pybot/misc.py: Fixed small issues on buildanswer().
* pybot/locals.py,pybot/misc.py,modules/*:
Introduced pybot.locals. All basic instances of the pybot
API are now defined on this file, and all modules are
running "from pybot.locals import *".
* pybot/misc.py,modules/*: Introduced misc.regexp(). This
function is a wrapper on top of re.compile() which will
deal better with the pybot triggers expressions.
--- NEW FILE: locals.py ---
# Copyright (c) 2000-2003 Gustavo Niemeyer <nie...@co...>
#
# This file is part of pybot.
#
# pybot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# pybot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pybot; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from pybot import *
from pybot.misc import regexp
# vim:ts=4:sw=4:et
Index: misc.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/misc.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** misc.py 12 May 2003 20:42:20 -0000 1.4
--- misc.py 24 Aug 2003 19:30:53 -0000 1.5
***************
*** 20,23 ****
--- 20,24 ----
from random import randint
from string import rfind
+ import re
__all__ = ["buildanswer", "breakline"]
***************
*** 40,74 ****
recret = buildanswer(tmptok, target, nick)
ret.append(recret)
! elif tok[0] == ":":
! tok = tok[1:]
! if tok[0] == "%":
! if nick != target:
ret.append(":"+nick+tok[1:])
! elif tok[0] == "/":
! ret.append(":"+nick+tok[1:])
! elif tok[0] == "\\":
! ret.append(":"+tok[1:])
! elif tok != None:
! ret.append(":"+tok)
! else:
! if tok[0] == "%":
! if nick != target:
ret.append(nick+tok[1:])
! elif tok[0] == "/":
! ret.append(nick+tok[1:])
! elif tok[0] == "\\":
! ret.append(tok[1:])
! elif tok != None:
! ret.append(tok)
if ret:
! str = ret[0]
for tok in ret[1:]:
if tok[0] in [".","!","?",","]:
! str = str+tok
else:
! str = str+" "+tok
else:
! str = ""
! return str
def breakline(line):
--- 41,77 ----
recret = buildanswer(tmptok, target, nick)
ret.append(recret)
! elif tok:
! tok = str(tok)
! if tok[0] == ":":
! tok = tok[1:]
! if tok[0] == "%":
! if nick != target:
! ret.append(":"+nick+tok[1:])
! elif tok[0] == "/":
ret.append(":"+nick+tok[1:])
! elif tok[0] == "\\":
! ret.append(":"+tok[1:])
! else:
! ret.append(":"+tok)
! else:
! if tok[0] == "%":
! if nick != target:
! ret.append(nick+tok[1:])
! elif tok[0] == "/":
ret.append(nick+tok[1:])
! elif tok[0] == "\\":
! ret.append(tok[1:])
! else:
! ret.append(tok)
if ret:
! s = ret[0]
for tok in ret[1:]:
if tok[0] in [".","!","?",","]:
! s += tok
else:
! s += " "+tok
else:
! s = ""
! return s
def breakline(line):
***************
*** 87,90 ****
--- 90,112 ----
startpos = endpos
endpos = startpos+MAXLINESIZE
+
+ def regexp(*args, **kwargs):
+ expr = "".join([str(x) for x in args])
+ expr = expr.replace(" *", r"\s*")
+ expr = expr.replace(" ?", r"\s*")
+ expr = expr.replace(" ", r"\s+")
+ if kwargs.get("needpunct"):
+ if kwargs.get("question"):
+ expr += "[!\s]*\?[!?\s*]*$"
+ else:
+ expr += "\s*[.!][.!\s]*$"
+ else:
+ if kwargs.get("question"):
+ expr += "[!?.\s]*$"
+ elif not kwargs.get("nopunct"):
+ expr += "[!.\s]*$"
+ else:
+ expr += "\s*$"
+ return re.compile(expr, re.I)
# vim:ts=4:sw=4:et
|