print relative time of countdown items
This commit is contained in:
parent
f4b1d7955a
commit
cfab1e29ca
31
dr.botzo.py
31
dr.botzo.py
@ -131,14 +131,14 @@ def sub_change_nick(connection, event, nick, userhost, replypath, what, admin_un
|
||||
connection.privmsg(replypath, 'changed nickname')
|
||||
|
||||
#####
|
||||
# sub_add_countdown
|
||||
# sub_countdown
|
||||
# add a countdown item to the bot
|
||||
#####
|
||||
|
||||
def sub_add_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
def sub_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
whats = what.split(' ')
|
||||
if whats[0] == 'countdown' and len(whats) >= 4:
|
||||
if whats[1] == 'add':
|
||||
if whats[0] == 'countdown' and len(whats) >= 2:
|
||||
if whats[1] == 'add' and len(whats) >= 4:
|
||||
item = whats[2]
|
||||
target = parse(' '.join(whats[3:]), default=datetime.now().replace(tzinfo=tzlocal()))
|
||||
if not config.has_section('countdown'):
|
||||
@ -146,6 +146,25 @@ def sub_add_countdown(connection, event, nick, userhost, replypath, what, admin_
|
||||
|
||||
config.set('countdown', item, target.astimezone(tzutc()).isoformat())
|
||||
connection.privmsg(replypath, 'added countdown item')
|
||||
else:
|
||||
try:
|
||||
time = parse(config.get('countdown', whats[1]))
|
||||
rdelta = relativedelta(time, datetime.now().replace(tzinfo=tzlocal()))
|
||||
relstr = whats[1] + ' will occur in '
|
||||
if rdelta.years != 0:
|
||||
relstr += str(rdelta.years) + ' years '
|
||||
if rdelta.months != 0:
|
||||
relstr += str(rdelta.months) + ' months '
|
||||
if rdelta.days != 0:
|
||||
relstr += str(rdelta.days) + ' days '
|
||||
if rdelta.hours != 0:
|
||||
relstr += str(rdelta.hours) + ' hours '
|
||||
if rdelta.minutes != 0:
|
||||
relstr += str(rdelta.minutes) + ' minutes '
|
||||
if rdelta.seconds != 0:
|
||||
relstr += str(rdelta.seconds) + ' seconds'
|
||||
connection.privmsg(replypath, relstr)
|
||||
except NoOptionError: pass
|
||||
|
||||
#####
|
||||
# on_connect
|
||||
@ -195,7 +214,7 @@ def on_privmsg(connection, event):
|
||||
|
||||
# standard commands
|
||||
sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
sub_add_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
sub_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
|
||||
#####
|
||||
# on_pubmsg
|
||||
@ -236,7 +255,7 @@ def on_pubmsg(connection, event):
|
||||
|
||||
# standard commands
|
||||
sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
sub_add_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
sub_countdown(connection, event, nick, userhost, replypath, what, admin_unlocked)
|
||||
|
||||
#####
|
||||
# init
|
||||
|
Loading…
Reference in New Issue
Block a user