async def purge(self, ctx, num=5, type=None, filter=None): num += 1 if not isinstance(num, int): await ctx.send("Please pass in a number of messages to delete.") return no_older_than = datetime.datetime.utcnow() - datetime.timedelta( days=14) + datetime.timedelta(seconds=1) if type: type = type.lower() if type == 'all': def check(msg): return True elif type == 'contains': def check(msg): return str(filter).lower() in msg.content.lower() elif type == 'from': try: converter = utils.MemberLookupConverter() mem = await converter.convert(ctx, filter) except discord.ext.commands.BadArgument as e: return ctx.send( f"No members found with the name: {filter}") def check(msg): return msg.author == mem else: return await ctx.send( f'`{type}` is not a valid filter type! Please choose from "all", "contains", "from"' ) else: def check(msg): return not msg.pinned messages = await ctx.channel.purge(limit=num, check=check, after=no_older_than, bulk=True) # if len(messages) < num: # return await ctx.send("You are trying to delete messages that are older than 15 days. Discord API doesn't " # "allow bots to do this!\nYou can use the nuke command to completely clean a " # "channel.", delete_after=10) await ctx.send(f"Deleted {len(messages) - 1} messages.", delete_after=5)
async def parsemembers(self, ctx): if not ctx.message.attachments: return await ctx.send( "Please attach an image containing only the result of the /who command!", delete_after=10) if len(ctx.message.attachments) > 1: return await ctx.send("Please only attach 1 image.", delete_after=10) attachment = ctx.message.attachments[0] if not attachment.height or 'mp4' in attachment.filename.lower( ) or 'mov' in attachment.filename.lower(): return await ctx.send( "Please only attach an image of type 'png' or 'jpg'.", delete_after=10) image = io.BytesIO() await attachment.save(image, seek_begin=True) if ctx.author.voice: vcchannel = ctx.author.voice.channel else: setup = VCSelect(self.client, ctx, parse=True) data = await setup.start() if isinstance(data, tuple): (raidnum, inraiding, invet, inevents, raiderrole, rlrole, hcchannel, vcchannel, setup_msg) = data else: return await setup_msg.delete() msg: discord.Message = await ctx.send( "Parsing image. This may take a minute...") res = await self.client.loop.run_in_executor( None, functools.partial(parse_image, ctx.author, image, vcchannel, True)) if not res: embed = discord.Embed( title="Error!", description= "Could not find the who command in the image you provided.\nPlease re-run the " "command with an image that shows the results of `/who`.", color=discord.Color.red()) await msg.delete() return await ctx.send(embed=embed) crashing, possible_alts, fixed_names = res await msg.edit(content="Parsing members. Please wait...") n_crashers = len(crashing) crashing_members = [] converter = utils.MemberLookupConverter() pages = [] nm_crashing = [] crashing_players = [] for n in crashing: try: mem = await converter.convert(ctx, n) except discord.ext.commands.BadArgument: crashing_players.append(n) for m in crashing_members: n_suspensions = 0 active_suspension = "❌" pdata = await sql.get_users_punishments(self.client.pool, m.id, ctx.guild.id) bdata = await sql.get_blacklist(self.client.pool, m.id, ctx.guild.id) pembed = discord.Embed( description= f"**Punishment Log for {m.mention}** - `{m.display_name}`") if pdata: for i, r in enumerate(pdata, start=1): requester = ctx.guild.get_member(r[sql.punish_cols.r_uid]) active = "✅" if r[sql.punish_cols.active] else "❌" starttime = f"Issued at: `{r[sql.punish_cols.starttime].strftime('%b %d %Y %H:%M:%S')}`" endtime = f"\nEnded at: `{r[sql.punish_cols.endtime].strftime('%b %d %Y %H:%M:%S')}`" if r[ sql.punish_cols.endtime] else "" ptype = r[sql.punish_cols.type].capitalize() pembed.add_field( name=f"{ptype} #{i} | Active {active}", value= f"Issued by: {requester.mention if requester else '(Issuer left server)'}\nReason:\n{r[sql.punish_cols.reason]}\n{starttime}\n" f"{endtime}", inline=False) if r[sql.punish_cols.active] and ptype == 'Suspend': active_suspension = active if ptype == 'Suspend': n_suspensions += 1 if bdata: for i, r in enumerate(bdata, start=1): requester = ctx.guild.get_member(r[sql.blacklist_cols.rid]) active = "✅" starttime = f"Issued at: `{r[sql.blacklist_cols.issuetime].strftime('%b %d %Y %H:%M:%S')}`" btype = r[sql.blacklist_cols.type].capitalize() pembed.add_field( name= f"{btype} #{i} issued by {requester.mention if requester else '(Issuer left server)'} | Active {active}", value= f"Reason:\n{r[sql.punish_cols.reason]}\n{starttime}") if pdata or bdata: pembed.description += f"\nFound `{len(pdata)}` Punishments in this user's history.\nFound `{len(bdata)}` Blacklists in this users history." pages.append(pembed) nm_crashing.append((m, n_suspensions, active_suspension)) mstring = "" nm_crashing = sorted(nm_crashing, key=lambda x: x[1], reverse=True) for r in nm_crashing: mstring += f"{r[0].mention} **-** `{r[0].display_name}`\nSuspensions: **{r[1]}** | Active: {r[2]}\n" if not mstring: mstring = "No members crashing!" embed = discord.Embed( title=f"Parsing Results for {vcchannel.name}", description=f"Possible Crashers: **{n_crashers}**", color=discord.Color.orange()) if len(mstring) > 1024: lines = mstring.splitlines(keepends=True) curr_str = "" n_sections = 1 for l in lines: if len(l) + len(curr_str) >= 1024: embed.add_field( name= f"Members Crashing (in the server) ({n_sections}):", value=curr_str, inline=True) curr_str = l n_sections += 1 else: curr_str += l embed.add_field( name=f"Members Crashing (in the server) ({n_sections}):", value=curr_str, inline=True) else: embed.add_field(name="Members Crashing (in the server):", value=mstring, inline=True) pstring = "\n".join( crashing_players ) if crashing_players else 'No players who are not in the server crashing.' embed.add_field(name="Players Crashing (not in server):", value=pstring, inline=False) if fixed_names: fixedlist = " Fixed Name | Original Parse".join( "`/kick " + fixed + "` | (" + orig + ")\n" for (orig, fixed) in fixed_names) embed.add_field(name="Possible Fixed Names", value=fixedlist, inline=True) if possible_alts: altlist = "".join("`" + name + "`\n" for name in possible_alts) embed.add_field(name="Possible Alts (In VC but not in game)", value=altlist, inline=True) pages.insert(0, embed) await msg.delete() paginator = utils.EmbedPaginator(self.client, ctx, pages) await paginator.paginate()