Add avatar preview on set
This commit is contained in:
parent
860cba7ffe
commit
64fa1f4e3c
@ -6,8 +6,7 @@ import discord
|
|||||||
|
|
||||||
from pluralkit import db
|
from pluralkit import db
|
||||||
from pluralkit.bot import client, logger
|
from pluralkit.bot import client, logger
|
||||||
from pluralkit.utils import command, generate_hid, generate_member_info_card, generate_system_info_card, member_command, parse_mention, text_input, get_system_fuzzy, get_member_fuzzy, command_map
|
from pluralkit.utils import command, generate_hid, generate_member_info_card, generate_system_info_card, member_command, parse_mention, text_input, get_system_fuzzy, get_member_fuzzy, command_map, make_default_embed
|
||||||
|
|
||||||
|
|
||||||
@command(cmd="pk;system", subcommand=None, description="Shows information about your system.")
|
@command(cmd="pk;system", subcommand=None, description="Shows information about your system.")
|
||||||
async def this_system_info(conn, message, args):
|
async def this_system_info(conn, message, args):
|
||||||
@ -316,7 +315,12 @@ async def member_avatar(conn, message, member, args):
|
|||||||
|
|
||||||
async with conn.transaction():
|
async with conn.transaction():
|
||||||
await db.update_member_field(conn, member_id=member["id"], field="avatar_url", value=avatar_url)
|
await db.update_member_field(conn, member_id=member["id"], field="avatar_url", value=avatar_url)
|
||||||
return True, "Avatar set." if avatar_url else "Avatar cleared."
|
|
||||||
|
# Add the avatar you just set into the success embed
|
||||||
|
if not avatar_url:
|
||||||
|
return True, "Avatar cleared."
|
||||||
|
else:
|
||||||
|
return True, make_default_embed("Avatar set.").set_image(url=avatar_url)
|
||||||
|
|
||||||
|
|
||||||
@member_command(cmd="pk;member", subcommand="proxy", usage="[example]", description="Updates a member's proxy settings. Needs an \"example\" proxied message containing the string \"text\" (eg. [text], |text|, etc).")
|
@member_command(cmd="pk;member", subcommand="proxy", usage="[example]", description="Updates a member's proxy settings. Needs an \"example\" proxied message containing the string \"text\" (eg. [text], |text|, etc).")
|
||||||
@ -394,23 +398,25 @@ async def message_info(conn, message, args):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@command(cmd="pk;help", subcommand=None, usage="[system|member|message]", description="Shows this help message.")
|
def make_help(cmds):
|
||||||
async def show_help(conn, message, args):
|
|
||||||
embed = discord.Embed()
|
embed = discord.Embed()
|
||||||
embed.colour = discord.Colour.blue()
|
embed.colour = discord.Colour.blue()
|
||||||
embed.title = "PluralKit Help"
|
embed.title = "PluralKit Help"
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text="<> denotes mandatory arguments, [] denotes optional arguments")
|
text="<> denotes mandatory arguments, [] denotes optional arguments")
|
||||||
|
|
||||||
|
for cmd, subcommands in cmds:
|
||||||
|
for subcmd, (_, usage, description) in subcommands.items():
|
||||||
|
embed.add_field(name="{} {} {}".format(
|
||||||
|
cmd, subcmd or "", usage or ""), value=description, inline=False)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
@command(cmd="pk;help", subcommand=None, usage="[system|member|message]", description="Shows this help message.")
|
||||||
|
async def show_help(conn, message, args):
|
||||||
if len(args) > 0 and ("pk;" + args[0]) in command_map:
|
if len(args) > 0 and ("pk;" + args[0]) in command_map:
|
||||||
cmds = ["", ("pk;" + args[0], command_map["pk;" + args[0]])]
|
cmds = ["", ("pk;" + args[0], command_map["pk;" + args[0]])]
|
||||||
else:
|
else:
|
||||||
cmds = command_map.items()
|
cmds = command_map.items()
|
||||||
|
|
||||||
for cmd, subcommands in cmds:
|
await client.send_message(message.channel, embed=make_help(cmds))
|
||||||
for subcmd, (_, usage, description) in subcommands.items():
|
|
||||||
embed.add_field(name="{} {} {}".format(
|
|
||||||
cmd, subcmd or "", usage or ""), value=description, inline=False)
|
|
||||||
|
|
||||||
await client.send_message(message.channel, embed=embed)
|
|
||||||
return True
|
return True
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
import time
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import asyncpg
|
import asyncpg
|
||||||
@ -59,6 +60,18 @@ async def get_member_fuzzy(conn, system_id: int, key: str, system_only=True) ->
|
|||||||
if member is not None:
|
if member is not None:
|
||||||
return member
|
return member
|
||||||
|
|
||||||
|
def make_default_embed(message):
|
||||||
|
embed = discord.Embed()
|
||||||
|
embed.colour = discord.Colour.blue()
|
||||||
|
embed.description = message
|
||||||
|
return embed
|
||||||
|
|
||||||
|
def make_error_embed(message):
|
||||||
|
embed = discord.Embed()
|
||||||
|
embed.colour = discord.Colour.dark_red()
|
||||||
|
embed.description = message
|
||||||
|
return embed
|
||||||
|
|
||||||
command_map = {}
|
command_map = {}
|
||||||
|
|
||||||
# Command wrapper
|
# Command wrapper
|
||||||
@ -69,7 +82,10 @@ command_map = {}
|
|||||||
def command(cmd, subcommand, usage=None, description=None):
|
def command(cmd, subcommand, usage=None, description=None):
|
||||||
def wrap(func):
|
def wrap(func):
|
||||||
async def wrapper(conn, message, args):
|
async def wrapper(conn, message, args):
|
||||||
|
before = time.perf_counter()
|
||||||
res = await func(conn, message, args)
|
res = await func(conn, message, args)
|
||||||
|
after = time.perf_counter()
|
||||||
|
time_ms = (after - before) * 1000
|
||||||
|
|
||||||
if res is not None:
|
if res is not None:
|
||||||
if not isinstance(res, tuple):
|
if not isinstance(res, tuple):
|
||||||
@ -79,25 +95,21 @@ def command(cmd, subcommand, usage=None, description=None):
|
|||||||
|
|
||||||
if not success and not msg:
|
if not success and not msg:
|
||||||
# Failure, no message, print usage
|
# Failure, no message, print usage
|
||||||
usage_embed = discord.Embed()
|
usage_str = "**Usage:** {} {} {}".format(cmd, subcommand or "", usage or "")
|
||||||
usage_embed.colour = discord.Colour.blue()
|
await client.send_message(message.channel, embed=make_default_embed(usage_str))
|
||||||
usage_embed.add_field(
|
|
||||||
name="Usage", value=usage, inline=False)
|
|
||||||
|
|
||||||
await client.send_message(message.channel, embed=usage_embed)
|
|
||||||
elif not success:
|
elif not success:
|
||||||
# Failure, print message
|
# Failure, print message
|
||||||
error_embed = discord.Embed()
|
embed = msg if isinstance(msg, discord.Embed) else make_error_embed(msg)
|
||||||
error_embed.colour = discord.Colour.dark_red()
|
# embed.set_footer(text="{:.02f} ms".format(time_ms))
|
||||||
error_embed.description = msg
|
await client.send_message(message.channel, embed=embed)
|
||||||
await client.send_message(message.channel, embed=error_embed)
|
|
||||||
elif msg:
|
elif msg:
|
||||||
# Success, print message
|
# Success, print message
|
||||||
success_embed = discord.Embed()
|
embed = msg if isinstance(msg, discord.Embed) else make_default_embed(msg)
|
||||||
success_embed.colour = discord.Colour.blue()
|
# embed.set_footer(text="{:.02f} ms".format(time_ms))
|
||||||
success_embed.description = msg
|
await client.send_message(message.channel, embed=embed)
|
||||||
await client.send_message(message.channel, embed=success_embed)
|
|
||||||
# Success, don't print anything
|
# Success, don't print anything
|
||||||
|
|
||||||
|
# Put command in map
|
||||||
if cmd not in command_map:
|
if cmd not in command_map:
|
||||||
command_map[cmd] = {}
|
command_map[cmd] = {}
|
||||||
if subcommand not in command_map[cmd]:
|
if subcommand not in command_map[cmd]:
|
||||||
@ -133,7 +145,7 @@ def member_command(cmd, subcommand, usage=None, description=None, system_only=Tr
|
|||||||
return False, "Can't find member \"{}\".".format(args[0])
|
return False, "Can't find member \"{}\".".format(args[0])
|
||||||
|
|
||||||
return await func(conn, message, member, args[1:])
|
return await func(conn, message, member, args[1:])
|
||||||
return command(cmd=cmd, subcommand=subcommand, usage=usage, description=description)(wrapper)
|
return command(cmd=cmd, subcommand=subcommand, usage="<name|id> {}".format(usage or ""), description=description)(wrapper)
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user