Update of /cvsroot/pybot/pybot/pybot/modules
In directory usw-pr-cvs1:/tmp/cvs-serv20766/modules
Modified Files:
plock.py uptime.py
Added Files:
help.py
Log Message:
- Fixed little bug in Options.getsoft() keepalive handling
- Implemented help module, offering an online help api for other modules
(have a look at plock.py for an example).
--- NEW FILE: help.py ---
# Copyright (c) 2000-2001 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 hooks, mm, options
import re
HELP = [
("""\
You may ask for help using "[show] help [about] <keyword>".\
""",)
]
class Help:
def __init__(self, bot):
self.data = options.getsoft("Help.data", {})
mm.register("register_help", self.mm_register_help)
mm.register("unregister_help", self.mm_unregister_help)
hooks.register("Message", self.message)
# [show] help [about] <keyword>
self.re1 = re.compile(r"(?:show\s+)?help(?:\s+about)?(?:\s+(?P<keyword>\S+))?\s*[.!]*$", re.I)
def unload(self):
hooks.unregister("Message", self.message)
mm.unregister("register_help")
mm.unregister("unregister_help")
def message(self, msg):
if msg.forme:
m = self.re1.match(msg.line)
if m:
if mm.hasperm(0, msg.server.servername, msg.target, msg.user, "help"):
keyword = m.group("keyword")
if keyword:
text = self.data.get(keyword)
else:
text = HELP
if text:
for line in text:
msg.answer("%:", *line)
else:
msg.answer("%:", ["No", "Sorry, no", "Sorry, but there's no"], "help about that", [".", "!"])
else:
msg.answer("%:", ["Sorry, you", "You"], ["can't", "are not allowed to"], "ask for help", [".", "!"])
return 0
def mm_register_help(self, defret, keywords, text):
for keyword in keywords:
self.data[keyword] = text
def mm_unregister_help(self, defret, keywords):
for keyword in keywords:
try:
del self.data[keyword]
except KeyError:
pass
def __loadmodule__(bot):
global help
help = Help(bot)
def __unloadmodule__(bot):
global help
help.unload()
del help
# vim:ts=4:sw=4:nowrap
Index: plock.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/plock.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** plock.py 2001/11/02 17:20:27 1.1.1.1
--- plock.py 2001/11/13 20:39:25 1.2
***************
*** 23,26 ****
--- 23,37 ----
import re
+ HELP = [
+ ("""\
+ You may (un)plock packages using "[force] [un]plock <package> [,<package>]". \
+ It's also possible to consult your plocks using "my plocks", or from \
+ somebody else using "plocks of <nick|email>".\
+ """,),
+ ("""\
+ Note that to be able to work with plocks, you must first register an \
+ email with "register email your@email".\
+ """,)]
+
class PLockFile:
def __init__(self, dir, name):
***************
*** 72,77 ****
--- 83,91 ----
self.re5 = re.compile(r"plock\s+(?P<package>[\w_-]+(?:(?:\s*,?\s*and\s+|[, ]+)[\w_-]+)*)\s*(?:!*\?[?!]*)$")
+ mm.register_help(0, ["plock", "unplock"], HELP)
+
def unload(self):
hooks.unregister("Message", self.message)
+ mm.unregister_help(0, ["plock", "unplock"])
def getnick(self, server, email):
Index: uptime.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/uptime.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** uptime.py 2001/11/02 17:20:27 1.1.1.1
--- uptime.py 2001/11/13 20:39:25 1.2
***************
*** 24,28 ****
class Uptime:
def __init__(self, bot):
! self.uptime = options.getsoft("Uptime.uptime", int(time.time()), 0)
hooks.register("Message", self.message)
--- 24,28 ----
class Uptime:
def __init__(self, bot):
! self.uptime = options.getsoft("Uptime.uptime", int(time.time()))
hooks.register("Message", self.message)
|