Skip to content

Commit 44aca8c

Browse files
committed
Make all files flake8 compliant
1 parent 1e31c76 commit 44aca8c

File tree

8 files changed

+57
-30
lines changed

8 files changed

+57
-30
lines changed

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Code of Conduct
22

3-
The Python Discord Code of Conduct can be found [on our website](https://pydis.com/coc).
3+
The Python Discord Code of Conduct can be found [on our website](https://pydis.com/coc).

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Contributing Guidelines
22

3-
The Contributing Guidelines for Python Discord projects can be found [on our website](https://pydis.com/contributing.md).
3+
The Contributing Guidelines for Python Discord projects can be found [on our website](https://pydis.com/contributing.md).

SECURITY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Security Notice
22

3-
The Security Notice for Python Discord projects can be found [on our website](https://pydis.com/security.md).
3+
The Security Notice for Python Discord projects can be found [on our website](https://pydis.com/security.md).

ban_appeals/ban_appeals.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
log = getLogger(__name__)
1919

20+
2021
class BanAppeals(commands.Cog):
22+
"""A plugin to manage threads from a separate ban appeal server."""
23+
2124
def __init__(self, bot: ModmailBot):
2225
self.bot = bot
2326

@@ -30,8 +33,8 @@ def __init__(self, bot: ModmailBot):
3033

3134
self.appeals_category: t.Optional[discord.CategoryChannel] = None
3235

33-
self.init_task = asyncio.create_task(self.ensure_plugin_init())
34-
36+
self.init_task = asyncio.create_task(self.init_plugin())
37+
3538
@staticmethod
3639
async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> t.Optional[discord.Member]:
3740
"""
@@ -49,7 +52,7 @@ async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> t.Optiona
4952
return None
5053
log.debug("%s (%d) fetched from API.", member, member.id)
5154
return member
52-
55+
5356
@staticmethod
5457
async def get_or_fetch_channel(guild: discord.Guild, channel_id: int) -> t.Optional[discord.ChannelType]:
5558
"""
@@ -69,15 +72,16 @@ async def get_or_fetch_channel(guild: discord.Guild, channel_id: int) -> t.Optio
6972

7073
return channel
7174

72-
async def ensure_plugin_init(self) -> None:
75+
async def init_plugin(self) -> None:
76+
"""Initialise the plugin's configuration."""
7377
self.pydis_guild = self.bot.guild
7478
self.appeals_guild = self.bot.get_guild(self._appeals_guild_id)
7579
self.appeals_category = await self.get_or_fetch_channel(self.pydis_guild, self._pydis_appeals_category_id)
7680
self.logs_channel = discord.utils.get(self.appeals_guild.channels, name="logs")
7781

7882
log.info("Plugin loaded, checking if there are people to kick.")
7983
await self._sync_kicks()
80-
84+
8185
async def _sync_kicks(self) -> None:
8286
"""Iter through all members in appeals guild, kick them if they meet criteria."""
8387
for member in self.appeals_guild.members:
@@ -102,7 +106,7 @@ async def _maybe_kick_user(self, member: discord.Member) -> None:
102106
log.error("Failed to kick %s (%d)due to insufficient permissions.", member, member.id)
103107
await self.logs_channel.send(f"Kicked {member} ({member.id}) on join as they're not banned in main server.")
104108
log.info("Kicked %s (%d).", member, member.id)
105-
109+
106110
async def _is_banned_pydis(self, member: discord.Member) -> bool:
107111
"""See if the given member is banned in PyDis."""
108112
try:
@@ -128,7 +132,7 @@ async def on_member_join(self, member: discord.Member) -> None:
128132
# Join event from the appeals server
129133
# Kick them if they are not banned and not part of the bypass list
130134
await self._maybe_kick_user(member)
131-
135+
132136
@commands.Cog.listener()
133137
async def on_thread_ready(self, thread: Thread, *args) -> None:
134138
"""If the new thread is for an appeal, move it to the appeals category."""
@@ -138,5 +142,6 @@ async def on_thread_ready(self, thread: Thread, *args) -> None:
138142
await thread.channel.edit(category=self.appeals_category, sync_permissions=True)
139143

140144

141-
def setup(bot: ModmailBot):
145+
def setup(bot: ModmailBot) -> None:
146+
"""Add the BanAppeals cog."""
142147
bot.add_cog(BanAppeals(bot))

close_message/close_message.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from discord.ext import commands
22

3+
from bot import ModmailBot
34
from core import checks
45
from core import time
56
from core.models import PermissionLevel
@@ -8,7 +9,10 @@
89

910

1011
class UserFriendlyTimeOnly(time.UserFriendlyTime):
11-
async def convert(self, ctx, argument):
12+
"""A convertor class to convert user friendly time to a duration."""
13+
14+
async def convert(self, ctx: commands.Context, argument: str) -> str:
15+
"""Convert the given argument to a user friendly time."""
1216
converted = await super().convert(ctx, argument)
1317
if converted.arg:
1418
raise commands.BadArgument(
@@ -19,22 +23,27 @@ async def convert(self, ctx, argument):
1923

2024

2125
class CloseMessage(commands.Cog):
22-
def __init__(self, bot):
26+
"""A plugin that adds a command to close a thread after a given period with a set message."""
27+
28+
def __init__(self, bot: ModmailBot):
2329
self.bot = bot
2430
self.close_command = self.bot.get_command('close')
2531

26-
@commands.command(name='closemessage', aliases=['cm'],
27-
usage="[after]",
28-
help='Close the current thread with the message '
29-
f'`{CLOSING_MESSAGE}`')
32+
@commands.command(
33+
name="closemessage", aliases=("cm"),
34+
usage="[after]",
35+
help=f"Close the current thread with the message `{CLOSING_MESSAGE}`"
36+
)
3037
@checks.has_permissions(PermissionLevel.SUPPORTER)
3138
@checks.thread_only()
32-
async def close_message(self, ctx, *, after='15m'):
39+
async def close_message(self, ctx: commands.Context, *, after: str = '15m') -> commands.Command:
40+
"""Close the thread after the given duration with the set message."""
3341
if after.isdigit():
3442
after = f'{after}m'
3543
after = await UserFriendlyTimeOnly().convert(ctx, after)
3644
return await self.close_command(ctx, after=after)
3745

3846

39-
def setup(bot):
47+
def setup(bot: ModmailBot) -> None:
48+
"""Load the CloseMessage plugin."""
4049
bot.add_cog(CloseMessage(bot))

mdlink/mdlink.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import discord
21
from discord.ext import commands
32

3+
from bot import ModmailBot
44
from core import checks
55
from core.models import PermissionLevel
66

77

88
class MDLink(commands.Cog):
9-
def __init__(self, bot):
9+
"""A plugin to get a link to the modmail thread using MD syntax."""
10+
11+
def __init__(self, bot: ModmailBot):
1012
self.bot = bot
1113

1214
@commands.command()
1315
@checks.has_permissions(PermissionLevel.MODERATOR)
1416
@checks.thread_only()
15-
async def mdlink(self, ctx, *, text="ModMail"):
17+
async def mdlink(self, ctx: commands.Context, *, text: str = "ModMail") -> None:
1618
"""Return a link to the modmail thread in markdown syntax."""
1719
link = await self.bot.api.get_log_link(ctx.channel.id)
1820
await ctx.send(f"`[{text}]({link})`")
1921

2022

21-
def setup(bot):
23+
def setup(bot: ModmailBot) -> None:
24+
"""Add the MDLink plugin."""
2225
bot.add_cog(MDLink(bot))

reply_cooldown/reply_cooldown.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from collections import deque
21
import time
2+
from collections import deque
33

44
import discord
5+
from discord.ext import commands
6+
7+
from bot import ModmailBot
58
from core.thread import Thread
69

710
# Number of messages kept in memory to check for double sends
@@ -13,11 +16,13 @@
1316
COOLDOWN_TIME = 10
1417

1518

16-
def setup(bot):
19+
def setup(bot: ModmailBot) -> None:
20+
"""Monkey patch the built-in reply function to add a cooldown between uses."""
1721
_reply = Thread.reply
1822

19-
async def reply(self, message: discord.Message, anonymous: bool = False, plain: bool = False):
20-
# Bypass the cooldown if the message has attachements
23+
async def reply(self: commands.Cog, message: discord.Message, anonymous: bool = False, plain: bool = False) -> None:
24+
"""The new reply function with a cooldown between uses."""
25+
# Bypass the cooldown if the message has attachments.
2126
if not message.attachments:
2227
for entry in MESSAGES_BUFFER:
2328
if (

tagging/tagging.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
from discord.ext import commands
44

5+
from bot import ModmailBot
56
from core import checks
67
from core.models import PermissionLevel
78

89

910
class Tagging(commands.Cog):
10-
def __init__(self, bot):
11+
"""A plugin that enables mods to prefix the thread name with a tag."""
12+
13+
def __init__(self, bot: ModmailBot):
1114
self.bot = bot
1215

1316
@checks.has_permissions(PermissionLevel.SUPPORTER)
1417
@commands.command()
15-
async def tag(self, ctx, tag: Optional[str]):
18+
async def tag(self, ctx: commands.Context, tag: Optional[str]) -> None:
1619
"""
1720
Append a tag at the beginning of the channel name.
21+
1822
Using the command without any argument will reset it.
1923
"""
2024
clean_name = ctx.channel.name.split("|", maxsplit=1)[-1]
@@ -28,5 +32,6 @@ async def tag(self, ctx, tag: Optional[str]):
2832
await ctx.message.add_reaction("\u2705")
2933

3034

31-
def setup(bot):
35+
def setup(bot: ModmailBot) -> None:
36+
"""Add the Tagging plugin."""
3237
bot.add_cog(Tagging(bot))

0 commit comments

Comments
 (0)