making comments more standard
This commit is contained in:
parent
a1c8686af5
commit
74371727ed
105
dr.botzo.py
105
dr.botzo.py
@ -29,42 +29,38 @@ from dateutil.tz import *
|
||||
import irclib
|
||||
|
||||
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):
|
||||
"""Constructor for a feature module. Inheritors should not do anything special
|
||||
here, instead they should implement register_handlers and do, or else this will
|
||||
be a very uneventful affair.
|
||||
|
||||
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
|
||||
modules to call do and see if anything can handle text they may have seen (such
|
||||
as in recursive commands).
|
||||
"""
|
||||
# Constructor for a feature module. Inheritors should not do anything special
|
||||
# here, instead they should implement register_handlers and do, or else this will
|
||||
# be a very uneventful affair.
|
||||
#
|
||||
# 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
|
||||
# modules to call do and see if anything can handle text they may have seen (such
|
||||
# as in recursive commands).
|
||||
|
||||
self.config = config
|
||||
self.modlist = modlist
|
||||
self.register_handlers(server)
|
||||
|
||||
def register_handlers(self, server):
|
||||
"""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,
|
||||
e.g.:
|
||||
|
||||
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
|
||||
own.
|
||||
"""
|
||||
# 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,
|
||||
# e.g.:
|
||||
#
|
||||
# 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
|
||||
# own.
|
||||
|
||||
print "looks like someone forgot to implement register_handlers!"
|
||||
|
||||
def on_pubmsg(self, connection, event):
|
||||
"""Does some variable setup and initial sanity checking before calling Module.do,
|
||||
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.
|
||||
"""
|
||||
# Does some variable setup and initial sanity checking before calling Module.do,
|
||||
# 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.
|
||||
|
||||
nick = irclib.nm_to_n(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)
|
||||
|
||||
def on_privmsg(self, connection, event):
|
||||
"""Does some variable setup and initial sanity checking before calling Module.do,
|
||||
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.
|
||||
"""
|
||||
# Does some variable setup and initial sanity checking before calling Module.do,
|
||||
# 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.
|
||||
|
||||
nick = irclib.nm_to_n(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)
|
||||
|
||||
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
|
||||
that we should do what is basically a text replacement on. The intent is to
|
||||
allow things like the following:
|
||||
|
||||
command arg1 [anothercommand arg1 arg2]
|
||||
|
||||
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
|
||||
be attempted after you've determined the line should be handled by your module.
|
||||
"""
|
||||
# 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
|
||||
# allow things like the following:
|
||||
#
|
||||
# command arg1 [anothercommand arg1 arg2]
|
||||
#
|
||||
# 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
|
||||
# be attempted after you've determined the line should be handled by your module.
|
||||
|
||||
start_idx = what.find('[')
|
||||
subcmd = what[start_idx+1:]
|
||||
@ -157,17 +151,15 @@ class Module(object):
|
||||
return attempt
|
||||
|
||||
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
"""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
|
||||
"""
|
||||
# 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
|
||||
|
||||
print "looks like someone forgot to implement do!"
|
||||
|
||||
class GoogleTranslate(Module):
|
||||
"""Class that translates text via Google Translate.
|
||||
|
||||
http://code.google.com/apis/ajaxlanguage/documentation/
|
||||
"""
|
||||
# Class that translates text via Google Translate.
|
||||
#
|
||||
# http://code.google.com/apis/ajaxlanguage/documentation/
|
||||
|
||||
def __init__(self, config, server, modlist):
|
||||
super(GoogleTranslate, self).__init__(config, server, modlist)
|
||||
@ -209,8 +201,7 @@ class GoogleTranslate(Module):
|
||||
connection.privmsg(replypath, translation)
|
||||
|
||||
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):
|
||||
super(Countdown, self).__init__(config, server, modlist)
|
||||
@ -281,8 +272,7 @@ class Countdown(Module):
|
||||
except NoOptionError: pass
|
||||
|
||||
class Dice(Module):
|
||||
"""Rolls dice, for RPGs mostly
|
||||
"""
|
||||
# Rolls dice, for RPGs mostly
|
||||
|
||||
def __init__(self, config, server, modlist):
|
||||
super(Dice, self).__init__(config, server, modlist)
|
||||
@ -362,9 +352,8 @@ class Dice(Module):
|
||||
connection.privmsg(replypath, result)
|
||||
|
||||
class Seen(Module):
|
||||
"""Keeps track of when people say things in public channels, and reports on when
|
||||
they last said something.
|
||||
"""
|
||||
# Keeps track of when people say things in public channels, and reports on when
|
||||
# they last said something.
|
||||
|
||||
def __init__(self, config, server, modlist):
|
||||
super(Seen, self).__init__(config, server, modlist)
|
||||
@ -397,8 +386,7 @@ class Seen(Module):
|
||||
except NoOptionError: pass
|
||||
|
||||
class IrcAdmin(Module):
|
||||
"""all kinds of miscellaneous irc stuff
|
||||
"""
|
||||
# All kinds of miscellaneous irc stuff
|
||||
|
||||
def __init__(self, config, server, modlist):
|
||||
super(IrcAdmin, self).__init__(config, server, modlist)
|
||||
@ -527,8 +515,7 @@ class IrcAdmin(Module):
|
||||
connection.privmsg(replypath, replystr)
|
||||
|
||||
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):
|
||||
super(FactFile, self).__init__(config, server, modlist)
|
||||
@ -562,7 +549,7 @@ class FactFile(Module):
|
||||
|
||||
class DrBotServerConnection(irclib.ServerConnection):
|
||||
def privmsg(self, target, text):
|
||||
"""Send a PRIVMSG command."""
|
||||
# Send a PRIVMSG command.
|
||||
# TODO: length limiting or splitting
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
|
||||
@ -572,10 +559,6 @@ class DrBotIRC(irclib.IRC):
|
||||
self.connections.append(c)
|
||||
return c
|
||||
|
||||
#####
|
||||
# init
|
||||
#####
|
||||
|
||||
# read config file
|
||||
|
||||
config = ConfigParser({'debug': 'false'})
|
||||
|
Loading…
Reference in New Issue
Block a user