less what.split(), more counting of what.split() results

This commit is contained in:
Brian S. Stephan 2010-07-25 10:43:27 -05:00
parent 748b59a272
commit 939f522f4b
1 changed files with 24 additions and 17 deletions

View File

@ -14,8 +14,9 @@ import irclib
#####
def sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'join' and admin_unlocked:
channel = what.split(' ')[1]
whats = what.split(' ')
if whats[0] == 'join' and admin_unlocked and len(whats) >= 2:
channel = whats[1]
if irclib.is_channel(channel):
connection.join(channel)
connection.privmsg(replypath, 'joined ' + channel + '.')
@ -26,10 +27,11 @@ def sub_join_channel(connection, event, nick, userhost, replypath, what, admin_u
#####
def sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'part' and admin_unlocked:
channel = what.split(' ')[1]
whats = what.split(' ')
if whats[0] == 'part' and admin_unlocked and len(whats) >= 2:
channel = whats[1]
if irclib.is_channel(channel):
connection.part(channel, ' '.join(what.split(' ')[2:]))
connection.part(channel, ' '.join(whats[2:]))
connection.privmsg(replypath, 'parted ' + channel + '.')
#####
@ -38,9 +40,10 @@ def sub_part_channel(connection, event, nick, userhost, replypath, what, admin_u
#####
def sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'quit' and admin_unlocked:
whats = what.split(' ')
if whats[0] == 'quit' and admin_unlocked:
connection.privmsg(replypath, 'quitting')
connection.quit(' '.join(what.split(' ')[1:]))
connection.quit(' '.join(whats[1:]))
with open('dr.botzo.cfg', 'w') as cfg:
config.write(cfg)
@ -50,21 +53,22 @@ def sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_u
#####
def sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'autojoin' and admin_unlocked:
if what.split(' ')[1] == 'add':
whats = what.split(' ')
if whats[0] == 'autojoin' and admin_unlocked and len(whats) >= 3:
if whats[1] == 'add':
try:
# get existing list
channel = what.split(' ')[2]
channel = whats[2]
if irclib.is_channel(channel):
channelset = set(config.get('channels', 'autojoin').split(','))
channelset.add(channel)
config.set('channels', 'autojoin', ','.join(channelset))
connection.privmsg(replypath, 'added ' + channel + ' to autojoin')
except NoOptionError: pass
elif what.split(' ')[1] == 'remove':
elif whats[1] == 'remove':
try:
# get existing list
channel = what.split(' ')[2]
channel = whats[2]
if irclib.is_channel(channel):
channelset = set(config.get('channels', 'autojoin').split(','))
channelset.discard(channel)
@ -89,8 +93,9 @@ def sub_add_to_seen(connection, event, nick, userhost, what):
#####
def sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'seen':
query = what.split(' ')[1]
whats = what.split(' ')
if whats[0] == 'seen' and len(whats) >= 2:
query = whats[1]
try:
seendata = config.get('seen', query).split('|:|')
converted = datetime.strptime(seendata[1], "%Y-%m-%dT%H:%M:%S.%f")
@ -103,7 +108,8 @@ def sub_report_seen(connection, event, nick, userhost, replypath, what, admin_un
#####
def sub_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'save' and admin_unlocked:
whats = what.split(' ')
if whats[0] == 'save' and admin_unlocked:
with open('dr.botzo.cfg', 'w') as cfg:
config.write(cfg)
connection.privmsg(replypath, 'saved config file')
@ -114,8 +120,9 @@ def sub_save_config(connection, event, nick, userhost, replypath, what, admin_un
#####
def sub_change_nick(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'nick' and admin_unlocked:
newnick = what.split(' ')[1]
whats = what.split(' ')
if whats[0] == 'nick' and admin_unlocked and len(whats) >= 2:
newnick = whats[1]
connection.nick(newnick)
config.set('IRC', 'nick', newnick)
connection.privmsg(replypath, 'changed nickname')