black formatting, bunch of small updates and bug fixes

This commit is contained in:
brandons209 2020-09-30 00:31:20 -04:00
parent f9352218dd
commit e17235fef4
11 changed files with 65 additions and 89 deletions

View file

@ -27,10 +27,7 @@ class RecentActivityRecord:
return len(self.activities) + len(self.messages) return len(self.activities) + len(self.messages)
def _filter( def _filter(
self, self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
) -> List[Union[datetime, discord.Message]]: ) -> List[Union[datetime, discord.Message]]:
ret: List[Union[datetime, discord.Message]] = [] ret: List[Union[datetime, discord.Message]] = []
@ -52,10 +49,7 @@ class RecentActivityRecord:
return ret return ret
def conditional_count( def conditional_count(
self, self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
) -> int: ) -> int:
ret = len(self._filter(after=after, message_check=message_check)) ret = len(self._filter(after=after, message_check=message_check))
@ -63,10 +57,7 @@ class RecentActivityRecord:
return ret return ret
def conditional_remove( def conditional_remove(
self, self, *, before: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
*,
before: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
): ):
if before: if before:
self.activities = [a for a in self.activities if a > before] self.activities = [a for a in self.activities if a > before]
@ -109,11 +100,7 @@ class RecordHandler:
self.records[guild][member].add_message(message) self.records[guild][member].add_message(message)
def get_active_for_guild( def get_active_for_guild(
self, self, *, guild: discord.Guild, after: datetime, message_check: Optional[MessagePredicate] = None,
*,
guild: discord.Guild,
after: datetime,
message_check: Optional[MessagePredicate] = None,
) -> Iterator[discord.Member]: ) -> Iterator[discord.Member]:
with contextlib.suppress(KeyError): with contextlib.suppress(KeyError):

View file

@ -587,12 +587,7 @@ class MoreAdmin(commands.Cog):
@checks.admin_or_permissions(administrator=True) @checks.admin_or_permissions(administrator=True)
@checks.bot_has_permissions(kick_members=True) @checks.bot_has_permissions(kick_members=True)
async def purge( async def purge(
self, self, ctx, role: discord.Role, check_messages: bool = True, *, threshold: str = None,
ctx,
role: discord.Role,
check_messages: bool = True,
*,
threshold: str = None,
): ):
""" """
Purge inactive users with role. Purge inactive users with role.
@ -799,7 +794,7 @@ class MoreAdmin(commands.Cog):
@commands.command(hidden=True) @commands.command(hidden=True)
@commands.guild_only() @commands.guild_only()
async def say(self, ctx, *, content: str): async def say(self, ctx, *, content: str):
await ctx.send(escape(content, mass_mentions=True)) await ctx.send(escape(content, mass_mentions=True), allowed_mentions=discord.AllowedMentions())
@commands.command(hidden=True) @commands.command(hidden=True)
@commands.guild_only() @commands.guild_only()
@ -839,7 +834,7 @@ class MoreAdmin(commands.Cog):
Sends a message to a channel from Aurelia. Sends a message to a channel from Aurelia.
""" """
try: try:
await channel.send(msg) await channel.send(msg, allowed_mentions=discord.AllowedMentions())
except: except:
await ctx.send("Could not send message in that channel.") await ctx.send("Could not send message in that channel.")
@ -891,6 +886,33 @@ class MoreAdmin(commands.Cog):
else: else:
await ctx.send("{}".format(escape(message.content, formatting=True, mass_mentions=True))) await ctx.send("{}".format(escape(message.content, formatting=True, mass_mentions=True)))
@commands.command()
@commands.guild_only()
@checks.mod()
async def getall(self, ctx, channel: discord.TextChannel, message_id: int):
"""
Gets ALL messages with it's formatting from Aurelia after the specified message.
For now, limit is 100 messages
"""
messages = []
try:
message = await channel.fetch_message(message_id)
except:
await ctx.send("Sorry, that message could not be found.")
return
async for m in channel.history(limit=100, after=message.created_at):
if m.author == ctx.guild.me:
messages.append(m)
for message in messages:
if message.content == "":
await ctx.send("(no message content)")
else:
await ctx.send("{}".format(escape(message.content, formatting=True, mass_mentions=True)))
await asyncio.sleep(0.2)
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@checks.admin_or_permissions(administrator=True) @checks.admin_or_permissions(administrator=True)

View file

@ -310,6 +310,18 @@ class NitroEmoji(commands.Cog):
await self.del_emoji(after.guild, after, emoji=emoji, reason=reason) await self.del_emoji(after.guild, after, emoji=emoji, reason=reason)
@commands.Cog.listener()
async def on_member_leave(self, member):
# remove all member emojis on leave
emojis = await self.config.member(member).emojis()
for emoji in emojis:
emoji = self.find_emoji(member.guild, emoji)
if not emoji:
continue
await self.del_emoji(member.guild, member, emoji=emoji, reason="Member left.")
await self.config.member(member).clear()
@commands.Cog.listener() @commands.Cog.listener()
async def on_guild_emojis_update(self, guild, before, after): async def on_guild_emojis_update(self, guild, before, after):
b_e = set(before) b_e = set(before)

View file

@ -98,9 +98,7 @@ class PersonalRoles(commands.Cog):
dic = { dic = {
_("User"): ctx.guild.get_member(member) or f"[X] {member}", _("User"): ctx.guild.get_member(member) or f"[X] {member}",
_("Role"): shorten( _("Role"): shorten(
str(ctx.guild.get_role(data["role"]) or "[X] {}".format(data["role"])), str(ctx.guild.get_role(data["role"]) or "[X] {}".format(data["role"])), 32, placeholder="",
32,
placeholder="",
), ),
} }
assigned_roles.append(dic) assigned_roles.append(dic)

View file

@ -50,11 +50,7 @@ MAX_EMBED = 25
class RoleManagement( class RoleManagement(
UtilMixin, UtilMixin, MassManagementMixin, EventMixin, commands.Cog, metaclass=CompositeMetaClass,
MassManagementMixin,
EventMixin,
commands.Cog,
metaclass=CompositeMetaClass,
): ):
""" """
Cog for role management Cog for role management
@ -312,12 +308,7 @@ class RoleManagement(
@checks.admin_or_permissions(manage_guild=True) @checks.admin_or_permissions(manage_guild=True)
@commands.command(name="rolebind") @commands.command(name="rolebind")
async def bind_role_to_reactions( async def bind_role_to_reactions(
self, self, ctx: GuildContext, role: discord.Role, channel: discord.TextChannel, msgid: int, emoji: str,
ctx: GuildContext,
role: discord.Role,
channel: discord.TextChannel,
msgid: int,
emoji: str,
): ):
""" """
Binds a role to a reaction on a message... Binds a role to a reaction on a message...
@ -356,11 +347,7 @@ class RoleManagement(
cfg = self.config.custom("REACTROLE", str(message.id), eid) cfg = self.config.custom("REACTROLE", str(message.id), eid)
await cfg.set( await cfg.set(
{ {"roleid": role.id, "channelid": message.channel.id, "guildid": role.guild.id,}
"roleid": role.id,
"channelid": message.channel.id,
"guildid": role.guild.id,
}
) )
await ctx.send( await ctx.send(
f"Remember, the reactions only function according to " f"Remember, the reactions only function according to "
@ -1048,11 +1035,7 @@ class RoleManagement(
channel_id = data.get("channelid", None) channel_id = data.get("channelid", None)
if channel_id: if channel_id:
link = linkfmt.format( link = linkfmt.format(guild_id=role.guild.id, channel_id=channel_id, message_id=message_id,)
guild_id=role.guild.id,
channel_id=channel_id,
message_id=message_id,
)
else: else:
link = ( link = (
f"unknown message with id {message_id}" f" (use `roleset fixup` to find missing data for this)" f"unknown message with id {message_id}" f" (use `roleset fixup` to find missing data for this)"

View file

@ -124,11 +124,7 @@ class MassManagementMixin(MixinMeta):
@mrole.command(name="user") @mrole.command(name="user")
async def mrole_user( async def mrole_user(
self, self, ctx: GuildContext, users: commands.Greedy[discord.Member], *, _query: RoleSyntaxConverter,
ctx: GuildContext,
users: commands.Greedy[discord.Member],
*,
_query: RoleSyntaxConverter,
) -> None: ) -> None:
""" """
adds/removes roles to one or more users adds/removes roles to one or more users
@ -249,8 +245,7 @@ class MassManagementMixin(MixinMeta):
filename += f"-part{part}" filename += f"-part{part}"
filename += ".csv" filename += ".csv"
await ctx.send( await ctx.send(
content=f"Data for {ctx.author.mention}", content=f"Data for {ctx.author.mention}", files=[discord.File(data, filename=filename)],
files=[discord.File(data, filename=filename)],
) )
csvf.close() csvf.close()
data.close() data.close()
@ -304,17 +299,11 @@ class MassManagementMixin(MixinMeta):
await self.update_roles_atomically(who=member, give=query["add"], remove=query["remove"]) await self.update_roles_atomically(who=member, give=query["add"], remove=query["remove"])
except RoleManagementException: except RoleManagementException:
log.debug( log.debug(
"Internal filter failure on member id %d guild id %d query %s", "Internal filter failure on member id %d guild id %d query %s", member.id, ctx.guild.id, query,
member.id,
ctx.guild.id,
query,
) )
except discord.HTTPException: except discord.HTTPException:
log.debug( log.debug(
"Unpredicted failure for member id %d in guild id %d query %s", "Unpredicted failure for member id %d in guild id %d query %s", member.id, ctx.guild.id, query,
member.id,
ctx.guild.id,
query,
) )
await ctx.tick() await ctx.tick()

View file

@ -79,11 +79,7 @@ class UtilMixin(MixinMeta):
return variation_stripper_re.sub("", s) return variation_stripper_re.sub("", s)
async def update_roles_atomically( async def update_roles_atomically(
self, self, *, who: discord.Member, give: List[discord.Role] = None, remove: List[discord.Role] = None,
*,
who: discord.Member,
give: List[discord.Role] = None,
remove: List[discord.Role] = None,
): ):
""" """
Give and remove roles as a single op with some slight sanity Give and remove roles as a single op with some slight sanity

View file

@ -86,8 +86,7 @@ class SchedulerMessage(discord.Message):
) )
self.channel_mentions: List[discord.TextChannel] = list( self.channel_mentions: List[discord.TextChannel] = list(
filter( filter(
None, None, [self.guild.get_channel(idx) for idx in self.raw_channel_mentions], # type: ignore
[self.guild.get_channel(idx) for idx in self.raw_channel_mentions], # type: ignore
) )
) )
self.role_mentions: List[discord.Role] = list( self.role_mentions: List[discord.Role] = list(

View file

@ -175,10 +175,7 @@ class Scheduler(commands.Cog):
task.cancel() task.cancel()
async def red_delete_data_for_user( async def red_delete_data_for_user(
self, self, *, requester: Literal["discord_deleted_user", "owner", "user", "user_strict"], user_id: int,
*,
requester: Literal["discord_deleted_user", "owner", "user", "user_strict"],
user_id: int,
): ):
loaded_tasks = await self.fetch_task_by_attrs_exact(author=user_id) loaded_tasks = await self.fetch_task_by_attrs_exact(author=user_id)
if loaded_tasks: if loaded_tasks:
@ -431,8 +428,7 @@ class Scheduler(commands.Cog):
""" """
tasks = await self.fetch_task_by_attrs_lax( tasks = await self.fetch_task_by_attrs_lax(
lax={"uid": info, "nicename": info}, lax={"uid": info, "nicename": info}, strict={"author": ctx.author, "channel": ctx.channel},
strict={"author": ctx.author, "channel": ctx.channel},
) )
if not tasks: if not tasks:
@ -467,10 +463,7 @@ class Scheduler(commands.Cog):
await self.task_menu(ctx, tasks) await self.task_menu(ctx, tasks)
async def task_menu( async def task_menu(
self, self, ctx: commands.GuildContext, tasks: List[Task], message: Optional[discord.Message] = None,
ctx: commands.GuildContext,
tasks: List[Task],
message: Optional[discord.Message] = None,
): ):
color = await ctx.embed_color() color = await ctx.embed_color()
@ -577,7 +570,7 @@ class Scheduler(commands.Cog):
@helpers.command(name="say") @helpers.command(name="say")
async def say(self, ctx: commands.GuildContext, *, content: str): async def say(self, ctx: commands.GuildContext, *, content: str):
await ctx.send(content) await ctx.send(content, allowed_mentions=discord.AllowedMentions())
@helpers.command(name="selfwhisper") @helpers.command(name="selfwhisper")
async def swhisp(self, ctx: commands.GuildContext, *, content: str): async def swhisp(self, ctx: commands.GuildContext, *, content: str):

View file

@ -70,12 +70,7 @@ class Task:
with contextlib.suppress(AttributeError, ValueError): with contextlib.suppress(AttributeError, ValueError):
yield cls( yield cls(
initial=initial, initial=initial, recur=recur, channel=channel, author=author, uid=uid, **data,
recur=recur,
channel=channel,
author=author,
uid=uid,
**data,
) )
@property @property

View file

@ -816,7 +816,9 @@ class Welcome(commands.Cog):
log.error(f"Failed to send {event} message to channel ID {channel.id} (server ID {guild.id})") log.error(f"Failed to send {event} message to channel ID {channel.id} (server ID {guild.id})")
return None return None
except KeyError: except KeyError:
log.error(f"Failed to send {event} message to channel ID {channel.id} (server id {guild.id}) because there is an error in message formatting.") log.error(
f"Failed to send {event} message to channel ID {channel.id} (server id {guild.id}) because there is an error in message formatting."
)
return await channel.send(f"{box(format_str)} has an unknown key in brackets. Please fix this format.") return await channel.send(f"{box(format_str)} has an unknown key in brackets. Please fix this format.")
async def __get_random_message_format(self, guild: discord.guild, event: str) -> str: async def __get_random_message_format(self, guild: discord.guild, event: str) -> str: