Allow url shorteners to be specified per-channel
This commit is contained in:
parent
2db2937038
commit
73fd3f37ce
2 changed files with 12 additions and 4 deletions
|
@ -16,6 +16,7 @@ class Module(ModuleManager.BaseModule):
|
|||
setting = utils.OptionsSetting("url-shortener", [],
|
||||
"Set URL shortener service",
|
||||
options_factory=self._shorturl_options_factory)
|
||||
self.exports.add("channelset", setting)
|
||||
self.exports.add("serverset", setting)
|
||||
self.exports.add("botset", setting)
|
||||
|
||||
|
@ -37,8 +38,14 @@ class Module(ModuleManager.BaseModule):
|
|||
def _shorturl_any(self, url):
|
||||
return self._call_shortener("bitly", url) or url
|
||||
|
||||
def _shorturl(self, server, url):
|
||||
shortener_name = server.get_setting("url-shortener", "bitly")
|
||||
def _shorturl(self, server, url, context=None):
|
||||
shortener_name = None
|
||||
if context:
|
||||
shortener_name = context.get_setting("url-shortener",
|
||||
server.get_setting("url-shortener", "bitly"))
|
||||
else:
|
||||
shortener_name = server.get_setting("url-shortener", "bitly")
|
||||
|
||||
if shortener_name == None:
|
||||
return url
|
||||
return self._call_shortener(shortener_name, url) or url
|
||||
|
@ -80,7 +87,7 @@ class Module(ModuleManager.BaseModule):
|
|||
url = self._find_url(event["target"], event["args_split"])
|
||||
|
||||
event["stdout"].write("Shortened URL: %s" % self._shorturl(
|
||||
event["server"], url))
|
||||
event["server"], url, context=event["target"]))
|
||||
|
||||
@utils.hook("received.command.unshorten")
|
||||
def unshorten(self, event):
|
||||
|
|
|
@ -37,7 +37,8 @@ class Module(ModuleManager.BaseModule):
|
|||
"\r", "").replace(" ", " ").strip()
|
||||
|
||||
if channel.get_setting("title-shorten", False):
|
||||
short_url = self.exports.get_one("shorturl")(server, url)
|
||||
short_url = self.exports.get_one("shorturl")(server, url,
|
||||
context=channel)
|
||||
return "%s - %s" % (title, short_url)
|
||||
return title
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue