making comments more standard

This commit is contained in:
Brian S. Stephan 2010-07-26 21:59:11 -05:00 committed by kad
parent a1c8686af5
commit 74371727ed

View File

@ -29,42 +29,38 @@ from dateutil.tz import *
import irclib import irclib
class Module(object): class Module(object):
"""Base class used for creating classes that have real functionality. # Base class used for creating classes that have real functionality.
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
"""Constructor for a feature module. Inheritors should not do anything special # Constructor for a feature module. Inheritors should not do anything special
here, instead they should implement register_handlers and do, or else this will # here, instead they should implement register_handlers and do, or else this will
be a very uneventful affair. # be a very uneventful affair.
#
Classes that are interested in allowing an indirect call to their do routine # Classes that are interested in allowing an indirect call to their do routine
should add themselves to modlist inside their __init__. This will allow other # should add themselves to modlist inside their __init__. This will allow other
modules to call do and see if anything can handle text they may have seen (such # modules to call do and see if anything can handle text they may have seen (such
as in recursive commands). # as in recursive commands).
"""
self.config = config self.config = config
self.modlist = modlist self.modlist = modlist
self.register_handlers(server) self.register_handlers(server)
def register_handlers(self, server): def register_handlers(self, server):
"""This is called by __init__ and sets up server.add_global_handlers. Classes # This is called by __init__ and sets up server.add_global_handlers. Classes
inheriting from Module should implement this and set up the appropriate handlers, # inheriting from Module should implement this and set up the appropriate handlers,
e.g.: # e.g.:
#
server.add_global_handler('privmsg', self.on_privmsg) # server.add_global_handler('privmsg', self.on_privmsg)
#
Module.on_pubmsg and Module.on_privmsg are defined so far, the rest, you're on your # Module.on_pubmsg and Module.on_privmsg are defined so far, the rest, you're on your
own. # own.
"""
print "looks like someone forgot to implement register_handlers!" print "looks like someone forgot to implement register_handlers!"
def on_pubmsg(self, connection, event): def on_pubmsg(self, connection, event):
"""Does some variable setup and initial sanity checking before calling Module.do, # Does some variable setup and initial sanity checking before calling Module.do,
which should be implemented by subclasses and what can be ultimately responsible # which should be implemented by subclasses and what can be ultimately responsible
for the work. Of course, you are free to reimplement on_pubmsg on your own too. # for the work. Of course, you are free to reimplement on_pubmsg on your own too.
"""
nick = irclib.nm_to_n(event.source()) nick = irclib.nm_to_n(event.source())
userhost = irclib.nm_to_uh(event.source()) userhost = irclib.nm_to_uh(event.source())
@ -90,10 +86,9 @@ class Module(object):
self.do(connection, event, nick, userhost, replypath, what, admin_unlocked) self.do(connection, event, nick, userhost, replypath, what, admin_unlocked)
def on_privmsg(self, connection, event): def on_privmsg(self, connection, event):
"""Does some variable setup and initial sanity checking before calling Module.do, # Does some variable setup and initial sanity checking before calling Module.do,
which should be implemented by subclasses and what can be ultimately responsible # which should be implemented by subclasses and what can be ultimately responsible
for the work. Of course, you are free to reimplement on_privmsg on your own too. # for the work. Of course, you are free to reimplement on_privmsg on your own too.
"""
nick = irclib.nm_to_n(event.source()) nick = irclib.nm_to_n(event.source())
userhost = irclib.nm_to_uh(event.source()) userhost = irclib.nm_to_uh(event.source())
@ -113,16 +108,15 @@ class Module(object):
self.do(connection, event, nick, userhost, replypath, what, admin_unlocked) self.do(connection, event, nick, userhost, replypath, what, admin_unlocked)
def try_recursion(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def try_recursion(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""Upon seeing a line intended for this module, see if there are subcommands # Upon seeing a line intended for this module, see if there are subcommands
that we should do what is basically a text replacement on. The intent is to # that we should do what is basically a text replacement on. The intent is to
allow things like the following: # allow things like the following:
#
command arg1 [anothercommand arg1 arg2] # command arg1 [anothercommand arg1 arg2]
#
where the output of anothercommand is command's arg2..n. It's mostly for # where the output of anothercommand is command's arg2..n. It's mostly for
amusement purposes, but maybe there are legitimate uses. This is intended to # amusement purposes, but maybe there are legitimate uses. This is intended to
be attempted after you've determined the line should be handled by your module. # be attempted after you've determined the line should be handled by your module.
"""
start_idx = what.find('[') start_idx = what.find('[')
subcmd = what[start_idx+1:] subcmd = what[start_idx+1:]
@ -157,17 +151,15 @@ class Module(object):
return attempt return attempt
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""Implement this method in your subclass to have a fairly-automatic hook into # Implement this method in your subclass to have a fairly-automatic hook into
IRC functionality. This is called by the default on_pubmsg and on_privmsg # IRC functionality. This is called by the default on_pubmsg and on_privmsg
"""
print "looks like someone forgot to implement do!" print "looks like someone forgot to implement do!"
class GoogleTranslate(Module): class GoogleTranslate(Module):
"""Class that translates text via Google Translate. # Class that translates text via Google Translate.
#
http://code.google.com/apis/ajaxlanguage/documentation/ # http://code.google.com/apis/ajaxlanguage/documentation/
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(GoogleTranslate, self).__init__(config, server, modlist) super(GoogleTranslate, self).__init__(config, server, modlist)
@ -209,8 +201,7 @@ class GoogleTranslate(Module):
connection.privmsg(replypath, translation) connection.privmsg(replypath, translation)
class Countdown(Module): class Countdown(Module):
"""Class that adds a countdown item to the bot # Class that adds a countdown item to the bot
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(Countdown, self).__init__(config, server, modlist) super(Countdown, self).__init__(config, server, modlist)
@ -281,8 +272,7 @@ class Countdown(Module):
except NoOptionError: pass except NoOptionError: pass
class Dice(Module): class Dice(Module):
"""Rolls dice, for RPGs mostly # Rolls dice, for RPGs mostly
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(Dice, self).__init__(config, server, modlist) super(Dice, self).__init__(config, server, modlist)
@ -362,9 +352,8 @@ class Dice(Module):
connection.privmsg(replypath, result) connection.privmsg(replypath, result)
class Seen(Module): class Seen(Module):
"""Keeps track of when people say things in public channels, and reports on when # Keeps track of when people say things in public channels, and reports on when
they last said something. # they last said something.
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(Seen, self).__init__(config, server, modlist) super(Seen, self).__init__(config, server, modlist)
@ -397,8 +386,7 @@ class Seen(Module):
except NoOptionError: pass except NoOptionError: pass
class IrcAdmin(Module): class IrcAdmin(Module):
"""all kinds of miscellaneous irc stuff # All kinds of miscellaneous irc stuff
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(IrcAdmin, self).__init__(config, server, modlist) super(IrcAdmin, self).__init__(config, server, modlist)
@ -527,8 +515,7 @@ class IrcAdmin(Module):
connection.privmsg(replypath, replystr) connection.privmsg(replypath, replystr)
class FactFile(Module): class FactFile(Module):
"""Returns a random fact/quote/whatever from one or more files # Returns a random fact/quote/whatever from one or more files
"""
def __init__(self, config, server, modlist): def __init__(self, config, server, modlist):
super(FactFile, self).__init__(config, server, modlist) super(FactFile, self).__init__(config, server, modlist)
@ -562,7 +549,7 @@ class FactFile(Module):
class DrBotServerConnection(irclib.ServerConnection): class DrBotServerConnection(irclib.ServerConnection):
def privmsg(self, target, text): def privmsg(self, target, text):
"""Send a PRIVMSG command.""" # Send a PRIVMSG command.
# TODO: length limiting or splitting # TODO: length limiting or splitting
self.send_raw("PRIVMSG %s :%s" % (target, text)) self.send_raw("PRIVMSG %s :%s" % (target, text))
@ -572,10 +559,6 @@ class DrBotIRC(irclib.IRC):
self.connections.append(c) self.connections.append(c)
return c return c
#####
# init
#####
# read config file # read config file
config = ConfigParser({'debug': 'false'}) config = ConfigParser({'debug': 'false'})