mirror of
https://github.com/Ryujinx/ryuko-ng.git
synced 2024-12-23 12:05:36 +00:00
formatting fixes and fix for custom emojis
This commit is contained in:
parent
7fecf73ff0
commit
687a26105d
44
cogs/mod.py
44
cogs/mod.py
|
@ -613,7 +613,9 @@ class Mod:
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.check(check_if_staff)
|
@commands.check(check_if_staff)
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def clearreactsbyuser(self, ctx, user: discord.Member, *, channel: discord.TextChannel = None, limit: int = 50):
|
async def clearreactsbyuser(self, ctx, user: discord.Member, *,
|
||||||
|
channel: discord.TextChannel = None,
|
||||||
|
limit: int = 50):
|
||||||
"""Clears reacts from a given user in the given channel, staff only."""
|
"""Clears reacts from a given user in the given channel, staff only."""
|
||||||
log_channel = self.bot.get_channel(config.log_channel)
|
log_channel = self.bot.get_channel(config.log_channel)
|
||||||
if not channel:
|
if not channel:
|
||||||
|
@ -621,19 +623,22 @@ class Mod:
|
||||||
count = 0
|
count = 0
|
||||||
async for msg in channel.history(limit=limit):
|
async for msg in channel.history(limit=limit):
|
||||||
for react in msg.reactions:
|
for react in msg.reactions:
|
||||||
if (await react.users().find(lambda u: u == user)) is not None:
|
if await react.users().find(lambda u: u == user):
|
||||||
count = count + 1
|
count+= 1
|
||||||
async for u in react.users():
|
async for u in react.users():
|
||||||
await msg.remove_reaction(react, u)
|
await msg.remove_reaction(react, u)
|
||||||
msg = f"✏️ **Cleared reacts**: {ctx.author.mention} cleared {user.mention}'s "\
|
msg = f"✏️ **Cleared reacts**: {ctx.author.mention} cleared "\
|
||||||
f"reacts from the last {limit} messages in {channel.mention}."
|
f"{user.mention}'s reacts from the last {limit} messages "\
|
||||||
|
f"in {channel.mention}."
|
||||||
await ctx.channel.send(f"Cleared {count} unique reactions")
|
await ctx.channel.send(f"Cleared {count} unique reactions")
|
||||||
await log_channel.send(msg)
|
await log_channel.send(msg)
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.check(check_if_staff)
|
@commands.check(check_if_staff)
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def clearallreacts(self, ctx, *, limit: int = 50, channel: discord.TextChannel = None):
|
async def clearallreacts(self, ctx, *,
|
||||||
|
limit: int = 50,
|
||||||
|
channel: discord.TextChannel = None):
|
||||||
"""Clears all reacts in a given channel, staff only. Use with care."""
|
"""Clears all reacts in a given channel, staff only. Use with care."""
|
||||||
log_channel = self.bot.get_channel(config.log_channel)
|
log_channel = self.bot.get_channel(config.log_channel)
|
||||||
if not channel:
|
if not channel:
|
||||||
|
@ -641,7 +646,7 @@ class Mod:
|
||||||
count = 0
|
count = 0
|
||||||
async for msg in channel.history(limit=limit):
|
async for msg in channel.history(limit=limit):
|
||||||
if msg.reactions:
|
if msg.reactions:
|
||||||
count = count + 1
|
count+= 1
|
||||||
await msg.clear_reactions()
|
await msg.clear_reactions()
|
||||||
msg = f"✏️ **Cleared reacts**: {ctx.author.mention} cleared all "\
|
msg = f"✏️ **Cleared reacts**: {ctx.author.mention} cleared all "\
|
||||||
f"reacts from the last {limit} messages in {channel.mention}."
|
f"reacts from the last {limit} messages in {channel.mention}."
|
||||||
|
@ -655,7 +660,8 @@ class Mod:
|
||||||
"""Clears reacts interactively, staff only. Use with care."""
|
"""Clears reacts interactively, staff only. Use with care."""
|
||||||
log_channel = self.bot.get_channel(config.log_channel)
|
log_channel = self.bot.get_channel(config.log_channel)
|
||||||
|
|
||||||
msg_text = f"{ctx.author.mention}, react to the reactions you want to remove. React to this message when you're done."
|
msg_text = f"{ctx.author.mention}, react to the reactions you want "\
|
||||||
|
f"to remove. React to this message when you're done."
|
||||||
msg = await ctx.channel.send(msg_text)
|
msg = await ctx.channel.send(msg_text)
|
||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
|
@ -670,25 +676,35 @@ class Mod:
|
||||||
else:
|
else:
|
||||||
# remove a reaction
|
# remove a reaction
|
||||||
async def impl():
|
async def impl():
|
||||||
msg = await self.bot.get_guild(event.guild_id).get_channel(event.channel_id).get_message(event.message_id)
|
msg = await self.bot \
|
||||||
|
.get_guild(event.guild_id) \
|
||||||
|
.get_channel(event.channel_id) \
|
||||||
|
.get_message(event.message_id)
|
||||||
def check_emoji(r):
|
def check_emoji(r):
|
||||||
|
if event.emoji.is_custom_emoji() == r.custom_emoji:
|
||||||
if event.emoji.is_custom_emoji():
|
if event.emoji.is_custom_emoji():
|
||||||
return event.emoji.id == r.emoji.id
|
return event.emoji.id == r.emoji.id
|
||||||
else:
|
else:
|
||||||
return event.emoji.name == r.emoji # gotta love consistent APIs
|
# gotta love consistent APIs
|
||||||
|
return event.emoji.name == r.emoji
|
||||||
|
else:
|
||||||
|
return False
|
||||||
for reaction in filter(check_emoji, msg.reactions):
|
for reaction in filter(check_emoji, msg.reactions):
|
||||||
async for u in reaction.users():
|
async for u in reaction.users():
|
||||||
await reaction.message.remove_reaction(reaction, u)
|
await reaction.message.remove_reaction(reaction, u)
|
||||||
tasks.append(asyncio.create_task(impl())) # schedule immediately
|
# schedule immediately
|
||||||
|
tasks.append(asyncio.create_task(impl()))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.bot.wait_for("raw_reaction_add", timeout=120.0, check=check)
|
await self.bot.wait_for("raw_reaction_add",
|
||||||
|
timeout=120.0,
|
||||||
|
check=check)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
await msg.edit(content = msg_text + " Timed out.")
|
await msg.edit(content = f"{msg_text} Timed out.")
|
||||||
else:
|
else:
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
await msg.edit(content = msg_text + " Done!")
|
await msg.edit(content = f"{msg_text} Done!")
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Mod(bot))
|
bot.add_cog(Mod(bot))
|
||||||
|
|
Loading…
Reference in a new issue