PluralKit/src/pluralkit/bot/commands/misc_commands.py

93 lines
3.1 KiB
Python
Raw Normal View History

import io
import json
import os
from discord.utils import oauth_url
from pluralkit.bot import help
from pluralkit.bot.commands import *
from pluralkit.bot.embeds import help_footer_embed
async def help_root(ctx: CommandContext):
if ctx.match("commands"):
2018-12-10 20:09:35 +01:00
await ctx.reply(help.all_commands, embed=help_footer_embed())
elif ctx.match("proxy"):
2018-12-10 20:09:35 +01:00
await ctx.reply(help.proxy_guide, embed=help_footer_embed())
elif ctx.match("system"):
await ctx.reply(help.system_commands, embed=help_footer_embed())
elif ctx.match("member"):
await ctx.reply(help.system_commands, embed=help_footer_embed())
else:
2018-12-10 20:09:35 +01:00
await ctx.reply(help.root, embed=help_footer_embed())
2018-09-07 17:34:38 +02:00
async def invite_link(ctx: CommandContext):
client_id = os.environ["CLIENT_ID"]
permissions = discord.Permissions()
# So the bot can actually add the webhooks it needs to do the proxy functionality
permissions.manage_webhooks = True
# So the bot can respond with status, error, and success messages
permissions.send_messages = True
# So the bot can delete channels
permissions.manage_messages = True
# So the bot can respond with extended embeds, ex. member cards
permissions.embed_links = True
# So the bot can send images too
permissions.attach_files = True
# (unsure if it needs this, actually, might be necessary for message lookup)
permissions.read_message_history = True
# So the bot can add reactions for confirm/deny prompts
permissions.add_reactions = True
url = oauth_url(client_id, permissions)
await ctx.reply_ok("Use this link to add PluralKit to your server: {}".format(url))
2018-09-07 17:34:38 +02:00
async def export(ctx: CommandContext):
system = await ctx.ensure_system()
members = await system.get_members(ctx.conn)
accounts = await system.get_linked_account_ids(ctx.conn)
switches = await system.get_switches(ctx.conn, 999999)
data = {
"name": system.name,
"id": system.hid,
"description": system.description,
"tag": system.tag,
"avatar_url": system.avatar_url,
"created": system.created.isoformat(),
"members": [
{
"name": member.name,
"id": member.hid,
"color": member.color,
"avatar_url": member.avatar_url,
"birthday": member.birthday.isoformat() if member.birthday else None,
"pronouns": member.pronouns,
"description": member.description,
"prefix": member.prefix,
"suffix": member.suffix,
"created": member.created.isoformat()
} for member in members
],
"accounts": [str(uid) for uid in accounts],
"switches": [
{
"timestamp": switch.timestamp.isoformat(),
"members": [member.hid for member in await switch.fetch_members(ctx.conn)]
} for switch in switches
] # TODO: messages
}
f = io.BytesIO(json.dumps(data).encode("utf-8"))
2018-11-08 16:25:58 +01:00
await ctx.message.channel.send(content="Here you go!", file=discord.File(fp=f, filename="system.json"))