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)
def _filter(
self,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
) -> List[Union[datetime, discord.Message]]:
ret: List[Union[datetime, discord.Message]] = []
@ -52,10 +49,7 @@ class RecentActivityRecord:
return ret
def conditional_count(
self,
*,
after: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
) -> int:
ret = len(self._filter(after=after, message_check=message_check))
@ -63,10 +57,7 @@ class RecentActivityRecord:
return ret
def conditional_remove(
self,
*,
before: Optional[datetime] = None,
message_check: Optional[MessagePredicate] = None,
self, *, before: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None,
):
if 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)
def get_active_for_guild(
self,
*,
guild: discord.Guild,
after: datetime,
message_check: Optional[MessagePredicate] = None,
self, *, guild: discord.Guild, after: datetime, message_check: Optional[MessagePredicate] = None,
) -> Iterator[discord.Member]:
with contextlib.suppress(KeyError):

View file

@ -587,12 +587,7 @@ class MoreAdmin(commands.Cog):
@checks.admin_or_permissions(administrator=True)
@checks.bot_has_permissions(kick_members=True)
async def purge(
self,
ctx,
role: discord.Role,
check_messages: bool = True,
*,
threshold: str = None,
self, ctx, role: discord.Role, check_messages: bool = True, *, threshold: str = None,
):
"""
Purge inactive users with role.
@ -799,7 +794,7 @@ class MoreAdmin(commands.Cog):
@commands.command(hidden=True)
@commands.guild_only()
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.guild_only()
@ -839,7 +834,7 @@ class MoreAdmin(commands.Cog):
Sends a message to a channel from Aurelia.
"""
try:
await channel.send(msg)
await channel.send(msg, allowed_mentions=discord.AllowedMentions())
except:
await ctx.send("Could not send message in that channel.")
@ -891,6 +886,33 @@ class MoreAdmin(commands.Cog):
else:
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.guild_only()
@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)
@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()
async def on_guild_emojis_update(self, guild, before, after):
b_e = set(before)

View file

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

View file

@ -50,11 +50,7 @@ MAX_EMBED = 25
class RoleManagement(
UtilMixin,
MassManagementMixin,
EventMixin,
commands.Cog,
metaclass=CompositeMetaClass,
UtilMixin, MassManagementMixin, EventMixin, commands.Cog, metaclass=CompositeMetaClass,
):
"""
Cog for role management
@ -312,12 +308,7 @@ class RoleManagement(
@checks.admin_or_permissions(manage_guild=True)
@commands.command(name="rolebind")
async def bind_role_to_reactions(
self,
ctx: GuildContext,
role: discord.Role,
channel: discord.TextChannel,
msgid: int,
emoji: str,
self, ctx: GuildContext, role: discord.Role, channel: discord.TextChannel, msgid: int, emoji: str,
):
"""
Binds a role to a reaction on a message...
@ -356,11 +347,7 @@ class RoleManagement(
cfg = self.config.custom("REACTROLE", str(message.id), eid)
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(
f"Remember, the reactions only function according to "
@ -1048,11 +1035,7 @@ class RoleManagement(
channel_id = data.get("channelid", None)
if channel_id:
link = linkfmt.format(
guild_id=role.guild.id,
channel_id=channel_id,
message_id=message_id,
)
link = linkfmt.format(guild_id=role.guild.id, channel_id=channel_id, message_id=message_id,)
else:
link = (
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")
async def mrole_user(
self,
ctx: GuildContext,
users: commands.Greedy[discord.Member],
*,
_query: RoleSyntaxConverter,
self, ctx: GuildContext, users: commands.Greedy[discord.Member], *, _query: RoleSyntaxConverter,
) -> None:
"""
adds/removes roles to one or more users
@ -249,8 +245,7 @@ class MassManagementMixin(MixinMeta):
filename += f"-part{part}"
filename += ".csv"
await ctx.send(
content=f"Data for {ctx.author.mention}",
files=[discord.File(data, filename=filename)],
content=f"Data for {ctx.author.mention}", files=[discord.File(data, filename=filename)],
)
csvf.close()
data.close()
@ -304,17 +299,11 @@ class MassManagementMixin(MixinMeta):
await self.update_roles_atomically(who=member, give=query["add"], remove=query["remove"])
except RoleManagementException:
log.debug(
"Internal filter failure on member id %d guild id %d query %s",
member.id,
ctx.guild.id,
query,
"Internal filter failure on member id %d guild id %d query %s", member.id, ctx.guild.id, query,
)
except discord.HTTPException:
log.debug(
"Unpredicted failure for member id %d in guild id %d query %s",
member.id,
ctx.guild.id,
query,
"Unpredicted failure for member id %d in guild id %d query %s", member.id, ctx.guild.id, query,
)
await ctx.tick()

View file

@ -79,11 +79,7 @@ class UtilMixin(MixinMeta):
return variation_stripper_re.sub("", s)
async def update_roles_atomically(
self,
*,
who: discord.Member,
give: List[discord.Role] = None,
remove: List[discord.Role] = None,
self, *, 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

View file

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

View file

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

View file

@ -70,12 +70,7 @@ class Task:
with contextlib.suppress(AttributeError, ValueError):
yield cls(
initial=initial,
recur=recur,
channel=channel,
author=author,
uid=uid,
**data,
initial=initial, recur=recur, channel=channel, author=author, uid=uid, **data,
)
@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})")
return None
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.")
async def __get_random_message_format(self, guild: discord.guild, event: str) -> str: