Skip to content

Commit 8cdd1f2

Browse files
committed
Use black formatter && Add pylint
1 parent 82c80e7 commit 8cdd1f2

File tree

7 files changed

+155
-51
lines changed

7 files changed

+155
-51
lines changed

.github/workflows/pylint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install pylint
21+
- name: Analysing the code with pylint
22+
run: |
23+
pylint $(git ls-files '*.py')

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
start_time = time.time()
1818

19+
1920
def load_data():
2021
if not os.path.exists(DATA_FILE):
2122
return {}
@@ -140,6 +141,7 @@ async def check_inactivity_thread(thread_id: int):
140141
save_data(data)
141142
return
142143

144+
143145
# Setup functions and vars
144146
client.load_data = load_data
145147
client.save_data = save_data

modules/errors.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
from disnake.ext import commands
77

8+
89
class NotOwner(commands.CheckFailure):
910
pass
1011

12+
1113
class ErrorsModule(commands.Cog):
1214
def __init__(self, bot):
1315
self.bot = bot
@@ -26,11 +28,13 @@ async def on_command_error(self, ctx: commands.Context, error: Exception):
2628
if isinstance(error, NotOwner):
2729
errEmbed.description = "Вы не разработчик бота."
2830
return await ctx.reply(embed=errEmbed, delete_after=40)
29-
31+
3032
### Triggers when an error occurs in a slash command ###
3133

3234
@commands.Cog.listener()
33-
async def on_slash_command_error(self, inter: disnake.ApplicationCommandInteraction, error: Exception):
35+
async def on_slash_command_error(
36+
self, inter: disnake.ApplicationCommandInteraction, error: Exception
37+
):
3438

3539
errEmbed = disnake.Embed(title="Ошибка", color=disnake.Color.red())
3640
user_avatar = (
@@ -82,5 +86,6 @@ async def on_slash_command_error(self, inter: disnake.ApplicationCommandInteract
8286
except disnake.InteractionResponded:
8387
await inter.followup.send(embed=errEmbed, ephemeral=True)
8488

89+
8590
def setup(bot):
86-
bot.add_cog(ErrorsModule(bot))
91+
bot.add_cog(ErrorsModule(bot))

modules/forums.py

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from disnake.ext import commands
66

7+
78
class ForumsModule(commands.Cog):
89
def __init__(self, bot):
910
self.bot = bot
@@ -55,14 +56,22 @@ async def close_thread(self, ctx: commands.Context):
5556

5657
## Slash commands ##
5758

58-
@commands.slash_command(name="forum", description="Управление форумами", default_member_permissions=disnake.Permissions(manage_channels=True))
59+
@commands.slash_command(
60+
name="forum",
61+
description="Управление форумами",
62+
default_member_permissions=disnake.Permissions(manage_channels=True),
63+
)
5964
async def forum(self, interaction: disnake.CommandInteraction):
6065
pass
6166

6267
### Add new forum command ###
6368

6469
@forum.sub_command(name="add", description="Создать новый форум")
65-
async def forum_add(self, interaction: disnake.CommandInteraction, name: str = commands.Param(description="Название форума")):
70+
async def forum_add(
71+
self,
72+
interaction: disnake.CommandInteraction,
73+
name: str = commands.Param(description="Название форума"),
74+
):
6675
if isinstance(interaction.channel, disnake.DMChannel):
6776
errEmbed = disnake.Embed(
6877
title="Ошибка",
@@ -75,8 +84,10 @@ async def forum_add(self, interaction: disnake.CommandInteraction, name: str = c
7584
else self.bot.user.display_avatar.url
7685
)
7786
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
78-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
79-
87+
return await interaction.response.send_message(
88+
embed=errEmbed, ephemeral=True
89+
)
90+
8091
await interaction.response.defer(ephemeral=True)
8192
forum = await interaction.guild.create_forum_channel(name)
8293
data = self.bot.load_data()
@@ -103,9 +114,13 @@ async def forum_add(self, interaction: disnake.CommandInteraction, name: str = c
103114
await interaction.edit_original_message(embed=respEmbed)
104115

105116
### Remove forum command ###
106-
117+
107118
@forum.sub_command(name="rem", description="Удалить форум")
108-
async def forum_rem(self, interaction: disnake.CommandInteraction, forum: str = commands.Param(description="Удаляемый форум", autocomplete=True)):
119+
async def forum_rem(
120+
self,
121+
interaction: disnake.CommandInteraction,
122+
forum: str = commands.Param(description="Удаляемый форум", autocomplete=True),
123+
):
109124
if isinstance(interaction.channel, disnake.DMChannel):
110125
errEmbed = disnake.Embed(
111126
title="Ошибка",
@@ -118,8 +133,10 @@ async def forum_rem(self, interaction: disnake.CommandInteraction, forum: str =
118133
else self.bot.user.display_avatar.url
119134
)
120135
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
121-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
122-
136+
return await interaction.response.send_message(
137+
embed=errEmbed, ephemeral=True
138+
)
139+
123140
errEmbed = disnake.Embed(
124141
title="Упс!",
125142
color=disnake.Color.red(),
@@ -170,8 +187,15 @@ async def forum_rem(self, interaction: disnake.CommandInteraction, forum: str =
170187

171188
### Toggle welcome message ###
172189

173-
@forum.sub_command(name="toggle_message", description="Включить или выключить приветственное сообщение")
174-
async def forum_welcome_toggle(self, interaction: disnake.CommandInteraction, value: bool = commands.Param(description="True - включить, False - выключить")):
190+
@forum.sub_command(
191+
name="toggle_message",
192+
description="Включить или выключить приветственное сообщение",
193+
)
194+
async def forum_welcome_toggle(
195+
self,
196+
interaction: disnake.CommandInteraction,
197+
value: bool = commands.Param(description="True - включить, False - выключить"),
198+
):
175199
if isinstance(interaction.channel, disnake.DMChannel):
176200
errEmbed = disnake.Embed(
177201
title="Ошибка",
@@ -184,8 +208,10 @@ async def forum_welcome_toggle(self, interaction: disnake.CommandInteraction, va
184208
else self.bot.user.display_avatar.url
185209
)
186210
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
187-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
188-
211+
return await interaction.response.send_message(
212+
embed=errEmbed, ephemeral=True
213+
)
214+
189215
await interaction.response.defer(ephemeral=True)
190216
data = self.bot.load_data()
191217
sid = str(interaction.guild.id)
@@ -219,8 +245,14 @@ async def forum_welcome_toggle(self, interaction: disnake.CommandInteraction, va
219245

220246
### Close after setting ###
221247

222-
@forum.sub_command(name="close_after", description="Установить время закрытия до ветки")
223-
async def close_after(self, interaction: disnake.CommandInteraction, hours: int = commands.Param(description="Время в часах.")):
248+
@forum.sub_command(
249+
name="close_after", description="Установить время закрытия до ветки"
250+
)
251+
async def close_after(
252+
self,
253+
interaction: disnake.CommandInteraction,
254+
hours: int = commands.Param(description="Время в часах."),
255+
):
224256
if isinstance(interaction.channel, disnake.DMChannel):
225257
errEmbed = disnake.Embed(
226258
title="Ошибка",
@@ -233,8 +265,10 @@ async def close_after(self, interaction: disnake.CommandInteraction, hours: int
233265
else self.bot.user.display_avatar.url
234266
)
235267
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
236-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
237-
268+
return await interaction.response.send_message(
269+
embed=errEmbed, ephemeral=True
270+
)
271+
238272
await interaction.response.defer(ephemeral=True)
239273
data = self.bot.load_data()
240274
sid = str(interaction.guild.id)
@@ -262,7 +296,9 @@ async def close_after(self, interaction: disnake.CommandInteraction, hours: int
262296

263297
### Welcome message setting ###
264298

265-
@forum.sub_command(name="message", description="Установить приветственное сообщение")
299+
@forum.sub_command(
300+
name="message", description="Установить приветственное сообщение"
301+
)
266302
async def forum_welcome_message(self, interaction: disnake.CommandInteraction):
267303
if isinstance(interaction.channel, disnake.DMChannel):
268304
errEmbed = disnake.Embed(
@@ -276,8 +312,10 @@ async def forum_welcome_message(self, interaction: disnake.CommandInteraction):
276312
else self.bot.user.display_avatar.url
277313
)
278314
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
279-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
280-
315+
return await interaction.response.send_message(
316+
embed=errEmbed, ephemeral=True
317+
)
318+
281319
class WelcomeModal(disnake.ui.Modal):
282320
def __init__(self):
283321
components = [
@@ -314,15 +352,24 @@ async def callback(self, modal_inter: disnake.ModalInteraction):
314352
if interaction.author.display_avatar
315353
else self.bot.user.display_avatar.url
316354
)
317-
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=author_avatar)
355+
errEmbed.set_footer(
356+
text=f"{interaction.author.name}", icon_url=author_avatar
357+
)
318358
await modal_inter.response.send_message(embed=respEmbed, ephemeral=True)
319359

320360
await interaction.response.send_modal(modal=WelcomeModal())
321361

322362
### Delete closed threads setting ###
323363

324-
@forum.sub_command(name="deleteclosed", description="Включить/выключить кнопку удаления закрытых веток")
325-
async def forum_delete_closed(self, interaction: disnake.CommandInteraction, value: bool = commands.Param(description="True или False")):
364+
@forum.sub_command(
365+
name="deleteclosed",
366+
description="Включить/выключить кнопку удаления закрытых веток",
367+
)
368+
async def forum_delete_closed(
369+
self,
370+
interaction: disnake.CommandInteraction,
371+
value: bool = commands.Param(description="True или False"),
372+
):
326373
if isinstance(interaction.channel, disnake.DMChannel):
327374
errEmbed = disnake.Embed(
328375
title="Ошибка",
@@ -335,8 +382,10 @@ async def forum_delete_closed(self, interaction: disnake.CommandInteraction, val
335382
else self.bot.user.display_avatar.url
336383
)
337384
errEmbed.set_footer(text=f"{interaction.author.name}", icon_url=user_avatar)
338-
return await interaction.response.send_message(embed=errEmbed, ephemeral=True)
339-
385+
return await interaction.response.send_message(
386+
embed=errEmbed, ephemeral=True
387+
)
388+
340389
await interaction.response.defer(ephemeral=True)
341390
data = self.bot.load_data()
342391
sid = str(interaction.guild.id)
@@ -373,10 +422,12 @@ async def forum_delete_closed(self, interaction: disnake.CommandInteraction, val
373422
### Autocomplete for forum deletion ###
374423

375424
@forum_rem.autocomplete("forum")
376-
async def removeforum_autocomplete(self, inter: disnake.ApplicationCommandInteraction, user_input: str):
425+
async def removeforum_autocomplete(
426+
self, inter: disnake.ApplicationCommandInteraction, user_input: str
427+
):
377428
if isinstance(inter.channel, disnake.DMChannel):
378429
return
379-
430+
380431
data = self.bot.load_data()
381432
sid = str(inter.guild.id)
382433
results = []
@@ -390,6 +441,5 @@ async def removeforum_autocomplete(self, inter: disnake.ApplicationCommandIntera
390441
return results[:25]
391442

392443

393-
394444
def setup(bot):
395-
bot.add_cog(ForumsModule(bot))
445+
bot.add_cog(ForumsModule(bot))

modules/info.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from disnake.ext import commands
55
from config import VERSION
66

7+
78
class InfoModule(commands.Cog):
89
def __init__(self, bot):
910
self.bot = bot
@@ -18,7 +19,8 @@ async def about(self, interaction: disnake.CommandInteraction):
1819
color=disnake.Color.purple(),
1920
)
2021
embed.set_footer(
21-
text=f"Made with ❤️ by PrivateKey2", icon_url=self.bot.user.display_avatar.url
22+
text=f"Made with ❤️ by PrivateKey2",
23+
icon_url=self.bot.user.display_avatar.url,
2224
)
2325
await interaction.response.send_message(embed=embed, ephemeral=True)
2426

@@ -32,25 +34,29 @@ async def info(self, interaction: disnake.CommandInteraction):
3234

3335
ping = round(self.bot.latency * 1000)
3436
guild_count = len(self.bot.guilds)
35-
user_count = len(set(member.id for guild in self.bot.guilds for member in guild.members))
37+
user_count = len(
38+
set(member.id for guild in self.bot.guilds for member in guild.members)
39+
)
3640
disnake_version = disnake.__version__
3741
python_version = platform.python_version()
3842
os_info = f"{platform.system()} {platform.release()} ({platform.machine()})"
3943

4044
embed_color = (
41-
disnake.Color.green() if ping < 100 else
42-
disnake.Color.yellow() if ping < 250 else
43-
disnake.Color.red()
45+
disnake.Color.green()
46+
if ping < 100
47+
else disnake.Color.yellow() if ping < 250 else disnake.Color.red()
4448
)
4549

4650
embed = disnake.Embed(
4751
title="Информация о боте",
4852
color=embed_color,
49-
timestamp=disnake.utils.utcnow()
53+
timestamp=disnake.utils.utcnow(),
5054
)
5155

5256
embed.add_field(name="📡 Пинг", value=f"`{ping} ms`", inline=True)
53-
embed.add_field(name="⏳ Аптайм", value=f"`{hours}h {minutes}m {seconds}s`", inline=True)
57+
embed.add_field(
58+
name="⏳ Аптайм", value=f"`{hours}h {minutes}m {seconds}s`", inline=True
59+
)
5460
embed.add_field(name="", value="", inline=False)
5561
embed.add_field(name="🛠️ Серверов", value=f"`{guild_count}`", inline=True)
5662
embed.add_field(name="👥 Пользователей", value=f"`{user_count}`", inline=True)
@@ -60,9 +66,9 @@ async def info(self, interaction: disnake.CommandInteraction):
6066
embed.add_field(name="", value="", inline=False)
6167
embed.add_field(name="💻 ОС", value=f"`{os_info}`", inline=False)
6268

63-
6469
embed.set_footer(
65-
text=f"Made with ❤️ by PrivateKey2", icon_url=self.bot.user.display_avatar.url
70+
text=f"Made with ❤️ by PrivateKey2",
71+
icon_url=self.bot.user.display_avatar.url,
6672
)
6773

6874
await interaction.response.send_message(embed=embed, ephemeral=True)
@@ -78,9 +84,11 @@ async def about(self, interaction: disnake.CommandInteraction):
7884
)
7985
embed.add_field(name="Версия", value=VERSION, inline=True)
8086
embed.set_footer(
81-
text=f"Made with ❤️ by PrivateKey2", icon_url=self.bot.user.display_avatar.url
87+
text=f"Made with ❤️ by PrivateKey2",
88+
icon_url=self.bot.user.display_avatar.url,
8289
)
8390
await interaction.response.send_message(embed=embed, ephemeral=True)
8491

92+
8593
def setup(bot):
8694
bot.add_cog(InfoModule(bot))

0 commit comments

Comments
 (0)