standardize config sections to use class name. NOTE: USERS NEED TO UPDATE THEIR CONFIG
This commit is contained in:
parent
f739cb6114
commit
4d41314195
|
@ -93,7 +93,7 @@ class Module(object):
|
|||
admin_unlocked = False
|
||||
|
||||
try:
|
||||
if userhost == self.config.get('admin', 'userhost'):
|
||||
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
||||
admin_unlocked = True
|
||||
except NoOptionError: pass
|
||||
|
||||
|
@ -131,7 +131,7 @@ class Module(object):
|
|||
admin_unlocked = False
|
||||
|
||||
try:
|
||||
if userhost == self.config.get('admin', 'userhost'):
|
||||
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
||||
admin_unlocked = True
|
||||
except NoOptionError: pass
|
||||
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
[IRC]
|
||||
[dr.botzo]
|
||||
server = irc.foonetic.net
|
||||
port = 6667
|
||||
nick = dr_devzo
|
||||
name = dr. devzo
|
||||
usermode = -x
|
||||
debug = true
|
||||
admin_userhost = bss@ayu.incorporeal.org
|
||||
module_list = IrcAdmin
|
||||
|
||||
[admin]
|
||||
userhost = bss@ayu.incorporeal.org
|
||||
|
||||
[channels]
|
||||
[IrcAdmin]
|
||||
autojoin = #bss
|
||||
|
||||
[modules]
|
||||
modlist = IrcAdmin
|
||||
|
|
12
dr.botzo.py
12
dr.botzo.py
|
@ -72,17 +72,17 @@ config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg'])
|
|||
# load necessary options
|
||||
try:
|
||||
# load connection info
|
||||
botserver = config.get('IRC', 'server')
|
||||
botport = config.getint('IRC', 'port')
|
||||
botnick = config.get('IRC', 'nick')
|
||||
botircname = config.get('IRC', 'name')
|
||||
botserver = config.get('dr.botzo', 'server')
|
||||
botport = config.getint('dr.botzo', 'port')
|
||||
botnick = config.get('dr.botzo', 'nick')
|
||||
botircname = config.get('dr.botzo', 'name')
|
||||
except NoSectionError as e:
|
||||
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))
|
||||
|
||||
# load additional options
|
||||
irclib.DEBUG = config.getboolean('IRC', 'debug')
|
||||
irclib.DEBUG = config.getboolean('dr.botzo', 'debug')
|
||||
|
||||
# start up the IRC bot
|
||||
|
||||
|
@ -92,7 +92,7 @@ server = irc.server().connect(botserver, botport, botnick, botircname)
|
|||
|
||||
# load features
|
||||
try:
|
||||
cfgmodlist = config.get('modules', 'modlist')
|
||||
cfgmodlist = config.get('dr.botzo', 'module_list')
|
||||
|
||||
mods = cfgmodlist.split(',')
|
||||
for mod in mods:
|
||||
|
|
|
@ -34,29 +34,30 @@ class Countdown(Module):
|
|||
if whats[1] == 'add' and len(whats) >= 4:
|
||||
item = whats[2]
|
||||
target = parse(' '.join(whats[3:]), default=datetime.now().replace(tzinfo=tzlocal()))
|
||||
if not self.config.has_section('countdown'):
|
||||
self.config.add_section('countdown')
|
||||
if not self.config.has_section(self.__class__.__name__):
|
||||
self.config.add_section(self.__class__.__name__)
|
||||
|
||||
self.config.set('countdown', item, target.astimezone(tzutc()).isoformat())
|
||||
self.config.set(self.__class__.__name__, item, target.astimezone(tzutc()).isoformat())
|
||||
replystr = 'added countdown item ' + whats[2]
|
||||
return self.reply(connection, replypath, replystr)
|
||||
elif whats[1] == 'remove':
|
||||
try:
|
||||
if self.config.remove_option('countdown', whats[2]):
|
||||
if self.config.remove_option(self.__class__.__name__, whats[2]):
|
||||
replystr = 'removed countdown item ' + whats[2]
|
||||
return self.reply(connection, replypath, replystr)
|
||||
except NoSectionError: pass
|
||||
elif whats[1] == 'list':
|
||||
try:
|
||||
cdlist = self.config.options('countdown')
|
||||
cdlist = self.config.options(self.__class__.__name__)
|
||||
cdlist.remove('debug')
|
||||
cdlist.remove('pubmsg_needs_bot_prefix')
|
||||
cdlist.sort()
|
||||
liststr = ', '.join(cdlist)
|
||||
return self.reply(connection, replypath, liststr)
|
||||
except NoSectionError: pass
|
||||
else:
|
||||
try:
|
||||
timestr = self.config.get('countdown', whats[1])
|
||||
timestr = self.config.get(self.__class__.__name__, whats[1])
|
||||
time = parse(timestr)
|
||||
rdelta = relativedelta(time, datetime.now().replace(tzinfo=tzlocal()))
|
||||
relstr = whats[1] + ' will occur in '
|
||||
|
|
|
@ -30,7 +30,7 @@ class FactFile(Module):
|
|||
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
whats = what.split(' ')
|
||||
try:
|
||||
filename = self.config.get('fact', whats[0])
|
||||
filename = self.config.get(self.__class__.__name__, whats[0])
|
||||
|
||||
# open file
|
||||
if os.path.isfile(filename):
|
||||
|
|
|
@ -45,14 +45,14 @@ class IrcAdmin(Module):
|
|||
|
||||
# user modes
|
||||
try:
|
||||
nick = self.config.get('IRC', 'nick')
|
||||
usermode = self.config.get('IRC', 'usermode')
|
||||
nick = self.config.get('dr.botzo', 'nick')
|
||||
usermode = self.config.get('dr.botzo', 'usermode')
|
||||
connection.mode(nick, usermode)
|
||||
except NoOptionError: pass
|
||||
|
||||
# join the specified channels
|
||||
try:
|
||||
autojoins = self.config.get('channels', 'autojoin').split(',')
|
||||
autojoins = self.config.get(self.__class__.__name__, 'autojoin').split(',')
|
||||
for channel in autojoins:
|
||||
if irclib.is_channel(channel):
|
||||
connection.join(channel)
|
||||
|
@ -104,9 +104,9 @@ class IrcAdmin(Module):
|
|||
# get existing list
|
||||
channel = whats[2]
|
||||
if irclib.is_channel(channel):
|
||||
channelset = set(self.config.get('channels', 'autojoin').split(','))
|
||||
channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(','))
|
||||
channelset.add(channel)
|
||||
self.config.set('channels', 'autojoin', ','.join(channelset))
|
||||
self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset))
|
||||
replystr = 'added ' + channel + ' to autojoin'
|
||||
return self.reply(connection, replypath, replystr)
|
||||
except NoOptionError: pass
|
||||
|
@ -115,9 +115,9 @@ class IrcAdmin(Module):
|
|||
# get existing list
|
||||
channel = whats[2]
|
||||
if irclib.is_channel(channel):
|
||||
channelset = set(self.config.get('channels', 'autojoin').split(','))
|
||||
channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(','))
|
||||
channelset.discard(channel)
|
||||
self.config.set('channels', 'autojoin', ','.join(channelset))
|
||||
self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset))
|
||||
replystr = 'removed ' + channel + ' from autojoin'
|
||||
return self.reply(connection, replypath, replystr)
|
||||
except NoOptionError: pass
|
||||
|
@ -135,7 +135,7 @@ class IrcAdmin(Module):
|
|||
if whats[0] == 'nick' and admin_unlocked and len(whats) >= 2:
|
||||
newnick = whats[1]
|
||||
connection.nick(newnick)
|
||||
self.config.set('IRC', 'nick', newnick)
|
||||
self.config.set('dr.botzo', 'nick', newnick)
|
||||
replystr = 'changed nickname'
|
||||
return self.reply(connection, replypath, replystr)
|
||||
|
||||
|
|
|
@ -40,13 +40,13 @@ class Seen(Module):
|
|||
admin_unlocked = False
|
||||
|
||||
# whatever it is, store it
|
||||
if not self.config.has_section('seen'):
|
||||
self.config.add_section('seen')
|
||||
if not self.config.has_section(self.__class__.__name__):
|
||||
self.config.add_section(self.__class__.__name__)
|
||||
|
||||
self.config.set('seen', nick, userhost + '|:|' + datetime.utcnow().isoformat() + '|:|' + what)
|
||||
self.config.set(self.__class__.__name__, nick, userhost + '|:|' + datetime.utcnow().isoformat() + '|:|' + what)
|
||||
|
||||
try:
|
||||
if userhost == self.config.get('admin', 'userhost'):
|
||||
if userhost == self.config.get('dr.botzo', 'admin_userhost'):
|
||||
admin_unlocked = True
|
||||
except NoOptionError: pass
|
||||
|
||||
|
@ -73,7 +73,7 @@ class Seen(Module):
|
|||
query = whats[1]
|
||||
if query != 'debug':
|
||||
try:
|
||||
seendata = self.config.get('seen', query).split('|:|')
|
||||
seendata = self.config.get(self.__class__.__name__, query).split('|:|')
|
||||
converted = datetime.strptime(seendata[1], "%Y-%m-%dT%H:%M:%S.%f").replace(tzinfo=tzutc())
|
||||
replystr = 'last saw ' + query + ' at ' + converted.astimezone(tzlocal()).strftime("%Y/%m/%d %H:%M:%S %Z") + ' saying \'' + seendata[2] + '\''
|
||||
return self.reply(connection, replypath, replystr)
|
||||
|
|
|
@ -34,7 +34,7 @@ class Urls(Module):
|
|||
whats = what.split(' ')
|
||||
if whats[0] == "url":
|
||||
try:
|
||||
filename = self.config.get('urls', 'urlfile')
|
||||
filename = self.config.get(self.__class__.__name__, 'urlfile')
|
||||
|
||||
# check file
|
||||
if os.path.isfile(filename):
|
||||
|
|
Loading…
Reference in New Issue