Mark command hooks that are aliases ('g' vs 'google')
This commit is contained in:
parent
c28a41ad21
commit
376825ea96
15 changed files with 55 additions and 21 deletions
|
@ -33,7 +33,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
raise UserNotFoundException("That user is not in this channel")
|
raise UserNotFoundException("That user is not in this channel")
|
||||||
|
|
||||||
@utils.hook("received.command.kick|k", channel_only=True, min_args=1)
|
@utils.hook("received.command.k", alias_of="kick")
|
||||||
|
@utils.hook("received.command.kick", channel_only=True, min_args=1)
|
||||||
def kick(self, event):
|
def kick(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Kick a user from the current channel
|
:help: Kick a user from the current channel
|
||||||
|
@ -103,7 +104,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
self.bot.timers.add_persistent("unban", timeout,
|
self.bot.timers.add_persistent("unban", timeout,
|
||||||
server_id=event["server"].id,
|
server_id=event["server"].id,
|
||||||
channel_name=event["target"].name, hostmask=hostmask)
|
channel_name=event["target"].name, hostmask=hostmask)
|
||||||
@utils.hook("received.command.tempban|tb", channel_only=True, min_args=2)
|
|
||||||
|
@utils.hook("received.command.tb", alias_of="tempban")
|
||||||
|
@utils.hook("received.command.tempban", channel_only=True, min_args=2)
|
||||||
def temp_ban(self, event):
|
def temp_ban(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Temporarily ban someone from the current channel
|
:help: Temporarily ban someone from the current channel
|
||||||
|
@ -115,7 +118,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
self._temp_ban(event, True)
|
self._temp_ban(event, True)
|
||||||
except InvalidTimeoutException as e:
|
except InvalidTimeoutException as e:
|
||||||
event["stderr"].write(str(e))
|
event["stderr"].write(str(e))
|
||||||
@utils.hook("received.command.tempkickban|tkb", channel_only=True,
|
|
||||||
|
@utils.hook("received.command.tkb", alias_of="tempkickban")
|
||||||
|
@utils.hook("received.command.tempkickban", channel_only=True,
|
||||||
min_args=2)
|
min_args=2)
|
||||||
def temp_kick_ban(self, event):
|
def temp_kick_ban(self, event):
|
||||||
"""
|
"""
|
||||||
|
@ -144,7 +149,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
self._ban(event["server"], event["target"], False,
|
self._ban(event["server"], event["target"], False,
|
||||||
event["args_split"][0])
|
event["args_split"][0])
|
||||||
|
|
||||||
@utils.hook("received.command.kickban|kb", channel_only=True, min_args=1)
|
@utils.hook("received.command.kb", alias_of="kickban")
|
||||||
|
@utils.hook("received.command.kickban", channel_only=True, min_args=1)
|
||||||
def kickban(self, event):
|
def kickban(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Kick and ban a user from the current channel
|
:help: Kick and ban a user from the current channel
|
||||||
|
|
|
@ -112,6 +112,13 @@ class Module(ModuleManager.BaseModule):
|
||||||
return
|
return
|
||||||
|
|
||||||
hook = self.get_hook(command)
|
hook = self.get_hook(command)
|
||||||
|
alias_of = self._get_alias_of(hook)
|
||||||
|
if alias_of:
|
||||||
|
if self.has_command(alias_of):
|
||||||
|
hook = self.get_hook(alias_of)
|
||||||
|
else:
|
||||||
|
raise ValueError("'%s' is an alias of unknown command '%s'"
|
||||||
|
% (command.lower(), alias_of.lower()))
|
||||||
is_channel = False
|
is_channel = False
|
||||||
|
|
||||||
if "channel" in event:
|
if "channel" in event:
|
||||||
|
@ -197,6 +204,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
return hook.get_kwarg("usage", None)
|
return hook.get_kwarg("usage", None)
|
||||||
def _get_prefix(self, hook):
|
def _get_prefix(self, hook):
|
||||||
return hook.get_kwarg("prefix", None)
|
return hook.get_kwarg("prefix", None)
|
||||||
|
def _get_alias_of(self, hook):
|
||||||
|
return hook.get_kwarg("alias_of", None)
|
||||||
|
|
||||||
@utils.hook("received.command.help")
|
@utils.hook("received.command.help")
|
||||||
def help(self, event):
|
def help(self, event):
|
||||||
|
@ -222,8 +231,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
for child in self.events.on("received.command").get_children():
|
for child in self.events.on("received.command").get_children():
|
||||||
hooks = self.events.on("received.command").on(child).get_hooks()
|
hooks = self.events.on("received.command").on(child).get_hooks()
|
||||||
|
|
||||||
if hooks and self._get_help(hooks[0]):
|
if hooks and self._get_help(hooks[0]
|
||||||
|
) and not self._get_alias_of(hooks[0]):
|
||||||
help_available.append(child)
|
help_available.append(child)
|
||||||
|
|
||||||
help_available = sorted(help_available)
|
help_available = sorted(help_available)
|
||||||
event["stdout"].write("Commands: %s" % ", ".join(help_available))
|
event["stdout"].write("Commands: %s" % ", ".join(help_available))
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ URL_GOOGLESEARCH = "https://www.googleapis.com/customsearch/v1"
|
||||||
URL_GOOGLESUGGEST = "http://google.com/complete/search"
|
URL_GOOGLESUGGEST = "http://google.com/complete/search"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.google|g")
|
@utils.hook("received.command.g", alias_of="google")
|
||||||
|
@utils.hook("received.command.google")
|
||||||
def google(self, event):
|
def google(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get first Google result for a given search term
|
:help: Get first Google result for a given search term
|
||||||
|
|
|
@ -9,7 +9,9 @@ URL_SCROBBLER = "http://ws.audioscrobbler.com/2.0/"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "last.fm"
|
_name = "last.fm"
|
||||||
|
|
||||||
@utils.hook("received.command.np|listening|nowplaying")
|
@utils.hook("received.command.np", alias_of="nowplaying")
|
||||||
|
@utils.hook("received.command.listening", alias_of="nowplaying")
|
||||||
|
@utils.hook("received.command.nowplaying")
|
||||||
def np(self, event):
|
def np(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get the last listened to track from a user
|
:help: Get the last listened to track from a user
|
||||||
|
|
|
@ -7,7 +7,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
return [part.strip() for part in s.split("=", 1)]
|
return [part.strip() for part in s.split("=", 1)]
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
@utils.hook("received.command.quoteadd|qadd", min_args=1)
|
@utils.hook("received.command.qadd", alias_of="quoteadd")
|
||||||
|
@utils.hook("received.command.quoteadd", min_args=1)
|
||||||
def quote_add(self, event):
|
def quote_add(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Add a quote to a category
|
:help: Add a quote to a category
|
||||||
|
@ -23,7 +24,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Please provide a category AND quote")
|
event["stderr"].write("Please provide a category AND quote")
|
||||||
|
|
||||||
@utils.hook("received.command.quoteget|qget", min_args=1)
|
@utils.hook("received.command.qget", alias_of="quoteget")
|
||||||
|
@utils.hook("received.command.quoteget", min_args=1)
|
||||||
def quote_get(self, event):
|
def quote_get(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get a quote from a ccategory
|
:help: Get a quote from a ccategory
|
||||||
|
@ -46,7 +48,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stderr"].write("Please provide a category and a "
|
event["stderr"].write("Please provide a category and a "
|
||||||
"part of a quote to find")
|
"part of a quote to find")
|
||||||
|
|
||||||
@utils.hook("received.command.quotedel|qdel", min_args=1)
|
@utils.hook("received.command.qdel", alias_of="quotedel")
|
||||||
|
@utils.hook("received.command.quotedel", min_args=1)
|
||||||
def quote_del(self, event):
|
def quote_del(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Delete a quote from a category
|
:help: Delete a quote from a category
|
||||||
|
@ -71,7 +74,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stderr"].write("Please provide a category and a quote "
|
event["stderr"].write("Please provide a category and a quote "
|
||||||
"to remove")
|
"to remove")
|
||||||
|
|
||||||
@utils.hook("received.command.quote|q", min_args=1)
|
@utils.hook("received.command.q", alias_of="quote")
|
||||||
|
@utils.hook("received.command.quote", min_args=1)
|
||||||
def quote(self, event):
|
def quote(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get a random quote from a category
|
:help: Get a random quote from a category
|
||||||
|
|
|
@ -4,7 +4,8 @@ from src import ModuleManager, utils
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Random"
|
_name = "Random"
|
||||||
|
|
||||||
@utils.hook("received.command.random|rand")
|
@utils.hook("received.command.rand", alias_of="random")
|
||||||
|
@utils.hook("received.command.random")
|
||||||
def random(self, event):
|
def random(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get a random number
|
:help: Get a random number
|
||||||
|
|
|
@ -10,7 +10,8 @@ REGEX_SOUNDCLOUD = "https?://soundcloud.com/([^/]+)/([^/]+)"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "SoundCloud"
|
_name = "SoundCloud"
|
||||||
|
|
||||||
@utils.hook("received.command.soundcloud|sc")
|
@utils.hook("received.command.sc", alias_of="soundcloud")
|
||||||
|
@utils.hook("received.command.soundcloud")
|
||||||
def soundcloud(self, event):
|
def soundcloud(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Search SoundCloud
|
:help: Search SoundCloud
|
||||||
|
|
|
@ -4,7 +4,8 @@ from src import ModuleManager, utils
|
||||||
REGEX_URL = re.compile("https?://\S+", re.I)
|
REGEX_URL = re.compile("https?://\S+", re.I)
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.title|t", usage="[URL]")
|
@utils.hook("received.command.t", alias_of="title")
|
||||||
|
@utils.hook("received.command.title", usage="[URL]")
|
||||||
def title(self, event):
|
def title(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get the title of a URL
|
:help: Get the title of a URL
|
||||||
|
|
|
@ -7,7 +7,8 @@ URL_TRAKTSLUG = "https://trakt.tv/%s/%s"
|
||||||
|
|
||||||
@utils.export("set", {"setting": "trakt", "help": "Set username on trakt.tv"})
|
@utils.export("set", {"setting": "trakt", "help": "Set username on trakt.tv"})
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.nowwatching|nw")
|
@utils.hook("received.command.nw", alias_of="nowwatching")
|
||||||
|
@utils.hook("received.command.nowwatching")
|
||||||
def now_watching(self, event):
|
def now_watching(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get what you or another user is now watching on trakt.tv
|
:help: Get what you or another user is now watching on trakt.tv
|
||||||
|
|
|
@ -6,7 +6,8 @@ URL_LANGUAGES = "https://cloud.google.com/translate/docs/languages"
|
||||||
REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
|
REGEX_LANGUAGES = re.compile("(\w+)?:(\w+)? ")
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.translate|tr")
|
@utils.hook("received.command.tr", alias_of="translate")
|
||||||
|
@utils.hook("received.command.translate")
|
||||||
def translate(self, event):
|
def translate(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Translate the provided phrase or the last line in thie current
|
:help: Translate the provided phrase or the last line in thie current
|
||||||
|
|
|
@ -19,7 +19,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
since, unit = utils.time_unit(seconds_since)
|
since, unit = utils.time_unit(seconds_since)
|
||||||
return "%s %s ago" % (since, unit)
|
return "%s %s ago" % (since, unit)
|
||||||
|
|
||||||
@utils.hook("received.command.tweet|tw")
|
@utils.hook("received.command.tw", alias_of="tweet")
|
||||||
|
@utils.hook("received.command.tweet")
|
||||||
def tweet(self, event):
|
def tweet(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get/find a tweet
|
:help: Get/find a tweet
|
||||||
|
|
|
@ -5,7 +5,8 @@ URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
|
||||||
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
|
REGEX_DEFNUMBER = re.compile("-n(\d+) \S+")
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.urbandictionary|ud", min_args=1)
|
@utils.hook("received.command.ud", alias_of="urbandictionary")
|
||||||
|
@utils.hook("received.command.urbandictionary", min_args=1)
|
||||||
def ud(self, event):
|
def ud(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get the definition of a provided term from Urban Dictionary
|
:help: Get the definition of a provided term from Urban Dictionary
|
||||||
|
|
|
@ -3,7 +3,8 @@ from src import ModuleManager, utils
|
||||||
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
|
URL_WIKIPEDIA = "https://en.wikipedia.org/w/api.php"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.command.wiki|wi", min_args=1)
|
@utils.hook("received.command.wi", alias_of="wiki")
|
||||||
|
@utils.hook("received.command.wiki", min_args=1)
|
||||||
def wikipedia(self, event):
|
def wikipedia(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get information from wikipedia
|
:help: Get information from wikipedia
|
||||||
|
|
|
@ -7,7 +7,8 @@ URL_WA = "https://api.wolframalpha.com/v1/result"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Wolfram|Alpha"
|
_name = "Wolfram|Alpha"
|
||||||
|
|
||||||
@utils.hook("received.command.wolframalpha|wa", min_args=1)
|
@utils.hook("received.command.wa", alias_of="wolframalpha")
|
||||||
|
@utils.hook("received.command.wolframalpha", min_args=1)
|
||||||
def wa(self, event):
|
def wa(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Evauate a given string on Wolfram|Alpha
|
:help: Evauate a given string on Wolfram|Alpha
|
||||||
|
|
|
@ -71,7 +71,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
video_id = search_page["items"][0]["id"]["videoId"]
|
video_id = search_page["items"][0]["id"]["videoId"]
|
||||||
return "https://youtu.be/%s" % video_id
|
return "https://youtu.be/%s" % video_id
|
||||||
|
|
||||||
@utils.hook("received.command.yt|youtube")
|
@utils.hook("received.command.yt", alias_of="youtube")
|
||||||
|
@utils.hook("received.command.youtube")
|
||||||
def yt(self, event):
|
def yt(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Find a video on youtube
|
:help: Find a video on youtube
|
||||||
|
|
Loading…
Reference in a new issue