Skip to content

Commit

Permalink
Migrate modules to new db
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Sep 14, 2014
1 parent 7253466 commit 1f87499
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 209 deletions.
41 changes: 14 additions & 27 deletions adminchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
from willie.tools import Nick


def setup(bot):
#Having a db means pref's exists. Later, we can just use `if bot.db`.
if bot.db and not bot.db.preferences.has_columns('topic_mask'):
bot.db.preferences.add_columns(['topic_mask'])


@commands('op')
def op(bot, trigger):
"""
Expand Down Expand Up @@ -228,9 +222,9 @@ def quiet(bot, trigger):
@commands('unquiet')
def unquiet(bot, trigger):
"""
This gives admins the ability to unquiet a user.
The bot must be a Channel Operator for this command to work.
"""
This gives admins the ability to unquiet a user.
The bot must be a Channel Operator for this command to work.
"""
if bot.privileges[trigger.sender][trigger.nick] < OP:
return
if bot.privileges[trigger.sender][bot.nick] < OP:
Expand All @@ -257,10 +251,10 @@ def unquiet(bot, trigger):
@priority('high')
def kickban(bot, trigger):
"""
This gives admins the ability to kickban a user.
The bot must be a Channel Operator for this command to work.
.kickban [#chan] user1 user!*@* get out of here
"""
This gives admins the ability to kickban a user.
The bot must be a Channel Operator for this command to work.
.kickban [#chan] user1 user!*@* get out of here
"""
if bot.privileges[trigger.sender][trigger.nick] < OP:
return
if bot.privileges[trigger.sender][bot.nick] < HALFOP:
Expand Down Expand Up @@ -306,9 +300,8 @@ def topic(bot, trigger):

narg = 1
mask = None
if bot.db and channel in bot.db.preferences:
mask = bot.db.preferences.get(channel, 'topic_mask')
narg = len(re.findall('%s', mask))
mask = bot.db.get_channel_value(channel, 'topic_mask')
narg = len(re.findall('%s', mask))
if not mask or mask == '':
mask = purple + 'Welcome to: ' + green + channel + purple \
+ ' | ' + bold + 'Topic: ' + bold + green + '%s'
Expand All @@ -334,21 +327,15 @@ def set_mask(bot, trigger):
"""
if bot.privileges[trigger.sender][trigger.nick] < OP:
return
if not bot.db:
bot.say("I'm afraid I can't do that.")
else:
bot.db.preferences.update(trigger.sender.lower(), {'topic_mask': trigger.group(2)})
bot.say("Gotcha, " + trigger.nick)
bot.db.set_channel_value(trigger.sender, 'topic_mask', trigger.group(2))
bot.say("Gotcha, " + trigger.nick)


@commands('showmask')
def show_mask(bot, trigger):
"""Show the topic mask for the current channel."""
if bot.privileges[trigger.sender][trigger.nick] < OP:
return
if not bot.db:
bot.say("I'm afraid I can't do that.")
elif trigger.sender.lower() in bot.db.preferences:
bot.say(bot.db.preferences.get(trigger.sender.lower(), 'topic_mask'))
else:
bot.say("%s")
mask = bot.db.get_channel_value(trigger.sender, 'topic_mask')
mask = mask or "%s"
bot.say(mask)
109 changes: 46 additions & 63 deletions clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def configure(config):
'Preferred time format (http://strftime.net)', '%F - %T%Z')


def setup(bot):
#Having a db means pref's exists. Later, we can just use `if bot.db`.
if bot.db and not bot.db.preferences.has_columns('tz'):
bot.db.preferences.add_columns(['tz'])
if bot.db and not bot.db.preferences.has_columns('time_format'):
bot.db.preferences.add_columns(['time_format'])


@commands('t', 'time')
@example('.t America/New_York')
def f_time(bot, trigger):
Expand All @@ -59,8 +51,6 @@ def update_user(bot, trigger):
"""
if not pytz:
bot.reply("Sorry, I don't have timezone support installed.")
elif not bot.db:
bot.reply("I can't remember that; I don't have a database.")
else:
tz = trigger.group(2)
if not tz:
Expand All @@ -72,7 +62,7 @@ def update_user(bot, trigger):
"http://dft.ba/-tz")
return

bot.db.preferences.update(trigger.nick, {'tz': tz})
bot.db.set_nick_value(trigger.nick, 'timezone', tz)
if len(tz) < 7:
bot.say("Okay, " + trigger.nick +
", but you should use one from http://dft.ba/-tz if "
Expand All @@ -88,34 +78,31 @@ def update_user_format(bot, trigger):
Sets your preferred format for time. Uses the standard strftime format. You
can use http://strftime.net or your favorite search engine to learn more.
"""
if bot.db:
tformat = trigger.group(2)
if not tformat:
bot.reply("What format do you want me to use? Try using"
" http://strftime.net to make one.")

tz = get_timezone(bot.db, bot.config, None, None,
trigger.sender)

# Get old format as back-up
old_format = bot.db.preferences.get(trigger.nick, 'time_format')

# Save the new format in the database so we can test it.
bot.db.preferences.update(trigger.nick, {'time_format': tformat})

try:
timef = format_time(db = bot.db, zone=tz, nick=trigger.nick)
except:
bot.reply("That format doesn't work. Try using"
" http://strftime.net to make one.")
# New format doesn't work. Revert save in database.
bot.db.preferences.update(trigger.nick, {'time_format': old_format})
return
bot.reply("Got it. Your time will now appear as %s. (If the "
"timezone is wrong, you might try the settz command)"
% timef)
else:
bot.reply("I can't remember that; I don't have a database.")
tformat = trigger.group(2)
if not tformat:
bot.reply("What format do you want me to use? Try using"
" http://strftime.net to make one.")

tz = get_timezone(bot.db, bot.config, None, None,
trigger.sender)

# Get old format as back-up
old_format = bot.db.get_nick_value(trigger.nick, 'time_format')

# Save the new format in the database so we can test it.
bot.db.set_nick_value(trigger.nick, 'time_format', tformat)

try:
timef = format_time(db = bot.db, zone=tz, nick=trigger.nick)
except:
bot.reply("That format doesn't work. Try using"
" http://strftime.net to make one.")
# New format doesn't work. Revert save in database.
bot.db.set_nick_value(trigger.nick, 'time_format', old_format)
return
bot.reply("Got it. Your time will now appear as %s. (If the "
"timezone is wrong, you might try the settz command)"
% timef)


@commands('channeltz')
Expand All @@ -128,8 +115,6 @@ def update_channel(bot, trigger):
return
elif not pytz:
bot.reply("Sorry, I don't have timezone support installed.")
elif not bot.db:
bot.reply("I can't remember that; I don't have a database.")
else:
tz = trigger.group(2)
if not tz:
Expand All @@ -141,7 +126,7 @@ def update_channel(bot, trigger):
"http://dft.ba/-tz")
return

bot.db.preferences.update(trigger.sender, {'tz': tz})
bot.db.set_channel_value(trigger.sender, 'timezone', tz)
if len(tz) < 7:
bot.say("Okay, " + trigger.nick +
", but you should use one from http://dft.ba/-tz if "
Expand All @@ -160,25 +145,23 @@ def update_channel_format(bot, trigger):
"""
if bot.privileges[trigger.sender][trigger.nick] < OP:
return
elif not bot.db:
bot.reply("I can't remember that; I don't have a database.")
else:
tformat = trigger.group(2)
if not tformat:
bot.reply("What format do you want me to use? Try using"
" http://strftime.net to make one.")

tz = get_timezone(bot.db, bot.config, None, None,
trigger.sender)
try:
timef = format_time(zone=tz)
except:
bot.reply("That format doesn't work. Try using"
" http://strftime.net to make one.")
return
bot.db.preferences.update(trigger.sender, {'time_format': tformat})
bot.reply("Got it. Times in this channel will now appear as %s "
"unless a user has their own format set. (If the timezone"
" is wrong, you might try the settz and channeltz "
"commands)" % timef)

tformat = trigger.group(2)
if not tformat:
bot.reply("What format do you want me to use? Try using"
" http://strftime.net to make one.")

tz = get_timezone(bot.db, bot.config, None, None,
trigger.sender)
try:
timef = format_time(zone=tz)
except:
bot.reply("That format doesn't work. Try using"
" http://strftime.net to make one.")
return
bot.db.set_channel_value(trigger.sender, 'time_format', tformat)
bot.reply("Got it. Times in this channel will now appear as %s "
"unless a user has their own format set. (If the timezone"
" is wrong, you might try the settz and channeltz "
"commands)" % timef)

Loading

0 comments on commit 1f87499

Please sign in to comment.