Use utils.formatTime
This commit is contained in:
parent
d9d30d9279
commit
052bd09540
@ -6,18 +6,19 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
|
from syncplay import utils
|
||||||
|
|
||||||
class Bot(object):
|
class Bot(object):
|
||||||
def __init__(self, server='irc.rizon.net', serverPassword='', port=6667, nick='SyncBot', nickservPass='', channel='', channelPassword='', functions=[]):
|
def __init__(self, server='irc.rizon.net', serverPassword='', port=6667, nick='SyncBot', nickservPass='', channel='', channelPassword='', functions=[]):
|
||||||
#Arguments
|
#Arguments
|
||||||
# server - IRC Server to connect to
|
# server - IRC Server to connect to
|
||||||
# serverPassword - probably empty
|
# serverPassword - probably empty
|
||||||
# port - usually between 6660 - 6669, 7000
|
# port - usually between 6660 - 6669, 7000
|
||||||
# nick - duh
|
# nick - duh
|
||||||
# nickservPass - if not given, NickServ identification string won't be sent
|
# nickservPass - if not given, NickServ identification string won't be sent
|
||||||
# channel - channel to autojoin and interact with
|
# channel - channel to autojoin and interact with
|
||||||
# channelPassword - if channel is +k
|
# channelPassword - if channel is +k
|
||||||
# functions - list/tuple of functions that can be used from the bot:
|
# functions - list/tuple of functions that can be used from the bot:
|
||||||
# * pause(room, state=bool)
|
# * pause(room, state=bool)
|
||||||
# * getRooms() -> list
|
# * getRooms() -> list
|
||||||
# * getPosition(room) -> int
|
# * getPosition(room) -> int
|
||||||
@ -114,7 +115,7 @@ class Bot(object):
|
|||||||
users = self.functions[4](room)
|
users = self.functions[4](room)
|
||||||
paused = self.functions[5](room)
|
paused = self.functions[5](room)
|
||||||
out = chr(2) + '<Paused>' + chr(15) if paused else chr(2) + '<Playing>' + chr(15)
|
out = chr(2) + '<Paused>' + chr(15) if paused else chr(2) + '<Playing>' + chr(15)
|
||||||
out += ' [' + elapsed_time(self.functions[2](room)) + '/' + elapsed_time(users[0]['length']) + '] '
|
out += ' [' + utils.formatTime(self.functions[2](room)) + '/' + utils.formatTime(users[0]['length']) + '] '
|
||||||
out += users[0]['file']
|
out += users[0]['file']
|
||||||
self.msg(to, out)
|
self.msg(to, out)
|
||||||
out = 'Users: '
|
out = 'Users: '
|
||||||
@ -201,32 +202,3 @@ def handlingThread(sock, bot):
|
|||||||
msg = msg[:-1].lstrip()
|
msg = msg[:-1].lstrip()
|
||||||
# ---END WTF BLOCK- --
|
# ---END WTF BLOCK- --
|
||||||
bot.irc_onMsg(nfrom, addrnfrom, to, msg)
|
bot.irc_onMsg(nfrom, addrnfrom, to, msg)
|
||||||
def elapsed_time(seconds, suffixes=['y','w','d','','',''], add_s=False, separator=':'):
|
|
||||||
"""
|
|
||||||
Takes an amount of seconds and turns it into a human-readable amount of time.
|
|
||||||
"""
|
|
||||||
# the formatted time string to be returned
|
|
||||||
time = []
|
|
||||||
|
|
||||||
# the pieces of time to iterate over (days, hours, minutes, etc)
|
|
||||||
# - the first piece in each tuple is the suffix (d, h, w)
|
|
||||||
# - the second piece is the length in seconds (a day is 60s * 60m * 24h)
|
|
||||||
parts = [(suffixes[0], 60 * 60 * 24 * 7 * 52),
|
|
||||||
(suffixes[1], 60 * 60 * 24 * 7),
|
|
||||||
(suffixes[2], 60 * 60 * 24),
|
|
||||||
(suffixes[3], 60 * 60),
|
|
||||||
(suffixes[4], 60),
|
|
||||||
(suffixes[5], 1)]
|
|
||||||
|
|
||||||
# for each time piece, grab the value and remaining seconds, and add it to
|
|
||||||
# the time string
|
|
||||||
for suffix, length in parts:
|
|
||||||
value = seconds / length
|
|
||||||
if value > 0:
|
|
||||||
seconds = seconds % length
|
|
||||||
time.append('%s%s' % (str(value),
|
|
||||||
(suffix, (suffix, suffix + 's')[value > 1])[add_s]))
|
|
||||||
if seconds < 1:
|
|
||||||
break
|
|
||||||
|
|
||||||
return separator.join(time)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user