2010-07-26 21:51:03 -05:00
|
|
|
# dr.botzo - a pluggable IRC bot written in Python
|
|
|
|
# Copyright (C) 2010 Brian S. Stephan
|
|
|
|
#
|
|
|
|
# This program 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 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-07-24 10:39:58 -05:00
|
|
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
2010-07-24 09:54:38 -05:00
|
|
|
import os
|
2010-07-25 08:52:48 -05:00
|
|
|
import re
|
2010-07-24 10:12:00 -05:00
|
|
|
import sys
|
2010-07-27 20:26:21 -05:00
|
|
|
import inspect
|
2010-07-24 09:54:38 -05:00
|
|
|
|
2010-07-26 22:36:07 -05:00
|
|
|
from irclib import irclib
|
2010-07-27 20:26:21 -05:00
|
|
|
from modules import *
|
2010-07-24 10:47:33 -05:00
|
|
|
|
2010-07-27 20:26:21 -05:00
|
|
|
modlist = []
|
2010-07-28 00:11:58 -05:00
|
|
|
moduleList = [ "Countdown", "Dice", "IrcAdmin", "GoogleTranslate", "Seen", "FactFile" ]
|
2010-07-27 20:26:21 -05:00
|
|
|
modObjs = []
|
2010-07-26 18:14:33 -05:00
|
|
|
|
2010-07-26 20:05:17 -05:00
|
|
|
class DrBotServerConnection(irclib.ServerConnection):
|
|
|
|
def privmsg(self, target, text):
|
2010-07-26 21:59:11 -05:00
|
|
|
# Send a PRIVMSG command.
|
2010-07-26 20:05:17 -05:00
|
|
|
# TODO: length limiting or splitting
|
|
|
|
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
|
|
|
|
|
|
|
class DrBotIRC(irclib.IRC):
|
|
|
|
def server(self):
|
|
|
|
c = DrBotServerConnection(self)
|
|
|
|
self.connections.append(c)
|
|
|
|
return c
|
|
|
|
|
2010-07-24 10:47:33 -05:00
|
|
|
# read config file
|
|
|
|
|
2010-07-24 11:34:19 -05:00
|
|
|
config = ConfigParser({'debug': 'false'})
|
2010-07-24 09:54:38 -05:00
|
|
|
config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg'])
|
|
|
|
|
2010-07-24 11:34:19 -05:00
|
|
|
# load necessary options
|
2010-07-24 10:12:00 -05:00
|
|
|
try:
|
|
|
|
# load connection info
|
2010-07-25 08:24:04 -05:00
|
|
|
botserver = config.get('IRC', 'server')
|
|
|
|
botport = config.getint('IRC', 'port')
|
|
|
|
botnick = config.get('IRC', 'nick')
|
|
|
|
botircname = config.get('IRC', 'name')
|
2010-07-24 10:12:00 -05:00
|
|
|
except NoSectionError as e:
|
2010-07-24 10:14:47 -05:00
|
|
|
sys.exit("Aborted due to error with necessary configuration: " + str(e))
|
|
|
|
except NoOptionError as e:
|
|
|
|
sys.exit("Aborted due to error with necessary configuration: " + str(e))
|
2010-07-24 09:54:38 -05:00
|
|
|
|
2010-07-24 11:34:19 -05:00
|
|
|
# load additional options
|
|
|
|
irclib.DEBUG = config.getboolean('IRC', 'debug')
|
|
|
|
|
2010-07-24 10:47:33 -05:00
|
|
|
# start up the IRC bot
|
|
|
|
|
|
|
|
# create IRC and server objects and connect
|
2010-07-26 20:05:17 -05:00
|
|
|
irc = DrBotIRC()
|
2010-07-25 08:24:04 -05:00
|
|
|
server = irc.server().connect(botserver, botport, botnick, botircname)
|
2010-07-24 10:47:33 -05:00
|
|
|
|
2010-07-29 22:36:08 -05:00
|
|
|
count = Countdown.Countdown(config, server, modlist)
|
|
|
|
dice = Dice.Dice(config, server, modlist)
|
|
|
|
fact = FactFile.FactFile(config, server, modlist)
|
|
|
|
admin = IrcAdmin.IrcAdmin(config, server, modlist)
|
|
|
|
gt = GoogleTranslate.GoogleTranslate(config, server, modlist)
|
|
|
|
seen = Seen.Seen(config, server, modlist)
|
2010-07-25 20:09:02 -05:00
|
|
|
|
2010-07-24 10:47:33 -05:00
|
|
|
# loop forever
|
|
|
|
irc.process_forever()
|
|
|
|
|
2010-07-24 09:54:38 -05:00
|
|
|
# vi:tabstop=4:expandtab:autoindent
|
2010-07-28 00:11:58 -05:00
|
|
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|