pybot-commits Mailing List for pybot (Page 8)
Brought to you by:
niemeyer
You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(6) |
Dec
(7) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
|
Feb
|
Mar
(1) |
Apr
(7) |
May
(1) |
Jun
(14) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(56) |
Jun
(4) |
Jul
|
Aug
(85) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
|
From: Gustavo N. <nie...@us...> - 2001-12-04 00:57:41
|
Update of /cvsroot/pybot/pybot/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv32496/scripts
Modified Files:
pybotopt.py pybotsetup.py
Removed Files:
pybot.py
Log Message:
- Implemented new startup system.
- Converted tabs to spaces so people using other editors feel
confortable as well (suggested by John Thingstad).
Index: pybotopt.py
===================================================================
RCS file: /cvsroot/pybot/pybot/scripts/pybotopt.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** pybotopt.py 2001/11/02 17:20:37 1.1.1.1
--- pybotopt.py 2001/12/04 00:57:38 1.2
***************
*** 34,87 ****
random.seed(time.time())
!
def random_answer(*pattern):
! ret = []
! for tok in pattern:
! if type(tok) == type(()):
! recret = self._answer(tok)
! ret = ret + recret
! elif type(tok) == type([]):
! tmptok = tok[random.randint(0,len(tok)-1)]
! if type(tmptok) == type(""):
! ret.append(tmptok)
! elif tmptok != None:
! recret = self._answer(tmptok)
! ret.append(recret)
! 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
if len(sys.argv)==3 and sys.argv[1] in ["show","print"]:
! if os.path.exists("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
! if not option.has_key(sys.argv[2]):
! print random_answer(["It seems that", "Sorry, but", "Sir,"], "there's not such option.")
! else:
! print option[sys.argv[2]]
! else:
! print "There's no options file, sir!"
elif len(sys.argv)>5 and sys.argv[1:3]==["set"] and sys.argv[4] == "to":
! if os.path.exists("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
! else:
! option = {}
! option[sys.argv[3]] = eval(string.join(sys.argv[5:]))
! file = open("options", "w")
! option = cPickle.dump(option,file,1)
! file.close()
! print "Done, sir!"
! # vim:ts=4:sw=4
--- 34,87 ----
random.seed(time.time())
!
def random_answer(*pattern):
! ret = []
! for tok in pattern:
! if type(tok) == type(()):
! recret = self._answer(tok)
! ret = ret + recret
! elif type(tok) == type([]):
! tmptok = tok[random.randint(0,len(tok)-1)]
! if type(tmptok) == type(""):
! ret.append(tmptok)
! elif tmptok != None:
! recret = self._answer(tmptok)
! ret.append(recret)
! 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
if len(sys.argv)==3 and sys.argv[1] in ["show","print"]:
! if os.path.exists("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
! if not option.has_key(sys.argv[2]):
! print random_answer(["It seems that", "Sorry, but", "Sir,"], "there's not such option.")
! else:
! print option[sys.argv[2]]
! else:
! print "There's no options file, sir!"
elif len(sys.argv)>5 and sys.argv[1:3]==["set"] and sys.argv[4] == "to":
! if os.path.exists("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
! else:
! option = {}
! option[sys.argv[3]] = eval(string.join(sys.argv[5:]))
! file = open("options", "w")
! option = cPickle.dump(option,file,1)
! file.close()
! print "Done, sir!"
! # vim:ts=4:sw=4:et
Index: pybotsetup.py
===================================================================
RCS file: /cvsroot/pybot/pybot/scripts/pybotsetup.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** pybotsetup.py 2001/11/02 17:20:37 1.1.1.1
--- pybotsetup.py 2001/12/04 00:57:38 1.2
***************
*** 28,39 ****
if os.path.isfile("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
else:
! option = {}
try:
! print """
This program does the basic setup for pybot. It will allow you to
set the first nick, username and server you want pybot to connect,
--- 28,39 ----
if os.path.isfile("options"):
! file = open("options")
! option = cPickle.load(file)
! file.close()
else:
! option = {}
try:
! print """
This program does the basic setup for pybot. It will allow you to
set the first nick, username and server you want pybot to connect,
***************
*** 48,92 ****
everything else.
"""
! raw_input("Press [ENTER] to continue...")
! print """
Enter the nick you're going to use while talking to pybot."""
! nick = raw_input("Your nick: ")
! print """Enter the username you're going to use while talking to pybot.
Please, note that you may have a '~' added to your username, depending on
your host's configuration. If you want to be sure what your username is,
issue a '/whois %s' while connected to your irc server. You may also
use a wildcard, like *username, if you're not sure at all."""%nick
! username = raw_input("Your username: ")
! print """
Enter the hostname you're going to use while talking to pybot.
If you're not sure, you should also look at the output of the command
'/whois %s' while connected to your irc server. A wildcard like
*.my.host also work here, but be careful!"""%nick
! hostname = raw_input("Your host: ")
! print """
Enter the server name:port where pybot will connect to. This is
just to start it out. You may add and/or remove servers later talking
with him."""
! server = raw_input("Server: ")
! print """
Enter the pybot nick you want to use in this server. That's important
because you'll be able to tell him to join a channel and/or connect
to a server by talking with him, so make sure you remember the nick."""
! pybotnick = raw_input("Pybot's nick: ")
! print """
Enter the username pybot will use in this server."""
! pybotusername = raw_input("Pybot's username: ")
! print """
Enter the real name pybot will use in this server."""
! pybotrealname = raw_input("Pybot's real name: ")
except EOFError:
! sys.exit("Interrupted!")
option["Permission.gosh"] = [pybot.User(nick, username, hostname)]
--- 48,92 ----
everything else.
"""
! raw_input("Press [ENTER] to continue...")
! print """
Enter the nick you're going to use while talking to pybot."""
! nick = raw_input("Your nick: ")
! print """Enter the username you're going to use while talking to pybot.
Please, note that you may have a '~' added to your username, depending on
your host's configuration. If you want to be sure what your username is,
issue a '/whois %s' while connected to your irc server. You may also
use a wildcard, like *username, if you're not sure at all."""%nick
! username = raw_input("Your username: ")
! print """
Enter the hostname you're going to use while talking to pybot.
If you're not sure, you should also look at the output of the command
'/whois %s' while connected to your irc server. A wildcard like
*.my.host also work here, but be careful!"""%nick
! hostname = raw_input("Your host: ")
! print """
Enter the server name:port where pybot will connect to. This is
just to start it out. You may add and/or remove servers later talking
with him."""
! server = raw_input("Server: ")
! print """
Enter the pybot nick you want to use in this server. That's important
because you'll be able to tell him to join a channel and/or connect
to a server by talking with him, so make sure you remember the nick."""
! pybotnick = raw_input("Pybot's nick: ")
! print """
Enter the username pybot will use in this server."""
! pybotusername = raw_input("Pybot's username: ")
! print """
Enter the real name pybot will use in this server."""
! pybotrealname = raw_input("Pybot's real name: ")
except EOFError:
! sys.exit("Interrupted!")
option["Permission.gosh"] = [pybot.User(nick, username, hostname)]
***************
*** 99,101 ****
print "Options saved!"
! # vim:ts=4:sw=4
--- 99,101 ----
print "Options saved!"
! # vim:ts=4:sw=4:et
--- pybot.py DELETED ---
|
|
From: Gustavo N. <nie...@us...> - 2001-12-04 00:57:41
|
Update of /cvsroot/pybot/pybot
In directory usw-pr-cvs1:/tmp/cvs-serv32496
Modified Files:
ChangeLog
Added Files:
pybot.py
Removed Files:
run
Log Message:
- Implemented new startup system.
- Converted tabs to spaces so people using other editors feel
confortable as well (suggested by John Thingstad).
--- NEW FILE: pybot.py ---
#!/usr/bin/python
#
# 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
import imp
import sys
import os
def main():
try:
module = imp.find_module("pybot/runner")
except ImportError:
sys.exit("error: couldn't find module pybot.runner")
module[0].close()
while 1:
ret = os.system("python "+module[1])
if ret != 0:
break
if __name__ == "__main__":
main()
# vim:sw=4:ts=4:et
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pybot/pybot/ChangeLog,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ChangeLog 2001/11/14 15:28:41 1.2
--- ChangeLog 2001/12/04 00:57:37 1.3
***************
*** 1,2 ****
--- 1,6 ----
+ 2001-12-03 Gustavo Niemeyer <nie...@co...>
+ * pybot.py, pybot/runner.py: New files with new startup system.
+ * run, scripts/pybot.py: Removed.
+
2001-11-14 Gustavo Niemeyer <nie...@co...>
* modules/messages.py: Added help.
--- run DELETED ---
|
|
From: Gustavo N. <nie...@us...> - 2001-11-22 13:43:21
|
Update of /cvsroot/pybot/pybot/pybot In directory usw-pr-cvs1:/tmp/cvs-serv22743 Modified Files: main.py Log Message: Temporarily removed SIGQUIT handling since Aaron told us it doesn't work on Windows. Index: main.py =================================================================== RCS file: /cvsroot/pybot/pybot/pybot/main.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** main.py 2001/11/02 17:20:21 1.1.1.1 --- main.py 2001/11/22 13:43:17 1.2 *************** *** 33,37 **** self.reboot = 0 self.quit = 0 ! signal.signal(signal.SIGQUIT, self.signalhandler) signal.signal(signal.SIGTERM, self.signalhandler) --- 33,40 ---- self.reboot = 0 self.quit = 0 ! # Aaron told SIGQUIT is not available in Windows. We must figure ! # out which platforms it is available and what's the most clean ! # way to use it. ! # signal.signal(signal.SIGQUIT, self.signalhandler) signal.signal(signal.SIGTERM, self.signalhandler) |
|
From: Gustavo N. <nie...@us...> - 2001-11-14 15:28:46
|
Update of /cvsroot/pybot/pybot
In directory usw-pr-cvs1:/tmp/cvs-serv24657
Modified Files:
ChangeLog
Log Message:
- Added help in messages module.
- Added handling of load levels, allowing one to control module
loading order at startup.
- Reduced load level of help module.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/pybot/pybot/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ChangeLog 2001/11/02 17:18:58 1.1.1.1
--- ChangeLog 2001/11/14 15:28:41 1.2
***************
*** 1,2 ****
--- 1,14 ----
+ 2001-11-14 Gustavo Niemeyer <nie...@co...>
+ * modules/messages.py: Added help.
+ * modules/help.py: Reduced load level.
+ * module.py, modules/modulecontrol.py: Added handling of load levels,
+ allowing one to control module loading order.
+
+ 2001-11-13 Gustavo Niemeyer <nie...@co...>
+ * option.py: Fixed little bug in Options.getsoft() keepalive handling.
+ * modules/{help,plock}.py: Implemented help module, offering an online
+ help api for other modules (have a look at plock.py for an example).
+ * social.py: Minor changes.
+
2001-11-01 Gustavo Niemeyer <nie...@co...>
* pybot was completely reestructured.
|
|
From: Gustavo N. <nie...@us...> - 2001-11-14 15:28:46
|
Update of /cvsroot/pybot/pybot/pybot/modules
In directory usw-pr-cvs1:/tmp/cvs-serv24657/pybot/modules
Modified Files:
help.py messages.py modulecontrol.py permission.py plock.py
social.py
Log Message:
- Added help in messages module.
- Added handling of load levels, allowing one to control module
loading order at startup.
- Reduced load level of help module.
Index: help.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/help.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** help.py 2001/11/13 20:39:25 1.1
--- help.py 2001/11/14 15:28:41 1.2
***************
*** 22,26 ****
HELP = [
("""\
! You may ask for help using "[show] help [about] <keyword>".\
""",)
]
--- 22,26 ----
HELP = [
("""\
! You may ask for help using "[show] help [about] <something>".\
""",)
]
***************
*** 28,32 ****
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)
--- 28,32 ----
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)
***************
*** 34,38 ****
# [show] help [about] <keyword>
! self.re1 = re.compile(r"(?:show\s+)?help(?:\s+about)?(?:\s+(?P<keyword>\S+))?\s*[.!]*$", re.I)
def unload(self):
--- 34,38 ----
# [show] help [about] <keyword>
! self.re1 = re.compile(r"(?:show\s+)?help(?:\s+about)?(?:\s+(?P<something>.+?))?\s*[.!]*$", re.I)
def unload(self):
***************
*** 46,58 ****
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:
--- 46,62 ----
if m:
if mm.hasperm(0, msg.server.servername, msg.target, msg.user, "help"):
! something = m.group("something")
! if something:
! found = 0
! for pattern, text in self.data:
! if pattern.match(something):
! found = 1
! for line in text:
! msg.answer("%:", *line)
else:
! found = 1
! for line in HELP:
msg.answer("%:", *line)
! if not found:
msg.answer("%:", ["No", "Sorry, no", "Sorry, but there's no"], "help about that", [".", "!"])
else:
***************
*** 60,73 ****
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):
--- 64,80 ----
return 0
! def mm_register_help(self, defret, pattern, text):
! self.data.append((re.compile(pattern, re.I), text))
! def mm_unregister_help(self, defret, text):
! for i in range(len(self.data)-1,-1,-1):
! if self.data[i][1] == text:
! del self.data[i]
!
!
! # Make sure it is loaded first to let mm.register_help()
! # available to everyone.
! __loadlevel__ = 90
!
def __loadmodule__(bot):
Index: messages.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/messages.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** messages.py 2001/11/02 17:20:26 1.1.1.1
--- messages.py 2001/11/14 15:28:41 1.2
***************
*** 17,25 ****
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! from pybot import hooks, options
import string
import time
import re
class Messages:
def __init__(self, bot):
--- 17,32 ----
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! from pybot import hooks, options, mm
import string
import time
import re
+ HELP = [
+ ("""\
+ You may leave a message to another user with "[priv[ate]] message (to|for) \
+ <nick>: <message>". I'll let <nick> know about your message when he join \
+ or speak something in one of the channels I'm in.\
+ """,)]
+
class Messages:
def __init__(self, bot):
***************
*** 31,34 ****
--- 38,44 ----
# Match '[priv[ate]] message (to|for) <nick>: <message>'
self.re1 = re.compile(r"(?P<private>priv(?:ate)?\s+)?message\s+(?:to|for)\s+(?P<nick>\S+?)\s*:\s+(?P<message>.*)$", re.I)
+
+ # Match '[leav(e|ing)] message[s]'
+ mm.register_help(0, "(?:leav(?:e|ing)\s+)?messages?", HELP)
def unload(self):
Index: modulecontrol.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/modulecontrol.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** modulecontrol.py 2001/11/02 17:20:23 1.1.1.1
--- modulecontrol.py 2001/11/14 15:28:41 1.2
***************
*** 23,28 ****
self.modules = options.gethard("ModuleControl.modules", [])
hooks.register("Message", self.message)
! for module in self.modules:
! modls.load(module)
def unload(self):
--- 23,27 ----
self.modules = options.gethard("ModuleControl.modules", [])
hooks.register("Message", self.message)
! modls.loadlist(self.modules)
def unload(self):
Index: permission.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/permission.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** permission.py 2001/11/02 17:20:26 1.1.1.1
--- permission.py 2001/11/14 15:28:41 1.2
***************
*** 37,41 ****
def message(self, msg):
var = []
! if msg.match(var, 6, "%", "give", 0, "~", ["permission", "perm"], "to", [("user", 1, "~"), None], [(["on", "at", None], [(2, "~this", "channel"), ("channel", 3, "^[#&+!][^,^G]+$")]), None], [(["on", "at", None], [(4, "~this", "server"), ("server", 5, "~")]), None], ["!", ".", None]):
if self.mm_hasperm(0, msg.server.servername, msg.target, msg.user, None):
if var[1] or var[2] or var[3] or var[4]:
--- 37,41 ----
def message(self, msg):
var = []
! if msg.match(var, 6, "%", "give", 0, "~", ["permission", "perm"], "to", [("user", 1, "~"), None], [(["on", "at", None], [(2, "~this", "channel"), ("channel", 3, "^[#&+!][^,^G]+$")]), None], [(["on", "at", "to", None], [(4, "~this", "server"), ("server", 5, "~")]), None], ["!", ".", None]):
if self.mm_hasperm(0, msg.server.servername, msg.target, msg.user, None):
if var[1] or var[2] or var[3] or var[4]:
Index: plock.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/plock.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** plock.py 2001/11/13 20:39:25 1.2
--- plock.py 2001/11/14 15:28:41 1.3
***************
*** 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):
--- 83,92 ----
self.re5 = re.compile(r"plock\s+(?P<package>[\w_-]+(?:(?:\s*,?\s*and\s+|[, ]+)[\w_-]+)*)\s*(?:!*\?[?!]*)$")
! # Match '[un]plock[ing] | <package|pkg> lock[ing]
! mm.register_help(0, "(?:un)?plock(?:ing)?|(?:package|pkg)\s+lock(?:ing)?", HELP)
def unload(self):
hooks.unregister("Message", self.message)
! mm.unregister_help(0, HELP)
def getnick(self, server, email):
Index: social.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/modules/social.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** social.py 2001/11/02 17:20:24 1.1.1.1
--- social.py 2001/11/14 15:28:41 1.2
***************
*** 33,38 ****
self.re2 = re.compile(r'(?P<nick>\w+)\s*!+$', re.I)
! # Match '[thank[']s|thank you] [!|.]'
! self.re3 = re.compile(r'thank(?:\'?s)?\s+you(?:\s+(?P<nick>\w+))\s*[!.]*', re.I)
# Match 'are you ok?|how are you [doing]?'
--- 33,38 ----
self.re2 = re.compile(r'(?P<nick>\w+)\s*!+$', re.I)
! # Match '[thank[']s|thank you|thx|tnk[']s] [!|.]'
! self.re3 = re.compile(r'(?:thank|thx|tnk)(?:\'?s|\s+you)(?:\s+(?P<nick>\w+))\s*[!.]*', re.I)
# Match 'are you ok?|how are you [doing]?'
***************
*** 51,54 ****
--- 51,57 ----
self.re8 = re.compile(r'.*(?:gay|stupid|fuck|idiot|imbecile|cretin)', re.I)
+ # Match 'h[e|u|a]h'
+ self.re9 = re.compile(r'h[eua]h', re.I)
+
def unload(self):
hooks.unregister("Message", self.message)
***************
*** 96,99 ****
--- 99,106 ----
if self.re8.match(msg.line):
msg.answer("%:", ["Be polite while talking to me!", "I should talk to your mother!", "Hey! What's this?", "I'll pretend to be blind."])
+ return 0
+
+ if self.re9.match(msg.line):
+ msg.answer("%:", ["Heh", "Huh"], ["?", "!?", "!?!?", ".."])
return 0
|
|
From: Gustavo N. <nie...@us...> - 2001-11-14 15:28:46
|
Update of /cvsroot/pybot/pybot/pybot
In directory usw-pr-cvs1:/tmp/cvs-serv24657/pybot
Modified Files:
module.py
Log Message:
- Added help in messages module.
- Added handling of load levels, allowing one to control module
loading order at startup.
- Reduced load level of help module.
Index: module.py
===================================================================
RCS file: /cvsroot/pybot/pybot/pybot/module.py,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** module.py 2001/11/02 17:20:19 1.1.1.1
--- module.py 2001/11/14 15:28:41 1.2
***************
*** 27,30 ****
--- 27,66 ----
return self.__modules.has_key(name)
+ def loadlist(self, names):
+ """Load list of given modules considering level attribute."""
+ modulelist = []
+ for name in names:
+ try:
+ module = __import__("pybot.modules."+name)
+ module = getattr(module, "modules")
+ module = getattr(module, name)
+ reload(module)
+ func = getattr(module, "__loadmodule__")
+ try:
+ level = getattr(module, "__loadlevel__")
+ except AttributeError:
+ level = 100
+ l = len(modulelist)
+ i = 0
+ while i < l:
+ if modulelist[i][-1] > level:
+ modulelist.insert(i, (name, module, func, level))
+ break
+ i = i + 1
+ else:
+ modulelist.append((name, module, func, level))
+ except (AttributeError, ImportError):
+ traceback.print_exc()
+ ret = []
+ for name, module, func, level in modulelist:
+ try:
+ func(self)
+ except:
+ traceback.print_exc()
+ else:
+ self.__modules[name] = module
+ ret.append(name)
+ return ret
+
def load(self, name):
try:
|
|
From: Gustavo N. <nie...@us...> - 2001-11-13 20:39:28
|
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)
|
|
From: Gustavo N. <nie...@us...> - 2001-11-13 20:39:28
|
Update of /cvsroot/pybot/pybot/pybot In directory usw-pr-cvs1:/tmp/cvs-serv20766 Modified Files: option.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). Index: option.py =================================================================== RCS file: /cvsroot/pybot/pybot/pybot/option.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** option.py 2001/11/02 17:20:21 1.1.1.1 --- option.py 2001/11/13 20:39:25 1.2 *************** *** 46,54 **** def getsoft(self, name, default, keepalive=None): opt = self.__soft.get(name) if opt: ! if time() < opt[0]: ! if keepalive == 0: ! opt[0] = 0 elif keepalive: opt[0] = time()+keepalive --- 46,59 ---- def getsoft(self, name, default, keepalive=None): + """Return temporary option. + You may define for how long the option will be considered + valid trough the keepalive argument (in seconds). If keepalive + is None (default), option will stay valid while pybot is up, or + at least until you change the keepalive to something else.""" opt = self.__soft.get(name) if opt: ! if opt[0] is None or time() < opt[0]: ! if keepalive is None: ! opt[0] = None elif keepalive: opt[0] = time()+keepalive *************** *** 56,62 **** else: del self.__soft[name] ! if keepalive == 0: ! self.__soft[name] = 0 ! elif keepalive: self.__soft[name] = [time()+keepalive, default] return default --- 61,67 ---- else: del self.__soft[name] ! if keepalive is None: ! self.__soft[name] = [None, default] ! else: self.__soft[name] = [time()+keepalive, default] return default |