From 97483dc403c2ac89f9647bfb5f4982c7f1e83259 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Fri, 16 Sep 2016 14:14:41 +0300 Subject: Don't send the issue name if it appears too often --- local/globals.py | 2 ++ local/handler/GithubHandler.py | 1 + local/theme/DefaultTheme.py | 7 ++++--- local/theme/Theme.py | 1 + local/utility.py | 19 +++++++++++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/local/globals.py b/local/globals.py index b389cab..57037f9 100644 --- a/local/globals.py +++ b/local/globals.py @@ -3,8 +3,10 @@ def init(): global configOverrides global travisStatuses global secretDB + global shownIssues messageList = [] configOverrides = {} travisStatuses = {} secretDB = None + shownIssues = {} diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index b791298..ed44de4 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -146,6 +146,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): repo['name'] = data.get('repository',{}).get('name') repo['owner'] = data.get('repository',{}).get('owner',{}).get('login') repo['fork'] = data.get('repository',{}).get('fork', False) + repo['id'] = data.get('repository',{}).get('id', "%s/%s" % (repo['owner'], repo['name'])) theme = klass(repo, brackets) # diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py index 2cd6226..3442383 100644 --- a/local/theme/DefaultTheme.py +++ b/local/theme/DefaultTheme.py @@ -76,6 +76,7 @@ class DefaultTheme(Theme): def issue(self, actor, action, type, issueNo, issueTitle, creator, milestone, url, assignee = None, comment = None, labelName = None, labelColor = None): formattedActor = ircutils.mircColor(actor, "green") + showName = showIssueName(self.repoId, issueNo) if actor == assignee: formattedActor = ircutils.bold(formattedActor) @@ -88,18 +89,18 @@ class DefaultTheme(Theme): elif action == 'labeled' or action == 'unlabeled': extra = " as %s" % ircutils.mircColor(labelName, hexToMirc(labelColor)) - self.msgs.append( "%s: %s %s %s #%s \"%s\"%s%s %s%s" % ( + self.msgs.append( "%s: %s %s %s #%s%s%s%s %s%s" % ( self.repo(), formattedActor, colorAction(action), type, issueNo, - ircutils.bold(issueTitle), + " \"%s\"" % (ircutils.bold(issueTitle)) if showName else '', " by %s" % ircutils.mircColor(creator,"green") if creator != actor else '', extra, self.enclose("%s%s" % ( ircutils.mircColor(milestone, "brown") + ' - ' if milestone else '', - url + url if (showName or comment) else '' )), ": %s" % maxLen(comment, 70) if comment else '' )) diff --git a/local/theme/Theme.py b/local/theme/Theme.py index c209e49..df8929a 100644 --- a/local/theme/Theme.py +++ b/local/theme/Theme.py @@ -2,6 +2,7 @@ class Theme(object): def __init__(self, repository, brackets = "()"): self.msgs = [] self.repoInfo = repository + self.repoId = repository['id'] self.brackets = brackets def finalize(self): diff --git a/local/utility.py b/local/utility.py index 065be0f..9120104 100644 --- a/local/utility.py +++ b/local/utility.py @@ -3,6 +3,7 @@ import math import random import string import urllib2 +from datetime import datetime, timedelta import supybot.conf as conf import supybot.world as world @@ -163,6 +164,24 @@ def getChannelSecret(channel): except KeyError: return None +def showIssueName(repoId, issueId): + """Returns whether we should show the issue name for a repo issue""" + now = datetime.now() + + if not repoId in globals.shownIssues: + globals.shownIssues[repoId] = {} + + # Clean up old issues + remove = [k for k in globals.shownIssues[repoId] if now - globals.shownIssues[repoId][k] > timedelta(seconds = 15)] + for k in remove: del globals.shownIssues[repoId][k] + + exists = issueId in globals.shownIssues[repoId] + + # Add our issue to the list + globals.shownIssues[repoId][issueId] = now + + return not exists + def hexToMirc(hash): colors = { 'white': (255, 255, 255), -- cgit v1.2.3