Add fancy rich table to update message
This commit is contained in:
parent
16d7ef940e
commit
7110fb1db5
1 changed files with 60 additions and 3 deletions
|
@ -13,6 +13,7 @@ from dis_snek.client.utils.misc_utils import find
|
|||
from dis_snek.models.discord.embed import EmbedField
|
||||
from dis_snek.models.discord.file import File
|
||||
from molter import msg_command
|
||||
from rich.table import Table
|
||||
|
||||
from jarvis.utils import build_embed, get_all_commands
|
||||
|
||||
|
@ -87,18 +88,23 @@ class BotutilCog(Scale):
|
|||
if current_hash != remote_hash:
|
||||
self.logger.info("Updating...")
|
||||
current_commands = get_all_commands()
|
||||
origin.pull()
|
||||
changes = origin.pull()
|
||||
|
||||
self.logger.info("Changes pulled...")
|
||||
self.logger.debug("Sleeping for 3 seconds to allow changes")
|
||||
await asyncio.sleep(3)
|
||||
self.logger.debug("Finished sleeping, loading new commands")
|
||||
|
||||
reloaded = []
|
||||
new_commands = get_all_commands()
|
||||
for module, commands in new_commands.items():
|
||||
self.logger.debug(f"Processing {module}")
|
||||
if module not in current_commands:
|
||||
self.bot.load_extension(module)
|
||||
reloaded.append(module)
|
||||
elif len(current_commands[module]) != len(commands):
|
||||
self.bot.reload_extension(module)
|
||||
reloaded.append(module)
|
||||
else:
|
||||
for command in commands:
|
||||
old_command = find(
|
||||
|
@ -108,16 +114,67 @@ class BotutilCog(Scale):
|
|||
new_args = get_type_hints(command)
|
||||
if len(old_args) != len(new_args):
|
||||
self.bot.reload_extension(module)
|
||||
reloaded.append(module)
|
||||
elif any(x not in old_args for x in new_args) or any(
|
||||
x not in new_args for x in old_args
|
||||
):
|
||||
self.bot.reload_extension(module)
|
||||
reloaded.append(module)
|
||||
elif any(new_args[x] != y for x, y in old_args):
|
||||
self.bot.reload_extension(module)
|
||||
reloaded.append(module)
|
||||
|
||||
file_changes = {}
|
||||
for change in changes:
|
||||
if change.commit.hexsha == current_hash:
|
||||
break
|
||||
files = change.commit.stats.files
|
||||
for file, stats in files.items():
|
||||
if file not in file_changes:
|
||||
file_changes[file] = {"insertions": 0, "deletions": 0, "lines": 0}
|
||||
for k, v in stats.items():
|
||||
file_changes[file][k] += v
|
||||
|
||||
table = Table(title="File Changes")
|
||||
|
||||
table.add_column("File", justify="left", style="white", no_wrap=True)
|
||||
table.add_column("Insertions", justify="center", style="green")
|
||||
table.add_column("Deletions", justify="center", style="red")
|
||||
table.add_column("Lines", justify="center", style="magenta")
|
||||
|
||||
i_total = 0
|
||||
d_total = 0
|
||||
l_total = 0
|
||||
for file, stats in file_changes.items():
|
||||
i_total += stats["insertions"]
|
||||
d_total += stats["deletions"]
|
||||
l_total += stats["lines"]
|
||||
table.add_row(
|
||||
file,
|
||||
str(stats["insertions"]),
|
||||
str(stats["deletions"]),
|
||||
str(stats["lines"]),
|
||||
)
|
||||
|
||||
table.add_row("Total", str(i_total), str(d_total), str(l_total))
|
||||
|
||||
fields = [
|
||||
EmbedField(name="Old Commit", value=current_hash),
|
||||
EmbedField(name="New Commit", value=remote_hash),
|
||||
EmbedField(name="Files Changes", value=f"```ansi\n{table}\n```"),
|
||||
]
|
||||
|
||||
embed = build_embed(
|
||||
"Update Status", description="Updates have been applied", fields=fields
|
||||
)
|
||||
|
||||
self.logger.info("Updates applied")
|
||||
await ctx.reply(f"Updates applied! `{current_hash}` => `{remote_hash}`")
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
else:
|
||||
await ctx.reply(f"No updates to apply. `{current_hash}` == `{remote_hash}`")
|
||||
embed = build_embed(title="Update Status", description="No changes applied", fields=[])
|
||||
embed.set_footer(text=current_hash)
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
|
||||
def setup(bot: Snake) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue