Merge pull request #7 from brandons209/shroomdog27-black

Black format
This commit is contained in:
Brandon 2020-09-06 18:56:24 -04:00 committed by GitHub
commit 9a59fdd770
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 124 additions and 63 deletions

View file

@ -1132,7 +1132,7 @@ class ActivityLogger(commands.Cog):
@commands.guild_only() @commands.guild_only()
async def set_prefixes(self, ctx, *, prefixes: str = None): async def set_prefixes(self, ctx, *, prefixes: str = None):
"""Set list of prefixes to mark messages as bot commands for user stats. """Set list of prefixes to mark messages as bot commands for user stats.
Seperate prefixes with spaces Seperate prefixes with spaces
""" """
if not prefixes: if not prefixes:
curr = [f"`{p}`" for p in self.cache[ctx.guild.id]["prefixes"]] curr = [f"`{p}`" for p in self.cache[ctx.guild.id]["prefixes"]]

View file

@ -137,8 +137,8 @@ class Birthday(commands.Cog):
@bdayset.command(name="dmmessage") @bdayset.command(name="dmmessage")
async def bdayset_dm_message(self, ctx, *, message: str = None): async def bdayset_dm_message(self, ctx, *, message: str = None):
""" Set message DMed to users when its their birthday! """Set message DMed to users when its their birthday!
Leave empty to get/clear current message Leave empty to get/clear current message
""" """
if not message: if not message:
current = await self.config.guild(ctx.guild).dm_message() current = await self.config.guild(ctx.guild).dm_message()
@ -188,7 +188,7 @@ class Birthday(commands.Cog):
@bday.command(name="set") @bday.command(name="set")
async def bday_set(self, ctx, *, date: str = None): async def bday_set(self, ctx, *, date: str = None):
""" Set your birthday. Year not required. """Set your birthday. Year not required.
Date can be any valid date format, like: Date can be any valid date format, like:
05/20/99 05/20/99
05-20-99 05-20-99

View file

@ -22,9 +22,9 @@ class Confession(commands.Cog):
@confessionset.command(name="confess") @confessionset.command(name="confess")
async def confessionset_confess(self, ctx, *, channel: discord.TextChannel = None): async def confessionset_confess(self, ctx, *, channel: discord.TextChannel = None):
"""Set a confession room """Set a confession room
Leave empty to unset the room. Leave empty to unset the room.
**Make sure bot is able to embed messages in confession room.** **Make sure bot is able to embed messages in confession room.**
""" """
room = await self.config.guild(ctx.guild).confession_room() room = await self.config.guild(ctx.guild).confession_room()
@ -51,12 +51,12 @@ class Confession(commands.Cog):
@confessionset.command(name="track") @confessionset.command(name="track")
async def confessionset_track(self, ctx, *, channel: discord.TextChannel = None): async def confessionset_track(self, ctx, *, channel: discord.TextChannel = None):
"""Set a tracker room """Set a tracker room
Leave empty to unset the room. Leave empty to unset the room.
Tracker room has confessions sent along with who sent them, Tracker room has confessions sent along with who sent them,
for easy moderation purposes. This is optional to set. for easy moderation purposes. This is optional to set.
**Make sure bot is able to embed messages in tracker room.** **Make sure bot is able to embed messages in tracker room.**
""" """
room = await self.config.guild(ctx.guild).tracker_room() room = await self.config.guild(ctx.guild).tracker_room()

View file

@ -27,7 +27,10 @@ class RecentActivityRecord:
return len(self.activities) + len(self.messages) return len(self.activities) + len(self.messages)
def _filter( 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]]: ) -> List[Union[datetime, discord.Message]]:
ret: List[Union[datetime, discord.Message]] = [] ret: List[Union[datetime, discord.Message]] = []
@ -49,7 +52,10 @@ class RecentActivityRecord:
return ret return ret
def conditional_count( def conditional_count(
self, *, after: Optional[datetime] = None, message_check: Optional[MessagePredicate] = None, self,
*,
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))
@ -57,7 +63,10 @@ class RecentActivityRecord:
return ret return ret
def conditional_remove( 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: if before:
self.activities = [a for a in self.activities if a > before] self.activities = [a for a in self.activities if a > before]
@ -100,7 +109,11 @@ 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, *, guild: discord.Guild, after: datetime, message_check: Optional[MessagePredicate] = None, self,
*,
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

@ -55,7 +55,7 @@ class Markov(commands.Cog):
@markovset.command(name="prefix") @markovset.command(name="prefix")
async def markovset_prefixes(self, ctx, *, prefixes: str = None): async def markovset_prefixes(self, ctx, *, prefixes: str = None):
""" Set prefixes for bots in your server """Set prefixes for bots in your server
This is so markov won't log bot commands. This is so markov won't log bot commands.
""" """
if not prefixes: if not prefixes:
@ -101,7 +101,7 @@ class Markov(commands.Cog):
@commands.cooldown(rate=1, per=10, type=commands.BucketType.user) @commands.cooldown(rate=1, per=10, type=commands.BucketType.user)
@checks.bot_has_permissions(embed_links=True) @checks.bot_has_permissions(embed_links=True)
async def markov(self, ctx, *, starting_text: str = None): async def markov(self, ctx, *, starting_text: str = None):
""" Generate text using markov chains! """Generate text using markov chains!
Text generated is based on what users say in the current channel Text generated is based on what users say in the current channel
""" """

View file

@ -587,7 +587,12 @@ 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, 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. Purge inactive users with role.

View file

@ -98,7 +98,9 @@ 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"])), 32, placeholder="", str(ctx.guild.get_role(data["role"]) or "[X] {}".format(data["role"])),
32,
placeholder="",
), ),
} }
assigned_roles.append(dic) assigned_roles.append(dic)

View file

@ -43,16 +43,16 @@ class Pony(commands.Cog):
@checks.admin() @checks.admin()
async def ponyfilter(self, ctx: commands.Context): async def ponyfilter(self, ctx: commands.Context):
"""Manages pony filters """Manages pony filters
Warning: Can be used to allow NSFW images Warning: Can be used to allow NSFW images
Filters automatically apply tags to each search""" Filters automatically apply tags to each search"""
pass pass
@ponyfilter.command(name="add") @ponyfilter.command(name="add")
async def _add_ponyfilter(self, ctx, filter_tag: str): async def _add_ponyfilter(self, ctx, filter_tag: str):
"""Adds a tag to the server's pony filter list """Adds a tag to the server's pony filter list
Example: !ponyfilter add safe""" Example: !ponyfilter add safe"""
guild = ctx.guild guild = ctx.guild
filters = await self.config.guild(guild).filters() filters = await self.config.guild(guild).filters()
max_filters = await self.config.maxfilters() max_filters = await self.config.maxfilters()
@ -71,9 +71,9 @@ class Pony(commands.Cog):
async def _del_ponyfilter(self, ctx, filter_tag: str = ""): async def _del_ponyfilter(self, ctx, filter_tag: str = ""):
"""Deletes a tag from the server's pony filter list """Deletes a tag from the server's pony filter list
Without arguments, reverts to the default pony filter list Without arguments, reverts to the default pony filter list
Example: !ponyfilter del safe""" Example: !ponyfilter del safe"""
guild = ctx.guild guild = ctx.guild
filters = await self.config.guild(guild).filters() filters = await self.config.guild(guild).filters()
if len(filter_tag) > 0: if len(filter_tag) > 0:
@ -139,9 +139,9 @@ class Pony(commands.Cog):
async def _maxfilters_ponyset(self, ctx, new_max_filters: int): async def _maxfilters_ponyset(self, ctx, new_max_filters: int):
"""Sets the global tag limit for the filter list. """Sets the global tag limit for the filter list.
Leave blank to get current max filters. Leave blank to get current max filters.
Gives an error when a user tries to add a filter while the server's filter list contains a certain amount of tags""" Gives an error when a user tries to add a filter while the server's filter list contains a certain amount of tags"""
if new_max_filters is None: if new_max_filters is None:
max_filters = self.config.maxfilters() max_filters = self.config.maxfilters()
await ctx.send("Current filter limit: {} filters.".format(max_filters)) await ctx.send("Current filter limit: {} filters.".format(max_filters))

View file

@ -71,24 +71,24 @@ class ReactPoll(commands.Cog):
@checks.bot_has_permissions(manage_messages=True) @checks.bot_has_permissions(manage_messages=True)
async def rpoll(self, ctx, *text): async def rpoll(self, ctx, *text):
"""Starts/stops a reaction poll """Starts/stops a reaction poll
Usage example (time argument is optional) Usage example (time argument is optional)
[p]rpoll question;option1;option2...;t=<date to end on or time duration> [p]rpoll question;option1;option2...;t=<date to end on or time duration>
[p]rpoll stop [p]rpoll stop
Durations look like (must be greater than 10 seconds): Durations look like (must be greater than 10 seconds):
15s 15s
5 minutes 5 minutes
1 minute 30 seconds 1 minute 30 seconds
1 hour 1 hour
2 days 2 days
5h30m 5h30m
times look like: times look like:
February 14 at 6pm EDT February 14 at 6pm EDT
2019-04-13 06:43:00 PST 2019-04-13 06:43:00 PST
01/20/18 at 21:00:43 01/20/18 at 21:00:43
times default to UTC if no timezone provided. times default to UTC if no timezone provided.
""" """
message = ctx.message message = ctx.message
channel = message.channel channel = message.channel

View file

@ -50,7 +50,11 @@ MAX_EMBED = 25
class RoleManagement( class RoleManagement(
UtilMixin, MassManagementMixin, EventMixin, commands.Cog, metaclass=CompositeMetaClass, UtilMixin,
MassManagementMixin,
EventMixin,
commands.Cog,
metaclass=CompositeMetaClass,
): ):
""" """
Cog for role management Cog for role management
@ -308,7 +312,12 @@ 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, 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... Binds a role to a reaction on a message...
@ -347,7 +356,11 @@ 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 "
@ -1035,7 +1048,11 @@ class RoleManagement(
channel_id = data.get("channelid", None) channel_id = data.get("channelid", None)
if channel_id: 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: 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,7 +124,11 @@ class MassManagementMixin(MixinMeta):
@mrole.command(name="user") @mrole.command(name="user")
async def mrole_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: ) -> None:
""" """
adds/removes roles to one or more users adds/removes roles to one or more users
@ -133,13 +137,13 @@ class MassManagementMixin(MixinMeta):
Example Usage: Example Usage:
[p]massrole user Sinbad --add RoleToGive "Role with spaces to give" [p]massrole user Sinbad --add RoleToGive "Role with spaces to give"
--remove RoleToRemove "some other role to remove" Somethirdrole --remove RoleToRemove "some other role to remove" Somethirdrole
[p]massrole user LoudMouthedUser ProfaneUser --add muted [p]massrole user LoudMouthedUser ProfaneUser --add muted
For role operations based on role membership, permissions had, or whether someone is a bot For role operations based on role membership, permissions had, or whether someone is a bot
(or even just add to/remove from all) see `[p]massrole search` and `[p]massrole modify` (or even just add to/remove from all) see `[p]massrole search` and `[p]massrole modify`
""" """
query = _query.parsed query = _query.parsed
apply = query["add"] + query["remove"] apply = query["add"] + query["remove"]
@ -245,7 +249,8 @@ 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}", files=[discord.File(data, filename=filename)], content=f"Data for {ctx.author.mention}",
files=[discord.File(data, filename=filename)],
) )
csvf.close() csvf.close()
data.close() data.close()
@ -256,7 +261,7 @@ class MassManagementMixin(MixinMeta):
async def mrole_complex(self, ctx: GuildContext, *, _query: ComplexActionConverter): async def mrole_complex(self, ctx: GuildContext, *, _query: ComplexActionConverter):
""" """
Similar syntax to search, while applying/removing roles Similar syntax to search, while applying/removing roles
--has-all roles --has-all roles
--has-none roles --has-none roles
--has-any roles --has-any roles
@ -276,7 +281,7 @@ class MassManagementMixin(MixinMeta):
--only-humans --only-humans
--only-bots --only-bots
--everyone --everyone
--add roles --add roles
--remove roles --remove roles
""" """
@ -299,11 +304,17 @@ 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", 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: except discord.HTTPException:
log.debug( 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() await ctx.tick()

View file

@ -79,7 +79,11 @@ 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, *, 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 Give and remove roles as a single op with some slight sanity

View file

@ -87,10 +87,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) # type: ignore
for idx in self.raw_channel_mentions
],
) )
) )
self.role_mentions: List[discord.Role] = list( self.role_mentions: List[discord.Role] = list(

View file

@ -175,7 +175,10 @@ class Scheduler(commands.Cog):
task.cancel() task.cancel()
async def red_delete_data_for_user( 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) loaded_tasks = await self.fetch_task_by_attrs_exact(author=user_id)
if loaded_tasks: if loaded_tasks:
@ -428,7 +431,8 @@ 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}, strict={"author": ctx.author, "channel": ctx.channel}, lax={"uid": info, "nicename": info},
strict={"author": ctx.author, "channel": ctx.channel},
) )
if not tasks: if not tasks:
@ -463,7 +467,10 @@ 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, 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() color = await ctx.embed_color()

View file

@ -70,7 +70,12 @@ class Task:
with contextlib.suppress(AttributeError, ValueError): with contextlib.suppress(AttributeError, ValueError):
yield cls( 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 @property

View file

@ -15,8 +15,8 @@ EXT = ("mp3", "flac", "ogg", "wav")
class SFX(commands.Cog): class SFX(commands.Cog):
""" Play saysounds in VC's in your guild """Play saysounds in VC's in your guild
Supports costs, files, and links. Supports costs, files, and links.
""" """
def __init__(self, bot): def __init__(self, bot):