def __init__(self, bot):
"""Procedurablly build reaction commands."""
with open("reactions.json") as fobject:
self.data = json.load(fobject)
# TODO Add a help field to this mess.
for key in self.data:
# Avoid duplicate commands.
if key in bot.all_commands.keys():
continue
# Avoid non-dictionary values.
# Make sure that there exists a value with key "images", and that it's a list.
elif (not isinstance(self.data[key], dict) or
not isinstance(self.data[key].get("images"), list)):
continue
# This signifies the type of message to be sent.
message_indicator = self.data[key].get("message")
# No message.
if message_indicator is None:
helptext = f"{key.capitalize()}!"
async def callback(self, ctx, *, args=None):
if args:
return
await _send_image(ctx, self.data[ctx.command.name]["images"])
# Zero-length string.
elif not message_indicator:
helptext = f"{key.capitalize()} a user!"
async def callback(self, ctx, *, user: str):
message = await _generate_message(ctx, ctx.command.name, user)
await _send_image(ctx, self.data[ctx.command.name]["images"], message)
# Custom message.
else:
helptext = f"{key.capitalize()}!"
async def callback(self, ctx, *, args=None):
if args:
return
await _send_image(ctx, self.data[ctx.command.name]["images"],
self.data[ctx.command.name]["message"])
# Ew, gross.
aliases = self.data[key].get("aliases", [])
for alias in aliases:
if alias in bot.all_commands.keys():
aliases.remove(alias)
command = commands.command(name=key, help=helptext, aliases=aliases)(callback)
command = commands.cooldown(6, 12, commands.BucketType.channel)(command)
command.instance = self
setattr(self, key, command)
评论列表
文章目录