From d66aa492c5c6ddea7d3b71f09d29606d95e3c446 Mon Sep 17 00:00:00 2001 From: CrimsonVoid Date: Wed, 6 Mar 2013 17:05:13 -0600 Subject: [PATCH 1/3] Fixed queue() not handling tokens correctly --- hanyuu_commands.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hanyuu_commands.py b/hanyuu_commands.py index 1bdc8aa..e94c862 100644 --- a/hanyuu_commands.py +++ b/hanyuu_commands.py @@ -117,10 +117,12 @@ def lp(server, nick, channel, text, hostmask): lp.handler = ("on_text", r'[.!@]lp$', irc.ALL_NICKS, irc.ALL_CHANNELS) def queue(server, nick, channel, text, hostmask): - p = tokenize(text) - if len(p) > 1: - if p[1] == u"length" or p[1] == u"l": - request_queue = regular_queue = requests_ = regulars = 0 + match = re.match(r"^[.@!]q(ueue)? ?(?Pl(ength)?)?.*", text, re.I|re.U) + + # We can be lazy here and not check if re.match() found anything because + # the function handler ensures [.!@]q(ueue)? match + if match.group("command"): + request_queue = regular_queue = requests_ = regulars = 0 for song in manager.Queue().iter(None): if (song.type == manager.REQUEST): request_queue += song.length @@ -143,11 +145,14 @@ def queue(server, nick, channel, text, hostmask): if (song.type == manager.REQUEST): request_time += song.length - message = u"{c3}Queue {time}:{c} ".format(time = "" if request_time == 0\ - else "(/r/ time: {t})".format(t=timedelta(seconds=request_time)), **irc_colours) + \ - " {c3}|{c} ".format(**irc_colours)\ - .join([song.metadata for song in queue]) + time_str = "" + if request_time != 0: + time_str = "(/r/ time: {t})".format(t=timedelta(seconds=request_time)) + + message = u"{c3}Queue {time}:{c} ".format(time = time_str, **irc_colours) + \ + " {c3}|{c} ".format(**irc_colours).join([song.metadata for song in queue]) else: + # Would this ever trigger? message = u"No queue at the moment" server.privmsg(channel, message) From e063212a4477868957aadc6e808dd2171fb0407b Mon Sep 17 00:00:00 2001 From: CrimsonVoid Date: Wed, 6 Mar 2013 17:21:07 -0600 Subject: [PATCH 2/3] Small fix to the regex in queue() --- hanyuu_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hanyuu_commands.py b/hanyuu_commands.py index e94c862..e8d9986 100644 --- a/hanyuu_commands.py +++ b/hanyuu_commands.py @@ -117,7 +117,7 @@ def lp(server, nick, channel, text, hostmask): lp.handler = ("on_text", r'[.!@]lp$', irc.ALL_NICKS, irc.ALL_CHANNELS) def queue(server, nick, channel, text, hostmask): - match = re.match(r"^[.@!]q(ueue)? ?(?Pl(ength)?)?.*", text, re.I|re.U) + match = re.match(r"^[.@!]q(ueue)?\b(?Pl(ength)?)?", text, re.I|re.U) # We can be lazy here and not check if re.match() found anything because # the function handler ensures [.!@]q(ueue)? match From 362e063a807af45463899eeb6d7ee70412b86ed5 Mon Sep 17 00:00:00 2001 From: CrimsonVoid Date: Wed, 6 Mar 2013 17:27:06 -0600 Subject: [PATCH 3/3] Fixed indention --- hanyuu_commands.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/hanyuu_commands.py b/hanyuu_commands.py index e8d9986..74560f7 100644 --- a/hanyuu_commands.py +++ b/hanyuu_commands.py @@ -123,20 +123,20 @@ def queue(server, nick, channel, text, hostmask): # the function handler ensures [.!@]q(ueue)? match if match.group("command"): request_queue = regular_queue = requests_ = regulars = 0 - for song in manager.Queue().iter(None): - if (song.type == manager.REQUEST): - request_queue += song.length - requests_ += 1 - elif (song.type == manager.REGULAR): - regular_queue += song.length - regulars += 1 - message = u"There are {req} requests ({req_time}), {norm} randoms ({norm_time}), total of {total} songs ({total_time})".\ - format(**{'req_time': timedelta(seconds=request_queue), - 'norm_time': timedelta(seconds=regular_queue), - 'total_time': timedelta(seconds=request_queue+regular_queue), - 'req': requests_, - 'norm': regulars, - 'total': requests_+regulars}) + for song in manager.Queue().iter(None): + if (song.type == manager.REQUEST): + request_queue += song.length + requests_ += 1 + elif (song.type == manager.REGULAR): + regular_queue += song.length + regulars += 1 + message = u"There are {req} requests ({req_time}), {norm} randoms ({norm_time}), total of {total} songs ({total_time})".\ + format(**{'req_time': timedelta(seconds=request_queue), + 'norm_time': timedelta(seconds=regular_queue), + 'total_time': timedelta(seconds=request_queue+regular_queue), + 'req': requests_, + 'norm': regulars, + 'total': requests_+regulars}) else: queue = list(manager.Queue()) if (len(queue) > 0): @@ -152,7 +152,6 @@ def queue(server, nick, channel, text, hostmask): message = u"{c3}Queue {time}:{c} ".format(time = time_str, **irc_colours) + \ " {c3}|{c} ".format(**irc_colours).join([song.metadata for song in queue]) else: - # Would this ever trigger? message = u"No queue at the moment" server.privmsg(channel, message)