From f161a009ceeb3970f5bed2bc569bb0696e2001c8 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Fri, 16 Sep 2016 16:32:05 +0300 Subject: Allow using supybot to override config values for each channel --- config.py | 28 +++++++++++++++------------- local/globals.py | 2 ++ local/handler/GithubHandler.py | 2 ++ local/utility.py | 17 +++++++++++++---- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/config.py b/config.py index f91f05b..3e0f66c 100644 --- a/config.py +++ b/config.py @@ -16,14 +16,16 @@ Github = conf.registerPlugin('Github') # This is where your configuration variables (if any) should go. For example: # conf.registerGlobalValue(Github, 'someConfigVariableName', # registry.Boolean(False, """Help for someConfigVariableName.""")) +# +# Global values should also be added to configValue() in utility.py conf.registerGlobalValue(Github, 'channel', registry.String('#commits', """Determines the channel where commit notifications will go by default.""")) -conf.registerGlobalValue(Github, 'shortURL', +conf.registerChannelValue(Github, 'shortURL', registry.Boolean(True, """Use git.io to produce shorter URLs""")) -conf.registerGlobalValue(Github, 'hidePush', +conf.registerChannelValue(Github, 'hidePush', registry.Boolean(False, """Whether to hide 'user pushed ... commits' message""")) conf.registerGlobalValue(Github, 'passcode', @@ -37,19 +39,19 @@ conf.registerGlobalValue(Github, 'disallowConfigOverride', registry.Boolean(True, """Don't let the user change config values from the URL""")) -conf.registerGlobalValue(Github, 'showMilestone', +conf.registerChannelValue(Github, 'showMilestone', registry.Boolean(True, """Show the name of the milestone when reporting issues or issue comments""")) -conf.registerGlobalValue(Github, 'tagShowCommitMsg', +conf.registerChannelValue(Github, 'tagShowCommitMsg', registry.Boolean(True, """Show the commit message of the commit a new tag points to""")) -conf.registerGlobalValue(Github, 'showMergedCommits', +conf.registerChannelValue(Github, 'showMergedCommits', registry.Boolean(False, """Show merged commits when a branch is merged into another""")) -conf.registerGlobalValue(Github, 'showSuccessfulBuildMessages', +conf.registerChannelValue(Github, 'showSuccessfulBuildMessages', registry.String('change', """Whether to show successful build messages - can be never, change or always""")) @@ -57,29 +59,29 @@ conf.registerGlobalValue(Github, 'port', registry.Integer(8093, """The port where Github will send HTTP requests""")) -conf.registerGlobalValue(Github, 'theme', +conf.registerChannelValue(Github, 'theme', registry.String('default', """The name of the theme that will be used to style messages""")) -conf.registerGlobalValue(Github, 'brackets', +conf.registerChannelValue(Github, 'brackets', registry.String('( )', """The brackets to use to enclose URLs (space-separated)""")) -conf.registerGlobalValue(Github, 'allowArbitraryMessages', +conf.registerChannelValue(Github, 'allowArbitraryMessages', registry.Boolean(False, """Whether to allow parsing and showing arbitrary messages sent by a client""")) -conf.registerGlobalValue(Github, 'hideURL', +conf.registerChannelValue(Github, 'hideURL', registry.Boolean(False, """Whether to not display the URLs of actions""")) -conf.registerGlobalValue(Github, 'preventIssueNameSpam', +conf.registerChannelValue(Github, 'preventIssueNameSpam', registry.Boolean(True, """Whether to prevent the same issue name from showing up too often""")) -conf.registerGlobalValue(Github, 'showIssueEdits', +conf.registerChannelValue(Github, 'showIssueEdits', registry.Boolean(True, """Whether to show a message when an issue is edited""")) -conf.registerGlobalValue(Github, 'showPendingStatuses', +conf.registerChannelValue(Github, 'showPendingStatuses', registry.Boolean(True, """Whether to show a message for a pending status (e.g. a build in progress)""")) diff --git a/local/globals.py b/local/globals.py index 57037f9..a05105d 100644 --- a/local/globals.py +++ b/local/globals.py @@ -4,9 +4,11 @@ def init(): global travisStatuses global secretDB global shownIssues + global channel messageList = [] configOverrides = {} travisStatuses = {} secretDB = None shownIssues = {} + channel = None diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index ed44de4..6b2dd30 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -24,6 +24,7 @@ import supybot.ircutils as ircutils import supybot.registry as registry import supybot.callbacks as callbacks +from ..globals import * from ..utility import * import PingHandler @@ -92,6 +93,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): addConfigOverride(explosion[0], explosion[1]) i+=1 + globals.channel = channel try: s.send_response(200) diff --git a/local/utility.py b/local/utility.py index b16646f..e84ea28 100644 --- a/local/utility.py +++ b/local/utility.py @@ -5,6 +5,7 @@ import string import urllib2 from datetime import datetime, timedelta +import supybot.log as log import supybot.conf as conf import supybot.world as world import supybot.ircutils as ircutils @@ -18,10 +19,14 @@ def registryValue(plugin, name, channel=None, value=True): for name in names: group = group.get(name) if channel is not None: - if ircutils.isChannel(channel): - group = group.get(channel) - else: - self.log.debug('registryValue got channel=%r', channel) + try: + if ircutils.isChannel(channel): + group = group.get(channel) + else: + log.debug('registryValue got channel=%r', channel) + except registry.NonExistentRegistryEntry: + log.debug('non existent registry entry %r for channel %r', name, channel) + pass if value: return group() else: @@ -30,6 +35,10 @@ def registryValue(plugin, name, channel=None, value=True): def configValue(name, channel=None, repo=None, type=None, module=None): if globals.configOverrides and name.lower() in globals.configOverrides: return globals.configOverrides[name.lower()] + + if channel == None and name not in ['channel', 'passcode', 'disallowChannelOverride', 'disallowConfigOverride']: + channel = globals.channel + return registryValue("Github", name, channel) def addConfigOverride(name, value): -- cgit v1.2.3