Switch to using docstring for usage, permission and require_mode
This commit is contained in:
parent
44887ab51d
commit
10ef985a8a
53 changed files with 415 additions and 276 deletions
|
@ -29,10 +29,11 @@ CHOICES = [
|
||||||
]
|
]
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.8ball", min_args=1, usage="<question>")
|
@Utils.hook("received.command.8ball", min_args=1)
|
||||||
def decide(selfs, event):
|
def decide(selfs, event):
|
||||||
"""
|
"""
|
||||||
Ask the mystic 8ball a question!
|
:help: Ask the mystic 8ball a question!
|
||||||
|
:usage: <question>
|
||||||
"""
|
"""
|
||||||
event["stdout"].write("You shake the magic ball... it "
|
event["stdout"].write("You shake the magic ball... it "
|
||||||
"says " + Utils.bold(random.choice(CHOICES)))
|
"says " + Utils.bold(random.choice(CHOICES)))
|
||||||
|
|
|
@ -1,27 +1,31 @@
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.changenickname",
|
@Utils.hook("received.command.changenickname", min_args=1)
|
||||||
permission="changenickname", min_args=1, usage="<nickname>")
|
|
||||||
def change_nickname(self, event):
|
def change_nickname(self, event):
|
||||||
"""
|
"""
|
||||||
Change my nickname
|
:help: Change my nickname
|
||||||
|
:usage: <nickname>
|
||||||
|
:permission: changenickname
|
||||||
"""
|
"""
|
||||||
nickname = event["args_split"][0]
|
nickname = event["args_split"][0]
|
||||||
event["server"].send_nick(nickname)
|
event["server"].send_nick(nickname)
|
||||||
|
|
||||||
@Utils.hook("received.command.raw", permission="raw", min_args=1,
|
@Utils.hook("received.command.raw", min_args=1)
|
||||||
usage="<raw line>")
|
|
||||||
def raw(self, event):
|
def raw(self, event):
|
||||||
"""
|
"""
|
||||||
Send a line of raw IRC data
|
:help: Send a line of raw IRC data
|
||||||
|
:usage: <raw line>
|
||||||
|
:permission: raw
|
||||||
"""
|
"""
|
||||||
event["server"].send(event["args"])
|
event["server"].send(event["args"])
|
||||||
|
|
||||||
@Utils.hook("received.command.part", permission="part", usage="[#channel]")
|
@Utils.hook("received.command.part")
|
||||||
def part(self, event):
|
def part(self, event):
|
||||||
"""
|
"""
|
||||||
Part from the current or given channel
|
:help: Part from the current or given channel
|
||||||
|
:usage: [channel]
|
||||||
|
:permission: part
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
target = event["args_split"][0]
|
target = event["args_split"][0]
|
||||||
|
@ -31,9 +35,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stderr"].write("No channel provided")
|
event["stderr"].write("No channel provided")
|
||||||
event["server"].send_part(target)
|
event["server"].send_part(target)
|
||||||
|
|
||||||
@Utils.hook("received.command.reconnect", permission="reconnect")
|
@Utils.hook("received.command.reconnect")
|
||||||
def reconnect(self, event):
|
def reconnect(self, event):
|
||||||
"""
|
"""
|
||||||
Reconnect to the current network
|
:help: Reconnect to the current network
|
||||||
|
:permission: reconnect
|
||||||
"""
|
"""
|
||||||
event["server"].send_quit("Reconnecting")
|
event["server"].send_quit("Reconnecting")
|
||||||
|
|
|
@ -51,32 +51,36 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write("Removed automode %s from '%s'" % (
|
event["stdout"].write("Removed automode %s from '%s'" % (
|
||||||
mode_name, target_user.nickname))
|
mode_name, target_user.nickname))
|
||||||
|
|
||||||
@Utils.hook("received.command.addop", require_mode="o", min_args=1,
|
@Utils.hook("received.command.addop", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<nickname>")
|
|
||||||
def add_op(self, event):
|
def add_op(self, event):
|
||||||
"""
|
"""
|
||||||
Add a user to the auto-mode list as an op
|
:help: Add a user to the auto-mode list as an op
|
||||||
|
:usage: <nickname>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
self._add_mode(event, "o", "op")
|
self._add_mode(event, "o", "op")
|
||||||
@Utils.hook("received.command.removeop", require_mode="o", min_args=1,
|
@Utils.hook("received.command.removeop", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<nickname>")
|
|
||||||
def remove_op(self, event):
|
def remove_op(self, event):
|
||||||
"""
|
"""
|
||||||
Remove a user from the auto-mode list as an op
|
:help: Remove a user from the auto-mode list as an op
|
||||||
|
:usage: <nickname>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
self._remove_mode(event, "o", "op")
|
self._remove_mode(event, "o", "op")
|
||||||
|
|
||||||
@Utils.hook("received.command.addvoice", require_mode="o", min_args=1,
|
@Utils.hook("received.command.addvoice", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<nickname>")
|
|
||||||
def add_voice(self, event):
|
def add_voice(self, event):
|
||||||
"""
|
"""
|
||||||
Add a user to the auto-mode list as a voice
|
:help: Add a user to the auto-mode list as a voice
|
||||||
|
:usage: <nickname>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
self._add_mode(event, "v", "voice")
|
self._add_mode(event, "v", "voice")
|
||||||
@Utils.hook("received.command.removevoice", require_mode="o", min_args=1,
|
@Utils.hook("received.command.removevoice", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<nickname>")
|
|
||||||
def remove_voice(self, event):
|
def remove_voice(self, event):
|
||||||
"""
|
"""
|
||||||
Remove a user from the auto-mode list as anvoice
|
:help: Remove a user from the auto-mode list as a voice
|
||||||
|
:usage: <nickname>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
self._remove_mode(event, "v", "voice")
|
self._remove_mode(event, "v", "voice")
|
||||||
|
|
|
@ -3,10 +3,11 @@ from src import ModuleManager, Utils
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "BTC"
|
_name = "BTC"
|
||||||
|
|
||||||
@Utils.hook("received.command.btc", usage="[currency]")
|
@Utils.hook("received.command.btc")
|
||||||
def btc(self, event):
|
def btc(self, event):
|
||||||
"""
|
"""
|
||||||
Get the exchange rate of bitcoins
|
:help: Get the exchange rate of bitcoins
|
||||||
|
:usage: [currency]
|
||||||
"""
|
"""
|
||||||
currency = (event["args"] or "USD").upper()
|
currency = (event["args"] or "USD").upper()
|
||||||
page = Utils.get_url("https://blockchain.info/ticker",
|
page = Utils.get_url("https://blockchain.info/ticker",
|
||||||
|
|
|
@ -36,10 +36,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Failed to load results")
|
event["stderr"].write("Failed to load results")
|
||||||
|
|
||||||
@Utils.hook("received.command.isbn", min_args=1, usage="<isbn>")
|
@Utils.hook("received.command.isbn", min_args=1)
|
||||||
def isbn(self, event):
|
def isbn(self, event):
|
||||||
"""
|
"""
|
||||||
Get book information from a provided ISBN
|
:help: Get book information from a provided ISBN
|
||||||
|
:usage: <isbn>
|
||||||
"""
|
"""
|
||||||
isbn = event["args_split"][0]
|
isbn = event["args_split"][0]
|
||||||
if len(isbn) == 10:
|
if len(isbn) == 10:
|
||||||
|
@ -47,9 +48,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
isbn = isbn.replace("-", "")
|
isbn = isbn.replace("-", "")
|
||||||
self.get_book("isbn:%s" % isbn, event)
|
self.get_book("isbn:%s" % isbn, event)
|
||||||
|
|
||||||
@Utils.hook("received.command.book", min_args=1, usage="<book title>")
|
@Utils.hook("received.command.book", min_args=1)
|
||||||
def book(self, event):
|
def book(self, event):
|
||||||
"""
|
"""
|
||||||
Get book information from a provided title
|
:help: Get book information from a provided title
|
||||||
|
:usage: <book title>
|
||||||
"""
|
"""
|
||||||
self.get_book(event["args"], event)
|
self.get_book(event["args"], event)
|
||||||
|
|
|
@ -33,11 +33,12 @@ 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,
|
@Utils.hook("received.command.kick|k", channel_only=True, min_args=1)
|
||||||
require_mode="o", usage="<nickname> [reason]", min_args=1)
|
|
||||||
def kick(self, event):
|
def kick(self, event):
|
||||||
"""
|
"""
|
||||||
Kick a user from the current channel
|
:help: Kick a user from the current channel
|
||||||
|
:usage: <nickname> [reason]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["args_split"][0]
|
target = event["args_split"][0]
|
||||||
reason = " ".join(event["args_split"][1:]) or None
|
reason = " ".join(event["args_split"][1:]) or None
|
||||||
|
@ -76,11 +77,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["target"].send_unban(target)
|
event["target"].send_unban(target)
|
||||||
return target
|
return target
|
||||||
|
|
||||||
@Utils.hook("received.command.ban", channel_only=True, min_args=1,
|
@Utils.hook("received.command.ban", channel_only=True, min_args=1)
|
||||||
require_mode="o", usage="<nickname/hostmask>")
|
|
||||||
def ban(self, event):
|
def ban(self, event):
|
||||||
"""
|
"""
|
||||||
Ban a user/hostmask from the current channel
|
:help: Ban a user/hostmask from the current channel
|
||||||
|
:usage: <nickname/hostmask>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
self._ban(event["server"], event["target"], True,
|
self._ban(event["server"], event["target"], True,
|
||||||
event["args_split"][0])
|
event["args_split"][0])
|
||||||
|
@ -101,17 +103,26 @@ 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|tban|tb", channel_only=True,
|
@Utils.hook("received.command.tempban|tb", channel_only=True, min_args=2)
|
||||||
min_args=2, require_mode="o", usage="<nickname/hostmask>")
|
|
||||||
def temp_ban(self, event):
|
def temp_ban(self, event):
|
||||||
|
"""
|
||||||
|
:help: Temporarily ban someone from the current channel
|
||||||
|
:usage: <nickname/hostmask>
|
||||||
|
:require_mode: o
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
self._temp_ban(event, True)
|
self._temp_ban(event, True)
|
||||||
except InvalidTimeoutException as e:
|
except InvalidTimeoutException as e:
|
||||||
event["stderr"].set_prefix("Tempban")
|
event["stderr"].set_prefix("Tempban")
|
||||||
event["stderr"].write(str(e))
|
event["stderr"].write(str(e))
|
||||||
@Utils.hook("received.command.tempkickban|tkban|tkb", channel_only=True,
|
@Utils.hook("received.command.tempkickban|tkb", channel_only=True,
|
||||||
min_args=2, require_mode="o", usage="<nickname/hostmask>")
|
min_args=2)
|
||||||
def temp_kick_ban(self, event):
|
def temp_kick_ban(self, event):
|
||||||
|
"""
|
||||||
|
:help: Temporarily kick and ban someone from the current channel
|
||||||
|
:usage: <nickname>
|
||||||
|
:require_mode: o
|
||||||
|
"""
|
||||||
reason = " ".join(event["args_split"][2:]) or None
|
reason = " ".join(event["args_split"][2:]) or None
|
||||||
event["stderr"].set_prefix("TKB")
|
event["stderr"].set_prefix("TKB")
|
||||||
try:
|
try:
|
||||||
|
@ -123,20 +134,22 @@ class Module(ModuleManager.BaseModule):
|
||||||
except UserNotFoundException as e:
|
except UserNotFoundException as e:
|
||||||
event["stderr"].write(str(e))
|
event["stderr"].write(str(e))
|
||||||
|
|
||||||
@Utils.hook("received.command.unban", channel_only=True, min_args=1,
|
@Utils.hook("received.command.unban", channel_only=True, min_args=1)
|
||||||
require_mode="o", usage="<nickname/hostmask>")
|
|
||||||
def unban(self, event):
|
def unban(self, event):
|
||||||
"""
|
"""
|
||||||
Unban a user/hostmask from the current channel
|
:help: Unban a user/hostmask from the current channel
|
||||||
|
:usage: <nickname/hostmask>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
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,
|
@Utils.hook("received.command.kickban|kb", channel_only=True, min_args=1)
|
||||||
require_mode="o", usage="<nickname> [reason]", min_args=1)
|
|
||||||
def kickban(self, event):
|
def kickban(self, event):
|
||||||
"""
|
"""
|
||||||
Kick and ban a user from the current channel
|
:help: Kick and ban a user from the current channel
|
||||||
|
:usage: <nickname> [reason]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["args_split"][0]
|
target = event["args_split"][0]
|
||||||
reason = " ".join(event["args_split"][1:]) or None
|
reason = " ".join(event["args_split"][1:]) or None
|
||||||
|
@ -147,56 +160,62 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stderr"].set_prefix("Kickban")
|
event["stderr"].set_prefix("Kickban")
|
||||||
event["stderr"].write(str(e))
|
event["stderr"].write(str(e))
|
||||||
|
|
||||||
@Utils.hook("received.command.op", channel_only=True,
|
@Utils.hook("received.command.op", channel_only=True)
|
||||||
require_mode="o", usage="[nickname]")
|
|
||||||
def op(self, event):
|
def op(self, event):
|
||||||
"""
|
"""
|
||||||
Op a user in the current channel
|
:help: Op a user in the current channel
|
||||||
|
:usage: [nickname]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["user"].nickname if not event["args_split"] else event[
|
target = event["user"].nickname if not event["args_split"] else event[
|
||||||
"args_split"][0]
|
"args_split"][0]
|
||||||
event["target"].send_mode("+o", target)
|
event["target"].send_mode("+o", target)
|
||||||
@Utils.hook("received.command.deop", channel_only=True,
|
@Utils.hook("received.command.deop", channel_only=True)
|
||||||
require_mode="o", usage="[nickname]")
|
|
||||||
def deop(self, event):
|
def deop(self, event):
|
||||||
"""
|
"""
|
||||||
Remove op from a user in the current channel
|
:help: Remove op from a user in the current channel
|
||||||
|
:usage: [nickname]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["user"].nickname if not event["args_split"] else event[
|
target = event["user"].nickname if not event["args_split"] else event[
|
||||||
"args_split"][0]
|
"args_split"][0]
|
||||||
event["target"].send_mode("-o", target)
|
event["target"].send_mode("-o", target)
|
||||||
|
|
||||||
@Utils.hook("received.command.voice", channel_only=True,
|
@Utils.hook("received.command.voice", channel_only=True)
|
||||||
require_mode="o", usage="[nickname]")
|
|
||||||
def voice(self, event):
|
def voice(self, event):
|
||||||
"""
|
"""
|
||||||
Voice a user in the current channel
|
:help: Voice a user in the current channel
|
||||||
|
:usage: [nickname]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["user"].nickname if not event["args_split"] else event[
|
target = event["user"].nickname if not event["args_split"] else event[
|
||||||
"args_split"][0]
|
"args_split"][0]
|
||||||
event["target"].send_mode("+v", target)
|
event["target"].send_mode("+v", target)
|
||||||
@Utils.hook("received.command.devoice", channel_only=True,
|
@Utils.hook("received.command.devoice", channel_only=True)
|
||||||
require_mode="o", usage="[nickname]")
|
|
||||||
def devoice(self, event):
|
def devoice(self, event):
|
||||||
"""
|
"""
|
||||||
Remove voice from a user in the current channel
|
:help: Remove voice from a user in the current channel
|
||||||
|
:usage: [nickname]
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
target = event["user"].nickname if not event["args_split"] else event[
|
target = event["user"].nickname if not event["args_split"] else event[
|
||||||
"args_split"][0]
|
"args_split"][0]
|
||||||
event["target"].send_mode("-v", target)
|
event["target"].send_mode("-v", target)
|
||||||
|
|
||||||
@Utils.hook("received.command.topic", min_args=1, require_mode="o",
|
@Utils.hook("received.command.topic", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<topic>")
|
|
||||||
def topic(self, event):
|
def topic(self, event):
|
||||||
"""
|
"""
|
||||||
Set the topic in the current channel
|
:help: Set the topic in the current channel
|
||||||
|
:usage: <topic>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
event["target"].send_topic(event["args"])
|
event["target"].send_topic(event["args"])
|
||||||
@Utils.hook("received.command.tappend", min_args=1, require_mode="o",
|
@Utils.hook("received.command.tappend", min_args=1, channel_only=True)
|
||||||
channel_only=True, usage="<topic>")
|
|
||||||
def tappend(self, event):
|
def tappend(self, event):
|
||||||
"""
|
"""
|
||||||
Append to the topic in the current channel
|
:help: Append to the topic in the current channel
|
||||||
|
:usage: <topic>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
event["target"].send_topic(event["target"].topic + event["args"])
|
event["target"].send_topic(event["target"].topic + event["args"])
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("preprocess.command")
|
@Utils.hook("preprocess.command")
|
||||||
def preprocess_command(self, event):
|
def preprocess_command(self, event):
|
||||||
if event["is_channel"] and event["hook"].kwargs.get(
|
require_mode = event["hook"].get_kwarg("require_mode")
|
||||||
"require_mode"):
|
if event["is_channel"] and require_mode:
|
||||||
required_mode = event["hook"].kwargs.get("require_mode")[0]
|
|
||||||
if not event["target"].mode_or_above(event["user"],
|
if not event["target"].mode_or_above(event["user"],
|
||||||
required_mode):
|
required_mode):
|
||||||
return "You do not have permission to do this"
|
return "You do not have permission to do this"
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.coins")
|
@Utils.hook("received.command.coins")
|
||||||
def coins(self, event):
|
def coins(self, event):
|
||||||
"""
|
"""
|
||||||
Show how many coins you have
|
:help: Show how many coins you have
|
||||||
"""
|
"""
|
||||||
if event["args_split"]:
|
if event["args_split"]:
|
||||||
target = event["server"].get_user(event["args_split"][0])
|
target = event["server"].get_user(event["args_split"][0])
|
||||||
|
@ -49,11 +49,12 @@ class Module(object):
|
||||||
event["stdout"].write("%s has %s coin%s" % (target.nickname,
|
event["stdout"].write("%s has %s coin%s" % (target.nickname,
|
||||||
"{0:.2f}".format(coins), "" if coins == 1 else "s"))
|
"{0:.2f}".format(coins), "" if coins == 1 else "s"))
|
||||||
|
|
||||||
@Utils.hook("received.command.resetcoins", permission="resetcoins",
|
@Utils.hook("received.command.resetcoins", min_args=1)
|
||||||
min_args=1, usage="<target>")
|
|
||||||
def reset_coins(self, event):
|
def reset_coins(self, event):
|
||||||
"""
|
"""
|
||||||
Reset a user's coins to 0
|
:help: Reset a user's coins to 0
|
||||||
|
:usage: <target>
|
||||||
|
:permission: resetcoins
|
||||||
"""
|
"""
|
||||||
target = event["server"].get_user(event["args_split"][0])
|
target = event["server"].get_user(event["args_split"][0])
|
||||||
coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
||||||
|
@ -64,11 +65,12 @@ class Module(object):
|
||||||
target.del_setting("coins")
|
target.del_setting("coins")
|
||||||
event["stdout"].write("Reset coins for %s" % target.nickname)
|
event["stdout"].write("Reset coins for %s" % target.nickname)
|
||||||
|
|
||||||
@Utils.hook("received.command.givecoins", min_args=1,
|
@Utils.hook("received.command.givecoins", min_args=1)
|
||||||
usage="<nickname> <coins>", permission="givecoins")
|
|
||||||
def give_coins(self, event):
|
def give_coins(self, event):
|
||||||
"""
|
"""
|
||||||
Give coins to a user
|
:help: Give coins to a user
|
||||||
|
:usage: <nickname> <coins>
|
||||||
|
:permission: givecoins
|
||||||
"""
|
"""
|
||||||
target = event["server"].get_user(event["args_split"][0])
|
target = event["server"].get_user(event["args_split"][0])
|
||||||
coins = event["args_split"][1]
|
coins = event["args_split"][1]
|
||||||
|
@ -86,7 +88,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.richest")
|
@Utils.hook("received.command.richest")
|
||||||
def richest(self, event):
|
def richest(self, event):
|
||||||
"""
|
"""
|
||||||
Show the top 10 richest users
|
:help: Show the top 10 richest users
|
||||||
"""
|
"""
|
||||||
all_coins = event["server"].get_all_user_settings("coins", [])
|
all_coins = event["server"].get_all_user_settings("coins", [])
|
||||||
all_coins = list(filter(lambda coin: decimal.Decimal(coin[1]),
|
all_coins = list(filter(lambda coin: decimal.Decimal(coin[1]),
|
||||||
|
@ -107,7 +109,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.redeemcoins")
|
@Utils.hook("received.command.redeemcoins")
|
||||||
def redeem_coins(self, event):
|
def redeem_coins(self, event):
|
||||||
"""
|
"""
|
||||||
Redeem your free coins
|
:help: Redeem your free coins
|
||||||
"""
|
"""
|
||||||
user_coins = decimal.Decimal(event["user"].get_setting(
|
user_coins = decimal.Decimal(event["user"].get_setting(
|
||||||
"coins", "0.0"))
|
"coins", "0.0"))
|
||||||
|
@ -132,11 +134,11 @@ class Module(object):
|
||||||
event["stderr"].write(
|
event["stderr"].write(
|
||||||
"You can only redeem coins when you have none")
|
"You can only redeem coins when you have none")
|
||||||
|
|
||||||
@Utils.hook("received.command.flip", usage="heads|tails <coin amount>",
|
@Utils.hook("received.command.flip", min_args=2, authenticated=True)
|
||||||
min_args=2, authenticated=True)
|
|
||||||
def flip(self, event):
|
def flip(self, event):
|
||||||
"""
|
"""
|
||||||
Bet on a coin flip
|
:help: Bet on a coin flip
|
||||||
|
:usage: heads|tails <coin amount>
|
||||||
"""
|
"""
|
||||||
side_name = event["args_split"][0].lower()
|
side_name = event["args_split"][0].lower()
|
||||||
coin_bet = event["args_split"][1].lower()
|
coin_bet = event["args_split"][1].lower()
|
||||||
|
@ -176,11 +178,11 @@ class Module(object):
|
||||||
event["user"].nickname, side_name, coin_bet_str,
|
event["user"].nickname, side_name, coin_bet_str,
|
||||||
"" if coin_bet == 1 else "s"))
|
"" if coin_bet == 1 else "s"))
|
||||||
|
|
||||||
@Utils.hook("received.command.sendcoins", min_args=2,
|
@Utils.hook("received.command.sendcoins", min_args=2, authenticated=True)
|
||||||
usage="<nickname> <amount>", authenticated=True)
|
|
||||||
def send(self, event):
|
def send(self, event):
|
||||||
"""
|
"""
|
||||||
Send coins to another user
|
:help: Send coins to another user
|
||||||
|
:usage: <nickname> <amount>
|
||||||
"""
|
"""
|
||||||
if event["user"].get_id() == event["server"].get_user(event[
|
if event["user"].get_id() == event["server"].get_user(event[
|
||||||
"args_split"][0]).get_id():
|
"args_split"][0]).get_id():
|
||||||
|
@ -245,11 +247,11 @@ class Module(object):
|
||||||
str(coins))
|
str(coins))
|
||||||
event["timer"].redo()
|
event["timer"].redo()
|
||||||
|
|
||||||
@Utils.hook("received.command.roulette", min_args=2,
|
@Utils.hook("received.command.roulette", min_args=2, authenticated=True)
|
||||||
usage="<type> <amount>", authenticated=True)
|
|
||||||
def roulette(self, event):
|
def roulette(self, event):
|
||||||
"""
|
"""
|
||||||
Spin a roulette wheel
|
:help: Spin a roulette wheel
|
||||||
|
:usage: <type> <amount>
|
||||||
"""
|
"""
|
||||||
bets = event["args_split"][0].lower().split(",")
|
bets = event["args_split"][0].lower().split(",")
|
||||||
if "0" in bets:
|
if "0" in bets:
|
||||||
|
|
|
@ -151,12 +151,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
self.message(event, command)
|
self.message(event, command)
|
||||||
|
|
||||||
def _get_help(self, hook):
|
def _get_help(self, hook):
|
||||||
return hook.kwargs.get("help", None) or hook.function.__doc__
|
return hook.get_kwarg("help", None) or hook.docstring.description
|
||||||
|
def _get_usage(self, hook):
|
||||||
|
return hook.get_kwarg("usage", None)
|
||||||
|
|
||||||
@Utils.hook("received.command.help", usage="<command>")
|
@Utils.hook("received.command.help")
|
||||||
def help(self, event):
|
def help(self, event):
|
||||||
"""
|
"""
|
||||||
Show help for a given command
|
:help: Show help for a given command
|
||||||
|
:usage: [command]
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
command = event["args_split"][0].lower()
|
command = event["args_split"][0].lower()
|
||||||
|
@ -166,11 +169,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
help = self._get_help(hooks[0])
|
help = self._get_help(hooks[0])
|
||||||
|
|
||||||
if help:
|
if help:
|
||||||
help = [line.strip() for line in help.split("\n")]
|
|
||||||
help = [line.strip() for line in help]
|
|
||||||
help = filter(None, help)
|
|
||||||
help = " ".join(help)
|
|
||||||
|
|
||||||
event["stdout"].write("%s: %s" % (command, help))
|
event["stdout"].write("%s: %s" % (command, help))
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No help available for %s" % command)
|
event["stderr"].write("No help available for %s" % command)
|
||||||
|
@ -186,10 +184,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
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))
|
||||||
|
|
||||||
@Utils.hook("received.command.usage", min_args=1, usage="<command>")
|
@Utils.hook("received.command.usage", min_args=1)
|
||||||
def usage(self, event):
|
def usage(self, event):
|
||||||
"""
|
"""
|
||||||
Show the usage for a given command
|
:help: Show the usage for a given command
|
||||||
|
:usage: <command>
|
||||||
"""
|
"""
|
||||||
command_prefix = ""
|
command_prefix = ""
|
||||||
if event["is_channel"]:
|
if event["is_channel"]:
|
||||||
|
@ -200,9 +199,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
if command in self.events.on("received").on(
|
if command in self.events.on("received").on(
|
||||||
"command").get_children():
|
"command").get_children():
|
||||||
hooks = self.events.on("received.command").on(command).get_hooks()
|
hooks = self.events.on("received.command").on(command).get_hooks()
|
||||||
if hooks and "usage" in hooks[0].kwargs:
|
usage = self._get_usage(hooks[0])
|
||||||
|
|
||||||
|
if usage:
|
||||||
event["stdout"].write("Usage: %s%s %s" % (command_prefix,
|
event["stdout"].write("Usage: %s%s %s" % (command_prefix,
|
||||||
command, hooks[0].kwargs["usage"]))
|
command, usage))
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No usage help available for %s" % command)
|
event["stderr"].write("No usage help available for %s" % command)
|
||||||
else:
|
else:
|
||||||
|
@ -211,16 +212,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.more", skip_out=True)
|
@Utils.hook("received.command.more", skip_out=True)
|
||||||
def more(self, event):
|
def more(self, event):
|
||||||
"""
|
"""
|
||||||
Show more output from the last command
|
:help: Show more output from the last command
|
||||||
"""
|
"""
|
||||||
if event["target"].last_stdout and event["target"].last_stdout.has_text():
|
if event["target"].last_stdout and event["target"].last_stdout.has_text():
|
||||||
event["target"].last_stdout.send()
|
event["target"].last_stdout.send()
|
||||||
|
|
||||||
@Utils.hook("received.command.ignore", min_args=1, usage="<nickname>",
|
@Utils.hook("received.command.ignore", min_args=1)
|
||||||
permission="ignore")
|
|
||||||
def ignore(self, event):
|
def ignore(self, event):
|
||||||
"""
|
"""
|
||||||
Ignore commands from a given user
|
:help: Ignore commands from a given user
|
||||||
|
:usage: <nickname>
|
||||||
|
:permission: ignore
|
||||||
"""
|
"""
|
||||||
user = event["server"].get_user(event["args_split"][0])
|
user = event["server"].get_user(event["args_split"][0])
|
||||||
if user.get_setting("ignore", False):
|
if user.get_setting("ignore", False):
|
||||||
|
@ -230,11 +232,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
user.set_setting("ignore", True)
|
user.set_setting("ignore", True)
|
||||||
event["stdout"].write("Now ignoring '%s'" % user.nickname)
|
event["stdout"].write("Now ignoring '%s'" % user.nickname)
|
||||||
|
|
||||||
@Utils.hook("received.command.unignore", min_args=1, usage="<nickname>",
|
@Utils.hook("received.command.unignore", min_args=1)
|
||||||
permission="unignore")
|
|
||||||
def unignore(self, event):
|
def unignore(self, event):
|
||||||
"""
|
"""
|
||||||
Unignore commands from a given user
|
:help: Unignore commands from a given user
|
||||||
|
:usage: <nickname>
|
||||||
|
:permission: unignore
|
||||||
"""
|
"""
|
||||||
user = event["server"].get_user(event["args_split"][0])
|
user = event["server"].get_user(event["args_split"][0])
|
||||||
if not user.get_setting("ignore", False):
|
if not user.get_setting("ignore", False):
|
||||||
|
|
|
@ -19,10 +19,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
@Utils.hook("received.command.define", usage="<phrase>")
|
@Utils.hook("received.command.define")
|
||||||
def define(self, event):
|
def define(self, event):
|
||||||
"""
|
"""
|
||||||
Define a provided term
|
:help: Define a provided term
|
||||||
|
:usage: <phrase>
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
word = event["args"]
|
word = event["args"]
|
||||||
|
@ -42,7 +43,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.randomword")
|
@Utils.hook("received.command.randomword")
|
||||||
def random_word(self, event):
|
def random_word(self, event):
|
||||||
"""
|
"""
|
||||||
Define a random word
|
:help: Define a random word
|
||||||
"""
|
"""
|
||||||
if not self._last_called or (time.time()-self._last_called >=
|
if not self._last_called or (time.time()-self._last_called >=
|
||||||
RANDOM_DELAY_SECONDS):
|
RANDOM_DELAY_SECONDS):
|
||||||
|
|
|
@ -4,10 +4,11 @@ from src import ModuleManager, Utils
|
||||||
ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20"
|
ERROR_FORMAT = "Incorrect format! Format must be [number]d[number], e.g. 1d20"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.roll", min_args=1, usage="[1-5]d[1-20]")
|
@Utils.hook("received.command.roll", min_args=1)
|
||||||
def roll_dice(self, event):
|
def roll_dice(self, event):
|
||||||
"""
|
"""
|
||||||
Roll some dice, DND style!
|
:help: Roll some dice, DND style!
|
||||||
|
:usage: [1-5]d[1-20]
|
||||||
"""
|
"""
|
||||||
raw_input = event["args_split"][0]
|
raw_input = event["args_split"][0]
|
||||||
roll = raw_input.split("d")
|
roll = raw_input.split("d")
|
||||||
|
|
|
@ -4,10 +4,11 @@ from src import ModuleManager, Utils
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "DNS"
|
_name = "DNS"
|
||||||
|
|
||||||
@Utils.hook("received.command.dns", min_args=1, usage="<hostname>")
|
@Utils.hook("received.command.dns", min_args=1)
|
||||||
def dns(self, event):
|
def dns(self, event):
|
||||||
"""
|
"""
|
||||||
Get all addresses for a given hostname (IPv4/IPv6)
|
:help: Get all addresses for a given hostname (IPv4/IPv6)
|
||||||
|
:usage: <hostname>
|
||||||
"""
|
"""
|
||||||
hostname = event["args_split"][0]
|
hostname = event["args_split"][0]
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -119,7 +119,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.decoy")
|
@Utils.hook("received.command.decoy")
|
||||||
def duck_decoy(self, event):
|
def duck_decoy(self, event):
|
||||||
"""
|
"""
|
||||||
Prepare a decoy duck
|
:help: Prepare a decoy duck
|
||||||
"""
|
"""
|
||||||
channel = event["target"]
|
channel = event["target"]
|
||||||
if self.is_duck_channel(channel) == False:
|
if self.is_duck_channel(channel) == False:
|
||||||
|
@ -225,7 +225,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.bef")
|
@Utils.hook("received.command.bef")
|
||||||
def befriend(self, event):
|
def befriend(self, event):
|
||||||
"""
|
"""
|
||||||
Befriend a duck
|
:help: Befriend a duck
|
||||||
"""
|
"""
|
||||||
channel = event["target"]
|
channel = event["target"]
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
|
@ -263,7 +263,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.bang")
|
@Utils.hook("received.command.bang")
|
||||||
def shoot(self, event):
|
def shoot(self, event):
|
||||||
"""
|
"""
|
||||||
Shoot a duck
|
:help: Shoot a duck
|
||||||
"""
|
"""
|
||||||
channel = event["target"]
|
channel = event["target"]
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
|
@ -302,7 +302,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.duckstats")
|
@Utils.hook("received.command.duckstats")
|
||||||
def duck_stats(self, event):
|
def duck_stats(self, event):
|
||||||
"""
|
"""
|
||||||
Show your duck stats
|
:help: Show your duck stats
|
||||||
"""
|
"""
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
channel = event["target"].name
|
channel = event["target"].name
|
||||||
|
@ -347,7 +347,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.killers")
|
@Utils.hook("received.command.killers")
|
||||||
def duck_enemies(self, event):
|
def duck_enemies(self, event):
|
||||||
"""
|
"""
|
||||||
Show the top duck shooters
|
:help: Show the top duck shooters
|
||||||
"""
|
"""
|
||||||
the_enemy = event["server"].find_all_user_channel_settings("ducks-shot")
|
the_enemy = event["server"].find_all_user_channel_settings("ducks-shot")
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ class Module(object):
|
||||||
@Utils.hook("received.command.friends")
|
@Utils.hook("received.command.friends")
|
||||||
def duck_friends(self, event):
|
def duck_friends(self, event):
|
||||||
"""
|
"""
|
||||||
Show the top duck friends
|
:help: Show the top duck friends
|
||||||
"""
|
"""
|
||||||
friends = event["server"].find_all_user_channel_settings(
|
friends = event["server"].find_all_user_channel_settings(
|
||||||
"ducks-befriended")
|
"ducks-befriended")
|
||||||
|
|
|
@ -4,10 +4,11 @@ from src import ModuleManager, Utils
|
||||||
EVAL_URL = "https://eval.appspot.com/eval"
|
EVAL_URL = "https://eval.appspot.com/eval"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.eval", min_args=1, usage="<statement>")
|
@Utils.hook("received.command.eval", min_args=1)
|
||||||
def eval(self, event):
|
def eval(self, event):
|
||||||
"""
|
"""
|
||||||
Evaluate a python statement
|
:help: Evaluate a python statement
|
||||||
|
:usage: <statement>
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
code, page = Utils.get_url(EVAL_URL, get_params={
|
code, page = Utils.get_url(EVAL_URL, get_params={
|
||||||
|
|
|
@ -5,10 +5,11 @@ URL_GEOIP = "http://ip-api.com/json/%s"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "GeoIP"
|
_name = "GeoIP"
|
||||||
|
|
||||||
@Utils.hook("received.command.geoip", min_args=1, usage="<IP>")
|
@Utils.hook("received.command.geoip", min_args=1)
|
||||||
def geoip(self, event):
|
def geoip(self, event):
|
||||||
"""
|
"""
|
||||||
Get geoip data on a given IPv4/IPv6 address
|
:help: Get geoip data on a given IPv4/IPv6 address
|
||||||
|
:usage: <IP>
|
||||||
"""
|
"""
|
||||||
page = Utils.get_url(URL_GEOIP % event["args_split"][0],
|
page = Utils.get_url(URL_GEOIP % event["args_split"][0],
|
||||||
json=True)
|
json=True)
|
||||||
|
|
|
@ -8,10 +8,11 @@ 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", usage="[search term]")
|
@Utils.hook("received.command.google|g")
|
||||||
def google(self, event):
|
def google(self, event):
|
||||||
"""
|
"""
|
||||||
Get first Google result for a given search term
|
:help: Get first Google result for a given search term
|
||||||
|
:usage: [search term]
|
||||||
"""
|
"""
|
||||||
phrase = event["args"] or event["target"].buffer.get()
|
phrase = event["args"] or event["target"].buffer.get()
|
||||||
if phrase:
|
if phrase:
|
||||||
|
|
|
@ -2,10 +2,11 @@ import hashlib
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.hash", min_args=2, usage="<algo> <string>")
|
@Utils.hook("received.command.hash", min_args=2)
|
||||||
def hash(self, event):
|
def hash(self, event):
|
||||||
"""
|
"""
|
||||||
Hash a given string with a given algorithm
|
:help: Hash a given string with a given algorithm
|
||||||
|
:usage: <algo> <string>
|
||||||
"""
|
"""
|
||||||
algorithm = event["args_split"][0].lower()
|
algorithm = event["args_split"][0].lower()
|
||||||
if algorithm in hashlib.algorithms_available:
|
if algorithm in hashlib.algorithms_available:
|
||||||
|
|
|
@ -4,12 +4,12 @@ URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
|
||||||
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
|
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.beenpwned", usage="<username/email>",
|
@Utils.hook("received.command.beenpwned", min_args=1)
|
||||||
min_args=1)
|
|
||||||
def beenpwned(self, event):
|
def beenpwned(self, event):
|
||||||
"""
|
"""
|
||||||
Find out if a username, email or similar has appeared in any
|
:help: Find out if a username, email or similar has appeared in any
|
||||||
hacked databases
|
hacked databases
|
||||||
|
:usage: <username/email>
|
||||||
"""
|
"""
|
||||||
page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True,
|
page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True,
|
||||||
code=True)
|
code=True)
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.myid")
|
@Utils.hook("received.command.myid")
|
||||||
def my_id(self, event):
|
def my_id(self, event):
|
||||||
"""
|
"""
|
||||||
Show your user ID
|
:help: Show your user ID
|
||||||
"""
|
"""
|
||||||
event["stdout"].write("%s: %d" % (event["user"].nickname,
|
event["stdout"].write("%s: %d" % (event["user"].nickname,
|
||||||
event["user"].get_id()))
|
event["user"].get_id()))
|
||||||
|
@ -14,7 +14,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.channelid", channel_only=True)
|
@Utils.hook("received.command.channelid", channel_only=True)
|
||||||
def channel_id(self, event):
|
def channel_id(self, event):
|
||||||
"""
|
"""
|
||||||
Show the current channel's ID
|
:help: Show the current channel's ID
|
||||||
"""
|
"""
|
||||||
event["stdout"].write("%s: %d" % (event["target"].name,
|
event["stdout"].write("%s: %d" % (event["target"].name,
|
||||||
event["target"].id))
|
event["target"].id))
|
||||||
|
|
|
@ -9,10 +9,11 @@ URL_IMDBTITLE = "http://imdb.com/title/%s"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "IMDb"
|
_name = "IMDb"
|
||||||
|
|
||||||
@Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>")
|
@Utils.hook("received.command.imdb", min_args=1)
|
||||||
def imdb(self, event):
|
def imdb(self, event):
|
||||||
"""
|
"""
|
||||||
Search for a given title on IMDb
|
:help: Search for a given title on IMDb
|
||||||
|
:usage: <movie/tv title>
|
||||||
"""
|
"""
|
||||||
page = Utils.get_url(URL_OMDB, get_params={
|
page = Utils.get_url(URL_OMDB, get_params={
|
||||||
"t": event["args"],
|
"t": event["args"],
|
||||||
|
|
|
@ -5,10 +5,11 @@ SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
||||||
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.in", min_args=2, usage="<time> <message>")
|
@Utils.hook("received.command.in", min_args=2)
|
||||||
def in_command(self, event):
|
def in_command(self, event):
|
||||||
"""
|
"""
|
||||||
Set a reminder
|
:help: Set a reminder
|
||||||
|
:usage: <time> <message>
|
||||||
"""
|
"""
|
||||||
seconds = Utils.from_pretty_time(event["args_split"][0])
|
seconds = Utils.from_pretty_time(event["args_split"][0])
|
||||||
message = " ".join(event["args_split"][1:])
|
message = " ".join(event["args_split"][1:])
|
||||||
|
|
|
@ -18,10 +18,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
if data and data["shorturl"]:
|
if data and data["shorturl"]:
|
||||||
return data["shorturl"]
|
return data["shorturl"]
|
||||||
|
|
||||||
@Utils.hook("received.command.shorten", min_args=1, usage="<url>")
|
@Utils.hook("received.command.shorten", min_args=1)
|
||||||
def shorten(self, event):
|
def shorten(self, event):
|
||||||
"""
|
"""
|
||||||
Shorten a given URL using the is.gd service
|
:help: Shorten a given URL using the is.gd service
|
||||||
|
:usage: <url>
|
||||||
"""
|
"""
|
||||||
link = self.events.on("get.shortlink").call_for_result(
|
link = self.events.on("get.shortlink").call_for_result(
|
||||||
url=event["args"])
|
url=event["args"])
|
||||||
|
|
|
@ -48,10 +48,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
target=event["channel"],
|
target=event["channel"],
|
||||||
message="Try again in a couple of seconds")
|
message="Try again in a couple of seconds")
|
||||||
|
|
||||||
@Utils.hook("received.command.karma", usage="[target]")
|
@Utils.hook("received.command.karma")
|
||||||
def karma(self, event):
|
def karma(self, event):
|
||||||
"""
|
"""
|
||||||
Get your or someone else's karma
|
:help: Get your or someone else's karma
|
||||||
|
:usage: [target]
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
target = event["args"]
|
target = event["args"]
|
||||||
|
@ -60,11 +61,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
karma = event["server"].get_setting("karma-%s" % target, 0)
|
karma = event["server"].get_setting("karma-%s" % target, 0)
|
||||||
event["stdout"].write("%s has %s karma" % (target, karma))
|
event["stdout"].write("%s has %s karma" % (target, karma))
|
||||||
|
|
||||||
@Utils.hook("received.command.resetkarma", permission="resetkarma",
|
@Utils.hook("received.command.resetkarma", min_args=1)
|
||||||
min_args=1, usage="<target>")
|
|
||||||
def reset_karma(self, event):
|
def reset_karma(self, event):
|
||||||
"""
|
"""
|
||||||
Reset a specified karma to 0
|
:help: Reset a specified karma to 0
|
||||||
|
:usage: <target>
|
||||||
|
:permission: resetkarme
|
||||||
"""
|
"""
|
||||||
setting = "karma-%s" % event["args_split"][0]
|
setting = "karma-%s" % event["args_split"][0]
|
||||||
karma = event["server"].get_setting(setting, 0)
|
karma = event["server"].get_setting(setting, 0)
|
||||||
|
|
|
@ -9,10 +9,11 @@ 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", usage="[username]")
|
@Utils.hook("received.command.np|listening|nowplaying")
|
||||||
def np(self, event):
|
def np(self, event):
|
||||||
"""
|
"""
|
||||||
Get the last listened to track from a user
|
:help: Get the last listened to track from a user
|
||||||
|
:usage: [username]
|
||||||
"""
|
"""
|
||||||
if event["args_split"]:
|
if event["args_split"]:
|
||||||
lastfm_username = event["args_split"][0]
|
lastfm_username = event["args_split"][0]
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.loadmodule", min_args=1,
|
@Utils.hook("received.command.loadmodule", min_args=1)
|
||||||
permission="load-module", usage="<module-name>")
|
|
||||||
def load(self, event):
|
def load(self, event):
|
||||||
"""
|
"""
|
||||||
Load a module
|
:help: Load a module
|
||||||
|
:usage: <module name>
|
||||||
|
:permission: load-module
|
||||||
"""
|
"""
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
if name in self.bot.modules.modules:
|
if name in self.bot.modules.modules:
|
||||||
|
@ -14,11 +15,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
self.bot.modules.load_module(self.bot, name)
|
self.bot.modules.load_module(self.bot, name)
|
||||||
event["stdout"].write("Loaded '%s'" % name)
|
event["stdout"].write("Loaded '%s'" % name)
|
||||||
|
|
||||||
@Utils.hook("received.command.unloadmodule", min_args=1,
|
@Utils.hook("received.command.unloadmodule", min_args=1)
|
||||||
permission="unload-module", usage="<module-name>")
|
|
||||||
def unload(self, event):
|
def unload(self, event):
|
||||||
"""
|
"""
|
||||||
Unload a module
|
:help: Unload a module
|
||||||
|
:usage: <module name>
|
||||||
|
:permission: unload-module
|
||||||
"""
|
"""
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
if not name in self.bot.modules.modules:
|
if not name in self.bot.modules.modules:
|
||||||
|
@ -31,11 +33,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
self.bot.modules.unload_module(name)
|
self.bot.modules.unload_module(name)
|
||||||
self.bot.modules.load_module(self.bot, name)
|
self.bot.modules.load_module(self.bot, name)
|
||||||
|
|
||||||
@Utils.hook("received.command.reloadmodule", min_args=1,
|
@Utils.hook("received.command.reloadmodule", min_args=1)
|
||||||
permission="reload-module", usage="<module-name>")
|
|
||||||
def reload(self, event):
|
def reload(self, event):
|
||||||
"""
|
"""
|
||||||
Reload a module
|
:help: Reload a module
|
||||||
|
:usage: <module name>
|
||||||
|
:permission: reload-module
|
||||||
"""
|
"""
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
try:
|
try:
|
||||||
|
@ -53,10 +56,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
return
|
return
|
||||||
event["stdout"].write("Reloaded '%s'" % name)
|
event["stdout"].write("Reloaded '%s'" % name)
|
||||||
|
|
||||||
@Utils.hook("received.command.reloadallmodules", permission="reload-module")
|
@Utils.hook("received.command.reloadallmodules")
|
||||||
def reload_all(self, event):
|
def reload_all(self, event):
|
||||||
"""
|
"""
|
||||||
Reload all modules
|
:help: Reload all modules
|
||||||
|
:permission: reload-all-modules
|
||||||
"""
|
"""
|
||||||
reloaded = []
|
reloaded = []
|
||||||
failed = []
|
failed = []
|
||||||
|
@ -78,11 +82,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stdout"].write("Reloaded %d modules" % len(reloaded))
|
event["stdout"].write("Reloaded %d modules" % len(reloaded))
|
||||||
|
|
||||||
@Utils.hook("received.command.enablemodule", min_args=1,
|
@Utils.hook("received.command.enablemodule", min_args=1)
|
||||||
permission="enable-module", usage="<module-name>")
|
|
||||||
def enable(self, event):
|
def enable(self, event):
|
||||||
"""
|
"""
|
||||||
Remove a module from the module blacklist
|
:help: Remove a module from the module blacklist
|
||||||
|
:usage: <module name>
|
||||||
|
:permission: enable-module
|
||||||
"""
|
"""
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
blacklist = self.bot.get_setting("module-blacklist", [])
|
blacklist = self.bot.get_setting("module-blacklist", [])
|
||||||
|
@ -94,11 +99,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write("Module '%s' has been enabled and can now "
|
event["stdout"].write("Module '%s' has been enabled and can now "
|
||||||
"be loaded" % name)
|
"be loaded" % name)
|
||||||
|
|
||||||
@Utils.hook("received.command.disablemodule", min_args=1,
|
@Utils.hook("received.command.disablemodule", min_args=1)
|
||||||
permission="disable-module", usage="<module-name>")
|
|
||||||
def disable(self, event):
|
def disable(self, event):
|
||||||
"""
|
"""
|
||||||
Add a module to the module blacklist
|
:help: Add a module to the module blacklist
|
||||||
|
:usage: <module name>
|
||||||
|
:permission: disable-module
|
||||||
"""
|
"""
|
||||||
name = event["args_split"][0].lower()
|
name = event["args_split"][0].lower()
|
||||||
and_unloaded = ""
|
and_unloaded = ""
|
||||||
|
|
|
@ -112,10 +112,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
def reduced_activities(self, string): return [a for a in self.activities(string) if a in self.PASSENGER_ACTIVITIES]
|
def reduced_activities(self, string): return [a for a in self.activities(string) if a in self.PASSENGER_ACTIVITIES]
|
||||||
|
|
||||||
@Utils.hook("telegram.command.nrtrains")
|
@Utils.hook("telegram.command.nrtrains")
|
||||||
@Utils.hook("received.command.nrtrains", min_args=1, usage="<crs_id>")
|
@Utils.hook("received.command.nrtrains", min_args=1)
|
||||||
def trains(self, event):
|
def trains(self, event):
|
||||||
"""
|
"""
|
||||||
Get train/bus services for a station (Powered by NRE)
|
:help: Get train/bus services for a station (Powered by NRE)
|
||||||
|
:usage: <crs_id>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
client = self.client
|
client = self.client
|
||||||
|
@ -292,11 +293,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write("%s%s: %s" % (station_summary, " departures calling at %s" % filter["inter"] if filter["inter"] else '', trains_string))
|
event["stdout"].write("%s%s: %s" % (station_summary, " departures calling at %s" % filter["inter"] if filter["inter"] else '', trains_string))
|
||||||
|
|
||||||
@Utils.hook("telegram.command.nrservice")
|
@Utils.hook("telegram.command.nrservice")
|
||||||
@Utils.hook("received.command.nrservice", min_args=1, usage="<service_id>")
|
@Utils.hook("received.command.nrservice", min_args=1)
|
||||||
def service(self, event):
|
def service(self, event):
|
||||||
"""
|
"""
|
||||||
Get train service information for a UID, headcode or RID
|
:help: Get train service information for a UID, headcode or RID
|
||||||
(Powered by NRE)
|
(Powered by NRE)
|
||||||
|
:usage: <service_id>
|
||||||
"""
|
"""
|
||||||
client = self.client
|
client = self.client
|
||||||
colours = self.COLOURS
|
colours = self.COLOURS
|
||||||
|
@ -487,10 +489,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
", ".join([s["summary"] for s in stations_filtered])))
|
", ".join([s["summary"] for s in stations_filtered])))
|
||||||
|
|
||||||
@Utils.hook("telegram.command.nrhead")
|
@Utils.hook("telegram.command.nrhead")
|
||||||
@Utils.hook("received.command.nrhead", min_args=1, usage="<headcode>")
|
@Utils.hook("received.command.nrhead", min_args=1)
|
||||||
def head(self, event):
|
def head(self, event):
|
||||||
"""
|
"""
|
||||||
Get information for a given headcode/UID/RID (Powered by NRE)
|
:help: Get information for a given headcode/UID/RID (Powered by NRE)
|
||||||
|
:usage: <headcode>
|
||||||
"""
|
"""
|
||||||
client = self.client
|
client = self.client
|
||||||
service_id = event["args_split"][0]
|
service_id = event["args_split"][0]
|
||||||
|
@ -508,10 +511,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write(", ".join(["h/%s r/%s u/%s rs/%s %s (%s) -> %s (%s)" % (a["trainid"], a["rid"], a["uid"], a["rsid"], a["originName"], a["originCrs"], a["destinationName"], a["destinationCrs"]) for a in services]))
|
event["stdout"].write(", ".join(["h/%s r/%s u/%s rs/%s %s (%s) -> %s (%s)" % (a["trainid"], a["rid"], a["uid"], a["rsid"], a["originName"], a["originCrs"], a["destinationName"], a["destinationCrs"]) for a in services]))
|
||||||
|
|
||||||
@Utils.hook("telegram.command.nrcode")
|
@Utils.hook("telegram.command.nrcode")
|
||||||
@Utils.hook("received.command.nrcode", min_args=1, usage="<code>")
|
@Utils.hook("received.command.nrcode", min_args=1)
|
||||||
def service_code(self, event):
|
def service_code(self, event):
|
||||||
"""
|
"""
|
||||||
Get the text for a given delay/cancellation code (Powered by NRE)
|
:help: Get the text for a given delay/cancellation code (Powered by NRE)
|
||||||
|
:usage: <code>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
client = self.client
|
client = self.client
|
||||||
|
|
|
@ -38,11 +38,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
user.identified_account_override = None
|
user.identified_account_override = None
|
||||||
user.identified_account_id_override = None
|
user.identified_account_id_override = None
|
||||||
|
|
||||||
@Utils.hook("received.command.identify", private_only=True, min_args=1,
|
@Utils.hook("received.command.identify", private_only=True, min_args=1)
|
||||||
usage="[account] <password>")
|
|
||||||
def identify(self, event):
|
def identify(self, event):
|
||||||
"""
|
"""
|
||||||
Identify yourself
|
:help: Identify yourself
|
||||||
|
:usage: [account] <password>
|
||||||
"""
|
"""
|
||||||
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
||||||
"internal")
|
"internal")
|
||||||
|
@ -80,11 +80,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("You are already identified")
|
event["stderr"].write("You are already identified")
|
||||||
|
|
||||||
@Utils.hook("received.command.register", private_only=True, min_args=1,
|
@Utils.hook("received.command.register", private_only=True, min_args=1)
|
||||||
usage="<password>")
|
|
||||||
def register(self, event):
|
def register(self, event):
|
||||||
"""
|
"""
|
||||||
Register yourself
|
:help: Register yourself
|
||||||
|
:usage: <password>
|
||||||
"""
|
"""
|
||||||
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
||||||
"internal")
|
"internal")
|
||||||
|
@ -107,7 +107,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.logout", private_only=True)
|
@Utils.hook("received.command.logout", private_only=True)
|
||||||
def logout(self, event):
|
def logout(self, event):
|
||||||
"""
|
"""
|
||||||
Logout from your identified account
|
:help: Logout from your identified account
|
||||||
"""
|
"""
|
||||||
if event["user"].identified_account_override:
|
if event["user"].identified_account_override:
|
||||||
self._logout(event["user"])
|
self._logout(event["user"])
|
||||||
|
@ -116,10 +116,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stderr"].write("You are not logged in")
|
event["stderr"].write("You are not logged in")
|
||||||
|
|
||||||
@Utils.hook("received.command.resetpassword", private_only=True,
|
@Utils.hook("received.command.resetpassword", private_only=True,
|
||||||
min_args=2, usage="<nickname> <password>", permission="resetpassword")
|
min_args=2)
|
||||||
def reset_password(self, event):
|
def reset_password(self, event):
|
||||||
"""
|
"""
|
||||||
Reset a given user's password
|
:help: Reset a given user's password
|
||||||
|
:usage: <nickname> <password>
|
||||||
|
:permission: resetpassword
|
||||||
"""
|
"""
|
||||||
target = event["server"].get_user(event["args_split"][0])
|
target = event["server"].get_user(event["args_split"][0])
|
||||||
password = " ".join(event["args_split"][1:])
|
password = " ".join(event["args_split"][1:])
|
||||||
|
@ -135,7 +137,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
@Utils.hook("preprocess.command")
|
@Utils.hook("preprocess.command")
|
||||||
def preprocess_command(self, event):
|
def preprocess_command(self, event):
|
||||||
permission = event["hook"].kwargs.get("permission", None)
|
permission = event["hook"].get_kwarg("permission", None)
|
||||||
authenticated = event["hook"].kwargs.get("authenticated", False)
|
authenticated = event["hook"].kwargs.get("authenticated", False)
|
||||||
|
|
||||||
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
||||||
|
@ -166,7 +168,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.mypermissions", authenticated=True)
|
@Utils.hook("received.command.mypermissions", authenticated=True)
|
||||||
def my_permissions(self, event):
|
def my_permissions(self, event):
|
||||||
"""
|
"""
|
||||||
Show your permissions
|
:help: Show your permissions
|
||||||
"""
|
"""
|
||||||
permissions = event["user"].get_setting("permissions", [])
|
permissions = event["user"].get_setting("permissions", [])
|
||||||
event["stdout"].write("Your permissions: %s" % ", ".join(permissions))
|
event["stdout"].write("Your permissions: %s" % ", ".join(permissions))
|
||||||
|
@ -177,11 +179,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
permissions = target.get_setting("permissions", [])
|
permissions = target.get_setting("permissions", [])
|
||||||
return [target, registered, permissions]
|
return [target, registered, permissions]
|
||||||
|
|
||||||
@Utils.hook("received.command.givepermission", min_args=2,
|
@Utils.hook("received.command.givepermission", min_args=2)
|
||||||
permission="givepermission")
|
|
||||||
def give_permission(self, event):
|
def give_permission(self, event):
|
||||||
"""
|
"""
|
||||||
Give a given permission to a given user
|
:help: Give a given permission to a given user
|
||||||
|
:usage: <nickname> <permission>
|
||||||
|
:permission: givepermission
|
||||||
"""
|
"""
|
||||||
permission = event["args_split"][1].lower()
|
permission = event["args_split"][1].lower()
|
||||||
target, registered, permissions = self._get_user_details(
|
target, registered, permissions = self._get_user_details(
|
||||||
|
@ -199,11 +202,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
target.set_setting("permissions", permissions)
|
target.set_setting("permissions", permissions)
|
||||||
event["stdout"].write("Gave permission '%s' to %s" % (
|
event["stdout"].write("Gave permission '%s' to %s" % (
|
||||||
permission, target.nickname))
|
permission, target.nickname))
|
||||||
@Utils.hook("received.command.removepermission", min_args=2,
|
@Utils.hook("received.command.removepermission", min_args=2)
|
||||||
permission="removepermission")
|
|
||||||
def remove_permission(self, event):
|
def remove_permission(self, event):
|
||||||
"""
|
"""
|
||||||
Remove a given permission from a given user
|
:help: Remove a given permission from a given user
|
||||||
|
:usage: <nickname> <permission>
|
||||||
|
:permission: removepermission
|
||||||
"""
|
"""
|
||||||
permission = event["args_split"][1].lower()
|
permission = event["args_split"][1].lower()
|
||||||
target, registered, permissions = self._get_user_details(
|
target, registered, permissions = self._get_user_details(
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.ping", help="Ping pong!")
|
@Utils.hook("received.command.ping")
|
||||||
def pong(self, event):
|
def pong(self, event):
|
||||||
|
"""
|
||||||
|
:help: Ping pong!
|
||||||
|
"""
|
||||||
event["stdout"].write("Pong!")
|
event["stdout"].write("Pong!")
|
||||||
|
|
|
@ -7,11 +7,11 @@ 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.quoteadd|qadd", min_args=1)
|
||||||
usage="<category> = <quote>")
|
|
||||||
def quote_add(self, event):
|
def quote_add(self, event):
|
||||||
"""
|
"""
|
||||||
Add a quote to a category
|
:help: Add a quote to a category
|
||||||
|
:usage: <category> = <quote>
|
||||||
"""
|
"""
|
||||||
category, quote = self.category_and_quote(event["args"])
|
category, quote = self.category_and_quote(event["args"])
|
||||||
if category and quote:
|
if category and quote:
|
||||||
|
@ -23,11 +23,11 @@ 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.quoteget|qget", min_args=1)
|
||||||
usage="<category> = <search>")
|
|
||||||
def quote_get(self, event):
|
def quote_get(self, event):
|
||||||
"""
|
"""
|
||||||
Get a quote from a ccategory
|
:help: Get a quote from a ccategory
|
||||||
|
:usage: <category> = <search>
|
||||||
"""
|
"""
|
||||||
category, to_find = self.category_and_quote(event["args"])
|
category, to_find = self.category_and_quote(event["args"])
|
||||||
if category and to_find:
|
if category and to_find:
|
||||||
|
@ -46,11 +46,11 @@ 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.quotedel|qdel", min_args=1)
|
||||||
usage="<category> = <quote>")
|
|
||||||
def quote_del(self, event):
|
def quote_del(self, event):
|
||||||
"""
|
"""
|
||||||
Delete a quote from a category
|
:help: Delete a quote from a category
|
||||||
|
:usage: <category> = <quote>
|
||||||
"""
|
"""
|
||||||
category, remove_quote = self.category_and_quote(event["args"])
|
category, remove_quote = self.category_and_quote(event["args"])
|
||||||
remove_quote_lower = remove_quote.lower()
|
remove_quote_lower = remove_quote.lower()
|
||||||
|
@ -71,10 +71,11 @@ 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", usage="<category>", min_args=1)
|
@Utils.hook("received.command.quote|q", min_args=1)
|
||||||
def quote(self, event):
|
def quote(self, event):
|
||||||
"""
|
"""
|
||||||
Get a random quote from a category
|
:help: Get a random quote from a category
|
||||||
|
:usage: <category>
|
||||||
"""
|
"""
|
||||||
category = event["args"].strip().lower()
|
category = event["args"].strip().lower()
|
||||||
quotes = event["server"].get_setting("quotes-%s" % category, [])
|
quotes = event["server"].get_setting("quotes-%s" % category, [])
|
||||||
|
|
|
@ -4,10 +4,11 @@ from src import ModuleManager, Utils
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "Random"
|
_name = "Random"
|
||||||
|
|
||||||
@Utils.hook("received.command.random|rand", usage="[start] [end]")
|
@Utils.hook("received.command.random|rand")
|
||||||
def random(self, event):
|
def random(self, event):
|
||||||
"""
|
"""
|
||||||
Get a random number
|
:help: Get a random number
|
||||||
|
:usage: [start] [end]
|
||||||
"""
|
"""
|
||||||
start, end = "1", "100"
|
start, end = "1", "100"
|
||||||
if len(event["args_split"]) > 1:
|
if len(event["args_split"]) > 1:
|
||||||
|
@ -30,6 +31,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.guid")
|
@Utils.hook("received.command.guid")
|
||||||
def guid(self, event):
|
def guid(self, event):
|
||||||
"""
|
"""
|
||||||
Get a random guid
|
:help: Get a random guid
|
||||||
"""
|
"""
|
||||||
event["stdout"].write(str(uuid.uuid4()))
|
event["stdout"].write(str(uuid.uuid4()))
|
||||||
|
|
|
@ -7,10 +7,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
seen_seconds = time.time()
|
seen_seconds = time.time()
|
||||||
event["user"].set_setting("seen", seen_seconds)
|
event["user"].set_setting("seen", seen_seconds)
|
||||||
|
|
||||||
@Utils.hook("received.command.seen", min_args=1, usage="<username>")
|
@Utils.hook("received.command.seen", min_args=1)
|
||||||
def seen(self, event):
|
def seen(self, event):
|
||||||
"""
|
"""
|
||||||
Find out when a user was last seen
|
:help: Find out when a user was last seen
|
||||||
|
:usage: <nickname>
|
||||||
"""
|
"""
|
||||||
seen_seconds = event["server"].get_user(event["args_split"][0]
|
seen_seconds = event["server"].get_user(event["args_split"][0]
|
||||||
).get_setting("seen")
|
).get_setting("seen")
|
||||||
|
|
|
@ -22,28 +22,31 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stdout"].write("Available settings: %s" % (
|
event["stdout"].write("Available settings: %s" % (
|
||||||
", ".join(settings_dict.keys())))
|
", ".join(settings_dict.keys())))
|
||||||
@Utils.hook("received.command.set", usage="<setting> <value>")
|
@Utils.hook("received.command.set")
|
||||||
def set(self, event):
|
def set(self, event):
|
||||||
"""
|
"""
|
||||||
Set a specified user setting
|
:help: Set a specified user setting
|
||||||
|
:usage: <setting> <value>
|
||||||
"""
|
"""
|
||||||
self._set(self.exports.get_all("set"), event, event["user"])
|
self._set(self.exports.get_all("set"), event, event["user"])
|
||||||
|
|
||||||
@Utils.hook("received.command.channelset", channel_only=True,
|
@Utils.hook("received.command.channelset", channel_only=True,
|
||||||
usage="<setting> <value>", require_mode="o")
|
require_mode="o")
|
||||||
@Utils.hook("received.command.channelsetoverride", channel_only=True,
|
@Utils.hook("received.command.channelsetoverride", channel_only=True,
|
||||||
usage="<setting> <value>", permission="channelsetoverride")
|
permission="channelsetoverride")
|
||||||
def channel_set(self, event):
|
def channel_set(self, event):
|
||||||
"""
|
"""
|
||||||
Get a specified channel setting for the current channel
|
:help: Get a specified channel setting for the current channel
|
||||||
|
:usage: <setting> <value>
|
||||||
"""
|
"""
|
||||||
self._set(self.exports.get_all("channelset"), event, event["target"])
|
self._set(self.exports.get_all("channelset"), event, event["target"])
|
||||||
|
|
||||||
@Utils.hook("received.command.serverset", usage="<setting> <value>",
|
@Utils.hook("received.command.serverset")
|
||||||
permission="serverset")
|
|
||||||
def server_set(self, event):
|
def server_set(self, event):
|
||||||
"""
|
"""
|
||||||
Set a specified server setting for the current server
|
:help: Set a specified server setting for the current server
|
||||||
|
:usage: <setting> <value>
|
||||||
|
:permission: serverset
|
||||||
"""
|
"""
|
||||||
self._set(self.exports.get_all("serverset"), event, event["server"])
|
self._set(self.exports.get_all("serverset"), event, event["server"])
|
||||||
|
|
||||||
|
@ -54,30 +57,33 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stdout"].write("'%s' has no value set" % setting)
|
event["stdout"].write("'%s' has no value set" % setting)
|
||||||
|
|
||||||
@Utils.hook("received.command.get", min_args=1, usage="<setting>")
|
@Utils.hook("received.command.get", min_args=1)
|
||||||
def get(self, event):
|
def get(self, event):
|
||||||
"""
|
"""
|
||||||
Get a specified user setting
|
:help: Get a specified user setting
|
||||||
|
:usage: <setting>
|
||||||
"""
|
"""
|
||||||
setting = event["args_split"][0]
|
setting = event["args_split"][0]
|
||||||
self._get(event, setting, "", event["user"].get_setting(
|
self._get(event, setting, "", event["user"].get_setting(
|
||||||
setting, None))
|
setting, None))
|
||||||
|
|
||||||
@Utils.hook("received.command.channelget", channel_only=True,
|
@Utils.hook("received.command.channelget", channel_only=True, min_args=1)
|
||||||
usage="<setting>", min_args=1, require_mode="o")
|
|
||||||
def channel_get(self, event):
|
def channel_get(self, event):
|
||||||
"""
|
"""
|
||||||
Get a specified channel setting for the current channel
|
:help: Get a specified channel setting for the current channel
|
||||||
|
:usage: <setting>
|
||||||
|
:require_mode: o
|
||||||
"""
|
"""
|
||||||
setting = event["args_split"][0]
|
setting = event["args_split"][0]
|
||||||
self._get(event, setting, " for %s" % event["target"].name,
|
self._get(event, setting, " for %s" % event["target"].name,
|
||||||
event["target"].get_setting(setting, None))
|
event["target"].get_setting(setting, None))
|
||||||
|
|
||||||
@Utils.hook("received.command.serverget", usage="<setting>", min_args=1,
|
@Utils.hook("received.command.serverget", min_args=1)
|
||||||
permission="serverget")
|
|
||||||
def server_get(self, event):
|
def server_get(self, event):
|
||||||
"""
|
"""
|
||||||
Get a specified server setting for the current server
|
:help: Get a specified server setting for the current server
|
||||||
|
:usage: <setting>
|
||||||
|
:permission: serverget
|
||||||
"""
|
"""
|
||||||
setting = event["args_split"][0]
|
setting = event["args_split"][0]
|
||||||
self._get(event, setting, "", event["server"].get_setting(
|
self._get(event, setting, "", event["server"].get_setting(
|
||||||
|
|
|
@ -13,7 +13,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.soundcloud|sc")
|
@Utils.hook("received.command.soundcloud|sc")
|
||||||
def soundcloud(self, event):
|
def soundcloud(self, event):
|
||||||
"""
|
"""
|
||||||
Search SoundCloud
|
:help: Search SoundCloud
|
||||||
|
:usage: <term>
|
||||||
"""
|
"""
|
||||||
query = None
|
query = None
|
||||||
url = None
|
url = None
|
||||||
|
|
|
@ -7,7 +7,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.spotify", min_args=1)
|
@Utils.hook("received.command.spotify", min_args=1)
|
||||||
def spotify(self, event):
|
def spotify(self, event):
|
||||||
"""
|
"""
|
||||||
Search for a track on spotify
|
:help: Search for a track on spotify
|
||||||
|
:usage: <term>
|
||||||
"""
|
"""
|
||||||
page = Utils.get_url(URL_SPOTIFY, get_params={"type": "track",
|
page = Utils.get_url(URL_SPOTIFY, get_params={"type": "track",
|
||||||
"limit": 1, "q": event["args"]}, json=True)
|
"limit": 1, "q": event["args"]}, json=True)
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.uptime")
|
@Utils.hook("received.command.uptime")
|
||||||
def uptime(self, event):
|
def uptime(self, event):
|
||||||
"""
|
"""
|
||||||
Show my uptime
|
:help: Show my uptime
|
||||||
"""
|
"""
|
||||||
seconds = int(time.time()-self.bot.start_time)
|
seconds = int(time.time()-self.bot.start_time)
|
||||||
event["stdout"].write("Uptime: %s" % Utils.to_pretty_time(
|
event["stdout"].write("Uptime: %s" % Utils.to_pretty_time(
|
||||||
|
@ -14,7 +14,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.stats")
|
@Utils.hook("received.command.stats")
|
||||||
def stats(self, event):
|
def stats(self, event):
|
||||||
"""
|
"""
|
||||||
Show my network/channel/user stats
|
:help: Show my network/channel/user stats
|
||||||
"""
|
"""
|
||||||
networks = len(self.bot.servers)
|
networks = len(self.bot.servers)
|
||||||
channels = 0
|
channels = 0
|
||||||
|
|
|
@ -5,8 +5,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.strax")
|
@Utils.hook("received.command.strax")
|
||||||
def strax(self, event):
|
def strax(self, event):
|
||||||
"""
|
"""
|
||||||
Suggests a glorious method of battle for the glory of the Sontaran
|
:help: Suggests a glorious method of battle for the glory of the
|
||||||
Empire, through IRC!
|
Sontaran Empire, through IRC!
|
||||||
"""
|
"""
|
||||||
suggestion_greeting = ["Might I suggest", "Can I suggest", "Should we attack immediately with"]
|
suggestion_greeting = ["Might I suggest", "Can I suggest", "Should we attack immediately with"]
|
||||||
command_greeting = ["We should attack now with", "We must attack now with", "I suggest attacking with",
|
command_greeting = ["We should attack now with", "We must attack now with", "I suggest attacking with",
|
||||||
|
|
|
@ -46,10 +46,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
platform = m.group(2)
|
platform = m.group(2)
|
||||||
return platform
|
return platform
|
||||||
|
|
||||||
@Utils.hook("received.command.tflbus", min_args=1, usage="<stop_id>")
|
@Utils.hook("received.command.tflbus", min_args=1)
|
||||||
def bus(self, event):
|
def bus(self, event):
|
||||||
"""
|
"""
|
||||||
Get bus due times for a TfL bus stop
|
:help: Get bus due times for a TfL bus stop
|
||||||
|
:usage: <stop_id>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
@ -122,10 +123,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Bus ID '%s' unknown" % stop_id)
|
event["stderr"].write("Bus ID '%s' unknown" % stop_id)
|
||||||
|
|
||||||
@Utils.hook("received.command.tflline", usage="<line_name>")
|
@Utils.hook("received.command.tflline")
|
||||||
def line(self, event):
|
def line(self, event):
|
||||||
"""
|
"""
|
||||||
Get line status for TfL underground lines
|
:help: Get line status for TfL underground lines
|
||||||
|
:usage: <line_name>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
@ -165,10 +167,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No results")
|
event["stderr"].write("No results")
|
||||||
|
|
||||||
@Utils.hook("received.command.tflsearch", min_args=1, usage="<name>")
|
@Utils.hook("received.command.tflsearch", min_args=1)
|
||||||
def search(self, event):
|
def search(self, event):
|
||||||
"""
|
"""
|
||||||
Get a list of TfL stop IDs for a given name
|
:help: Get a list of TfL stop IDs for a given name
|
||||||
|
:usage: <name>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
@ -186,10 +189,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No results")
|
event["stderr"].write("No results")
|
||||||
|
|
||||||
@Utils.hook("received.command.tflvehicle", min_args=1, usage="<ID>")
|
@Utils.hook("received.command.tflvehicle", min_args=1)
|
||||||
def vehicle(self, event):
|
def vehicle(self, event):
|
||||||
"""
|
"""
|
||||||
Get information for a given vehicle
|
:help: Get information for a given vehicle
|
||||||
|
:usage: <ID>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
@ -206,11 +210,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
vehicle["vehicleId"], vehicle["lineName"], vehicle["destinationName"], vehicle["currentLocation"],
|
vehicle["vehicleId"], vehicle["lineName"], vehicle["destinationName"], vehicle["currentLocation"],
|
||||||
vehicle["stationName"], vehicle["naptanId"], arrival_time, platform))
|
vehicle["stationName"], vehicle["naptanId"], arrival_time, platform))
|
||||||
|
|
||||||
@Utils.hook("received.command.tflservice", min_args=1,
|
@Utils.hook("received.command.tflservice", min_args=1)
|
||||||
usage="<service index>")
|
|
||||||
def service(self, event):
|
def service(self, event):
|
||||||
"""
|
"""
|
||||||
Get service information and arrival estimates
|
:help: Get service information and arrival estimates
|
||||||
|
:usage: <service index>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
@ -239,10 +243,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
a["expectedArrival"][11:16]
|
a["expectedArrival"][11:16]
|
||||||
) for a in arrivals]))
|
) for a in arrivals]))
|
||||||
|
|
||||||
@Utils.hook("received.command.tflstop", min_args=1, usage="<stop_id>")
|
@Utils.hook("received.command.tflstop", min_args=1)
|
||||||
def stop(self, event):
|
def stop(self, event):
|
||||||
"""
|
"""
|
||||||
Get information for a given stop
|
:help: Get information for a given stop
|
||||||
|
:usage: <stop_id>
|
||||||
"""
|
"""
|
||||||
app_id = self.bot.config["tfl-api-id"]
|
app_id = self.bot.config["tfl-api-id"]
|
||||||
app_key = self.bot.config["tfl-api-key"]
|
app_key = self.bot.config["tfl-api-key"]
|
||||||
|
|
|
@ -5,11 +5,11 @@ from src import ModuleManager, Utils
|
||||||
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.synonym|antonym", min_args=1,
|
@Utils.hook("received.command.synonym|antonym", min_args=1)
|
||||||
usage="<word> [type]")
|
|
||||||
def thesaurus(self, event):
|
def thesaurus(self, event):
|
||||||
"""
|
"""
|
||||||
Get synonyms/antonyms for a provided phrase
|
:help: Get synonyms/antonyms for a provided phrase
|
||||||
|
:usage: <word> [type]
|
||||||
"""
|
"""
|
||||||
phrase = event["args_split"][0]
|
phrase = event["args_split"][0]
|
||||||
page = Utils.get_url(URL_THESAURUS % (self.bot.config[
|
page = Utils.get_url(URL_THESAURUS % (self.bot.config[
|
||||||
|
|
|
@ -7,7 +7,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.title|t", usage="[URL]")
|
@Utils.hook("received.command.title|t", usage="[URL]")
|
||||||
def title(self, event):
|
def title(self, event):
|
||||||
"""
|
"""
|
||||||
Get the title of a URL
|
:help: Get the title of a URL
|
||||||
|
:usage: [URL]
|
||||||
"""
|
"""
|
||||||
url = None
|
url = None
|
||||||
if len(event["args"]) > 0:
|
if len(event["args"]) > 0:
|
||||||
|
|
|
@ -11,11 +11,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
if messages:
|
if messages:
|
||||||
event["channel"].del_user_setting(event["user"].get_id(), "to")
|
event["channel"].del_user_setting(event["user"].get_id(), "to")
|
||||||
|
|
||||||
@Utils.hook("received.command.to", min_args=2, channel_only=True,
|
@Utils.hook("received.command.to", min_args=2, channel_only=True)
|
||||||
usage="<username> <message>")
|
|
||||||
def to(self, event):
|
def to(self, event):
|
||||||
"""
|
"""
|
||||||
Relay a message to a user the next time they talk in this channel"
|
:help: Relay a message to a user the next time they talk in this
|
||||||
|
channel
|
||||||
|
:usage: <nickname> <message>
|
||||||
"""
|
"""
|
||||||
target_user = event["server"].get_user(event["args_split"][0])
|
target_user = event["server"].get_user(event["args_split"][0])
|
||||||
messages = event["target"].get_user_setting(target_user.get_id(),
|
messages = event["target"].get_user_setting(target_user.get_id(),
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from src import ModuleManager, Utils
|
from src import ModuleManager, Utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.todo", usage="[item number]")
|
@Utils.hook("received.command.todo")
|
||||||
def todo(self, event):
|
def todo(self, event):
|
||||||
"""
|
"""
|
||||||
Find out what's in your todo list
|
:help: Find out what's in your todo list
|
||||||
|
:usage: [item number]
|
||||||
"""
|
"""
|
||||||
todo = event["user"].get_setting("todo", [])
|
todo = event["user"].get_setting("todo", [])
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
|
@ -20,10 +21,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
todo_count = len(todo)
|
todo_count = len(todo)
|
||||||
event["stdout"].write("There are %d items in your todo" % todo_count)
|
event["stdout"].write("There are %d items in your todo" % todo_count)
|
||||||
|
|
||||||
@Utils.hook("received.command.todoadd", min_args=1, usage="<description>")
|
@Utils.hook("received.command.todoadd", min_args=1)
|
||||||
def todo_add(self, event):
|
def todo_add(self, event):
|
||||||
"""
|
"""
|
||||||
Add something to your todo list
|
:help: Add something to your todo list
|
||||||
|
:usage: <description>
|
||||||
"""
|
"""
|
||||||
arg_lower = event["args"].lower()
|
arg_lower = event["args"].lower()
|
||||||
todo = event["user"].get_setting("todo", [])
|
todo = event["user"].get_setting("todo", [])
|
||||||
|
@ -36,10 +38,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["user"].set_setting("todo", todo)
|
event["user"].set_setting("todo", todo)
|
||||||
event["stdout"].write("Saved")
|
event["stdout"].write("Saved")
|
||||||
|
|
||||||
@Utils.hook("received.command.tododel", min_args=1, usage="<item number>")
|
@Utils.hook("received.command.tododel", min_args=1)
|
||||||
def todo_del(self, event):
|
def todo_del(self, event):
|
||||||
"""
|
"""
|
||||||
Remove something from your todo list
|
:help: Remove something from your todo list
|
||||||
|
:usage: <item number>
|
||||||
"""
|
"""
|
||||||
todo = event["user"].get_setting("todo", [])
|
todo = event["user"].get_setting("todo", [])
|
||||||
if event["args_split"][0].isdigit() and int(event["args_split"][0]) > 0:
|
if event["args_split"][0].isdigit() and int(event["args_split"][0]) > 0:
|
||||||
|
|
|
@ -7,10 +7,11 @@ 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", usage="[username]")
|
@Utils.hook("received.command.nowwatching|nw")
|
||||||
def now_watching(self, event):
|
def now_watching(self, event):
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
:usage: [username]
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
username = event["args_split"][0]
|
username = event["args_split"][0]
|
||||||
|
|
|
@ -6,10 +6,12 @@ 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", usage="[phrase]")
|
@Utils.hook("received.command.translate|tr")
|
||||||
def translate(self, event):
|
def translate(self, event):
|
||||||
"""
|
"""
|
||||||
Translate the provided phrase or the last line in thie current channel
|
:help: Translate the provided phrase or the last line in thie current
|
||||||
|
channel
|
||||||
|
:usage: [phrase]
|
||||||
"""
|
"""
|
||||||
phrase = event["args"]
|
phrase = event["args"]
|
||||||
if not phrase:
|
if not phrase:
|
||||||
|
|
|
@ -19,10 +19,11 @@ 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", usage="[@username/URL/ID]")
|
@Utils.hook("received.command.tweet|tw")
|
||||||
def tweet(self, event):
|
def tweet(self, event):
|
||||||
"""
|
"""
|
||||||
Get/find a tweet
|
:help: Get/find a tweet
|
||||||
|
:usage: [@username/URL/ID]
|
||||||
"""
|
"""
|
||||||
api_key = self.bot.config["twitter-api-key"]
|
api_key = self.bot.config["twitter-api-key"]
|
||||||
api_secret = self.bot.config["twitter-api-secret"]
|
api_secret = self.bot.config["twitter-api-secret"]
|
||||||
|
|
|
@ -5,10 +5,11 @@ UPCITEMDB_URL = "https://api.upcitemdb.com/prod/trial/lookup"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "UPC"
|
_name = "UPC"
|
||||||
|
|
||||||
@Utils.hook("received.command.upc|ean|gtin", min_args=1, usage="<UPC|EAN>")
|
@Utils.hook("received.command.upc|ean|gtin", min_args=1)
|
||||||
def upc(self, event):
|
def upc(self, event):
|
||||||
"""
|
"""
|
||||||
Look up a product by UPC, EAN or GTIN
|
:help: Look up a product by UPC, EAN or GTIN
|
||||||
|
:usage: <UPC|EAN|GTIN>
|
||||||
"""
|
"""
|
||||||
arg_len = len(event["args_split"][0])
|
arg_len = len(event["args_split"][0])
|
||||||
if not arg_len == 12 and not arg_len == 13:
|
if not arg_len == 12 and not arg_len == 13:
|
||||||
|
|
|
@ -5,11 +5,11 @@ 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.urbandictionary|ud", min_args=1)
|
||||||
usage="<term>")
|
|
||||||
def ud(self, event):
|
def ud(self, event):
|
||||||
"""
|
"""
|
||||||
Get the definition of a provided term from Urban Dictionary
|
:help: Get the definition of a provided term from Urban Dictionary
|
||||||
|
:usage: <term>
|
||||||
"""
|
"""
|
||||||
term = event["args"]
|
term = event["args"]
|
||||||
number = 1
|
number = 1
|
||||||
|
|
|
@ -8,7 +8,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.weather", min_args=1, usage="<location>")
|
@Utils.hook("received.command.weather", min_args=1, usage="<location>")
|
||||||
def weather(self, event):
|
def weather(self, event):
|
||||||
"""
|
"""
|
||||||
Get current weather data for a provided location
|
:help: Get current weather data for a provided location
|
||||||
|
:usage: <location>
|
||||||
"""
|
"""
|
||||||
api_key = self.bot.config["openweathermap-api-key"]
|
api_key = self.bot.config["openweathermap-api-key"]
|
||||||
page = Utils.get_url(URL_WEATHER, get_params={
|
page = Utils.get_url(URL_WEATHER, get_params={
|
||||||
|
|
|
@ -6,7 +6,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
@Utils.hook("received.command.wiki|wi", min_args=1)
|
@Utils.hook("received.command.wiki|wi", min_args=1)
|
||||||
def wikipedia(self, event):
|
def wikipedia(self, event):
|
||||||
"""
|
"""
|
||||||
Get information from wikipedia
|
:help: Get information from wikipedia
|
||||||
|
:usage: <term>
|
||||||
"""
|
"""
|
||||||
page = Utils.get_url(URL_WIKIPEDIA, get_params={
|
page = Utils.get_url(URL_WIKIPEDIA, get_params={
|
||||||
"action": "query", "prop": "extracts",
|
"action": "query", "prop": "extracts",
|
||||||
|
|
|
@ -7,10 +7,11 @@ 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, usage="<query>")
|
@Utils.hook("received.command.wolframalpha|wa", min_args=1)
|
||||||
def wa(self, event):
|
def wa(self, event):
|
||||||
"""
|
"""
|
||||||
Evauate a given string on Wolfram|Alpha
|
:help: Evauate a given string on Wolfram|Alpha
|
||||||
|
:usage: <query>
|
||||||
"""
|
"""
|
||||||
code, result = Utils.get_url(URL_WA, get_params={"i": event["args"],
|
code, result = Utils.get_url(URL_WA, get_params={"i": event["args"],
|
||||||
"appid": self.bot.config["wolframalpha-api-key"],
|
"appid": self.bot.config["wolframalpha-api-key"],
|
||||||
|
|
|
@ -31,10 +31,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
self._channel_message(event["server"].get_user(
|
self._channel_message(event["server"].get_user(
|
||||||
event["server"].nickname), event)
|
event["server"].nickname), event)
|
||||||
|
|
||||||
@Utils.hook("received.command.words", channel_only=True, usage="<nickname>")
|
@Utils.hook("received.command.words", channel_only=True)
|
||||||
def words(self, event):
|
def words(self, event):
|
||||||
"""
|
"""
|
||||||
See how many words you or the given nickname have used
|
:help: See how many words you or the given nickname have used
|
||||||
|
:usage: [nickname]
|
||||||
"""
|
"""
|
||||||
if event["args_split"]:
|
if event["args_split"]:
|
||||||
target = event["server"].get_user(event["args_split"
|
target = event["server"].get_user(event["args_split"
|
||||||
|
@ -51,11 +52,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].write("%s has used %d words (%d in %s)" % (
|
event["stdout"].write("%s has used %d words (%d in %s)" % (
|
||||||
target.nickname, total, this_channel, event["target"].name))
|
target.nickname, total, this_channel, event["target"].name))
|
||||||
|
|
||||||
@Utils.hook("received.command.trackword", min_args=1,
|
@Utils.hook("received.command.trackword", min_args=1)
|
||||||
permission="track-word")
|
|
||||||
def track_word(self, event):
|
def track_word(self, event):
|
||||||
"""
|
"""
|
||||||
Start tracking a word
|
:help: Start tracking a word
|
||||||
|
:usage: <word>
|
||||||
|
:permission: track-word
|
||||||
"""
|
"""
|
||||||
word = event["args_split"][0].lower()
|
word = event["args_split"][0].lower()
|
||||||
tracked_words = event["server"].get_setting("tracked-words", [])
|
tracked_words = event["server"].get_setting("tracked-words", [])
|
||||||
|
@ -66,10 +68,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Already tracking '%s'" % word)
|
event["stderr"].write("Already tracking '%s'" % word)
|
||||||
|
|
||||||
@Utils.hook("received.command.wordusers", min_args=1, usage="<word>")
|
@Utils.hook("received.command.wordusers", min_args=1)
|
||||||
def word_users(self, event):
|
def word_users(self, event):
|
||||||
"""
|
"""
|
||||||
Show who has used a tracked word the most
|
:help: Show who has used a tracked word the most
|
||||||
|
:usage: <word>
|
||||||
"""
|
"""
|
||||||
word = event["args_split"][0].lower()
|
word = event["args_split"][0].lower()
|
||||||
if word in event["server"].get_setting("tracked-words", []):
|
if word in event["server"].get_setting("tracked-words", []):
|
||||||
|
|
|
@ -71,10 +71,11 @@ 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", usage="[query]")
|
@Utils.hook("received.command.yt|youtube")
|
||||||
def yt(self, event):
|
def yt(self, event):
|
||||||
"""
|
"""
|
||||||
Find a video on youtube
|
:help: Find a video on youtube
|
||||||
|
:usage: [query/URL]
|
||||||
"""
|
"""
|
||||||
video_id = None
|
video_id = None
|
||||||
search = None
|
search = None
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import itertools, time, traceback
|
import itertools, time, traceback
|
||||||
|
from src import Utils
|
||||||
|
|
||||||
PRIORITY_URGENT = 0
|
PRIORITY_URGENT = 0
|
||||||
PRIORITY_HIGH = 1
|
PRIORITY_HIGH = 1
|
||||||
|
@ -29,9 +30,15 @@ class EventCallback(object):
|
||||||
self.function = function
|
self.function = function
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
self.docstring = Utils.parse_docstring(function.__doc__)
|
||||||
|
|
||||||
def call(self, event):
|
def call(self, event):
|
||||||
return self.function(event)
|
return self.function(event)
|
||||||
|
|
||||||
|
def get_kwarg(self, name, default=None):
|
||||||
|
item = self.kwargs.get(name, default)
|
||||||
|
return item or self.docstring.items.get(name, default)
|
||||||
|
|
||||||
class MultipleEventHook(object):
|
class MultipleEventHook(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._event_hooks = set([])
|
self._event_hooks = set([])
|
||||||
|
|
32
src/Utils.py
32
src/Utils.py
|
@ -313,3 +313,35 @@ def get_hashflags(filename):
|
||||||
value = line_split[1]
|
value = line_split[1]
|
||||||
hashflags[hashflag] = value
|
hashflags[hashflag] = value
|
||||||
return hashflags.items()
|
return hashflags.items()
|
||||||
|
|
||||||
|
class Docstring(object):
|
||||||
|
def __init__(self, description, items):
|
||||||
|
self.description = description
|
||||||
|
self.items = items
|
||||||
|
|
||||||
|
def parse_docstring(s):
|
||||||
|
description = ""
|
||||||
|
last_item = None
|
||||||
|
items = {}
|
||||||
|
if s:
|
||||||
|
for line in s.split("\n"):
|
||||||
|
line = line.strip()
|
||||||
|
|
||||||
|
if line:
|
||||||
|
if line[0] == ":":
|
||||||
|
line_split = line.split(": ", 1)
|
||||||
|
|
||||||
|
value = None
|
||||||
|
if len(line_split) > 1:
|
||||||
|
value = line_split[1]
|
||||||
|
|
||||||
|
last_item = line_split[0][1:].lower()
|
||||||
|
items[last_item] = value
|
||||||
|
else:
|
||||||
|
if last_item:
|
||||||
|
items[last_item] += " %s" % line
|
||||||
|
else:
|
||||||
|
if description:
|
||||||
|
description += " "
|
||||||
|
description += line
|
||||||
|
return Docstring(description, items)
|
||||||
|
|
Loading…
Reference in a new issue