Ban updates2.0
Description
- ban() now uses guild.ban() to facilitate clearing messages because its instant and the slowness of the previous method was not liked. also sometimes the clearing of messages just wouldn't work
- wall_e_models have been updated. PR: https://github.com/CSSS/wall_e_models/pull/7
- intercept updated to use halting problem to capture audit log data, will reduce the number of failures if discord takes longer to generate the audit entry
- removed all intermediate message, prevents clutter from mod report channel
- all responses are sent to mod channel instead of responding to the interaction
- updated default ban reason
- ~~embed utility was dropped for most commands in Ban, was unnecessary for most of the embeds since they're deterministic in size~~
- no more getting discrimintors for users since they were phased out last year, now pulling from user.name()
@modernNeo
Seems my first branch has some commits from master that've since been removed. So I made this fresh branch and cherry picked my commits over.
please add the embed helper back. the checks against the text sizes was just 1 thing it does. hint take a look at line of code under 180 on embed.py
The embeds in ban that I changed don't set author or author icon, so there's no need for the utility.
Not using the embed utilitiy function made the code simpler plus its faster:
Run # 1 discord.Embed avg time: 0.0000404119 utility.embed avg time: 0.0001147270 discord.Embed is 2.8389 times faster than utility.embed
Run # 2 discord.Embed avg time: 0.0000305653 utility.embed avg time: 0.0001038313 discord.Embed is 3.3970 times faster than utility.embed
Run # 3 discord.Embed avg time: 0.0000303030 utility.embed avg time: 0.0000788689 discord.Embed is 2.6027 times faster than utility.embed
Run # 4 discord.Embed avg time: 0.0000374556 utility.embed avg time: 0.0000818253 discord.Embed is 2.1846 times faster than utility.embed
Run # 5 discord.Embed avg time: 0.0000367880 utility.embed avg time: 0.0000920296 discord.Embed is 2.5016 times faster than utility.embed
Run # 6 discord.Embed avg time: 0.0000489712 utility.embed avg time: 0.0000953436 discord.Embed is 1.9469 times faster than utility.embed
Run # 7 discord.Embed avg time: 0.0000379562 utility.embed avg time: 0.0000935793 discord.Embed is 2.4655 times faster than utility.embed
Run # 8 discord.Embed avg time: 0.0000402689 utility.embed avg time: 0.0000868082 discord.Embed is 2.1557 times faster than utility.embed
Run # 9 discord.Embed avg time: 0.0000540733 utility.embed avg time: 0.0001094818 discord.Embed is 2.0247 times faster than utility.embed
Run # 10 discord.Embed avg time: 0.0000351906 utility.embed avg time: 0.0001027107 discord.Embed is 2.9187 times faster than utility.embed
Fast Factors [ 2.8389, 3.3970, 2.6027, 2.1846, 2.5016, 1.9469, 2.4655, 2.1557, 2.0247, 2.9187] Avg: 2.5036
code i used for the tests. called .go 10. measures time for creation of embed.
@commands.command()
async def go(self, ctx, num: int):
times = [0 for _ in range(1, num+1)]
for idx in range(1, num+1):
await ctx.send(f"**Run #{idx}**")
times[idx-1] = await self.time(ctx)
avg = sum(times)/num
times = (
"**Fast Factor**\n"
f"[ {', '.join([f'{t:.4f}' for t in times])}]\n"
f"Avg: {avg:.4f}"
)
await ctx.send(times)
@commands.command()
async def time(self, ctx):
times = [0 for _ in range(1, 11)]
times2 = [0 for _ in range(1, 11)]
ban_date = pstdatetime.now()
for idx in range(1, 11):
start = time.time()
e_obj = discord.Embed(title=f"Time testing #{idx}", color=discord.Color.red())
e_obj.add_field(name="Banned User", value=f"**Username**")
e_obj.add_field(name="Moderator", value=f"**Mod Name**")
e_obj.add_field(name="Reason", value=f"```Ban Reason```", inline=False)
e_obj.add_field(name="User Notified via DM", value="No", inline=False)
e_obj.set_footer(text="Moderator Action")
e_obj.timestamp = ban_date
end = time.time()
times[idx-1] = end - start
await asyncio.sleep(1)
for idx in range(1, 11):
start = time.time()
content = [
("Banned User", "**Username**", True),
("Moderator", "**Mod Name**", True),
("Reason", "```Ban Reason```", False),
("User Notified via DM", "No", False)
]
e_obj = await embed(
logger=self.logger,
ctx=ctx,
title=f"Time testing #{idx}",
colour=WallEColour.ERROR,
content=content,
footer_text="Moderator Action",
timestamp=ban_date
)
if e_obj:
end = time.time()
times2[idx - 1] = end - start
await asyncio.sleep(1)
av1 = sum(times)/10
av2 = sum(times2)/10
fast = av2/av1
await ctx.send(
(f"discord.Embed avg time: `{av1:.10f}`\n"
f"utility.embed avg time: `{av2:.10f}`\n"
f"discord.Embed is `{fast:.4f}` times faster than utility.embed")
)
return fast
please use the wall_e embed utility to ensure consistency and then I will take a look
Done.
also sometimes the clearing of messages just wouldn't work
were you able to reproduce this bug? I am fine with removing the logic that I think I put in [?] but I am now curious if it was a bug in the code I wrote or a bug in discord.py
also sometimes the clearing of messages just wouldn't work
were you able to reproduce this bug? I am fine with removing the logic that I think I put in [?] but I am now curious if it was a bug in the code I wrote or a bug in discord.py
Honestly, it's pretty random. Some bans it'll go delete message other times it just says it's done without actually doing any deleting. No errors in the logs either.
i have updated the embed function so you can choose to call it with validate=False so that it just does the embed creation without validation. should help with runtime. you can use that new flag if you want since you were complaining about the runtime.
beyond that, just the one minor style fix and this should be merge-able.