Skip to content

Commit cbe5780

Browse files
committed
Use pylint for enforcing code styles
1 parent 6a72cdb commit cbe5780

File tree

14 files changed

+754
-257
lines changed

14 files changed

+754
-257
lines changed

.pylintrc

Lines changed: 494 additions & 0 deletions
Large diffs are not rendered by default.

bot.py

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424

2525
__version__ = '2.11.0'
2626

27-
import discord
28-
from discord.enums import ActivityType
29-
from discord.ext import commands
30-
from discord.ext.commands.view import StringView
31-
3227
from os import listdir
3328
import asyncio
3429
from textwrap import dedent
3530
from datetime import datetime
3631
from types import SimpleNamespace
3732

33+
import discord
34+
from discord.enums import ActivityType
35+
from discord.ext import commands
36+
from discord.ext.commands.view import StringView
37+
3838
import uvloop
3939
from aiohttp import ClientSession
4040
from motor.motor_asyncio import AsyncIOMotorClient
@@ -48,10 +48,9 @@
4848
from core.changelog import ChangeLog
4949
from core.objects import Bot
5050

51-
5251
colorama.init()
5352

54-
line = Fore.BLACK + Style.BRIGHT + '-------------------------' + \
53+
LINE = Fore.BLACK + Style.BRIGHT + '-------------------------' + \
5554
Style.RESET_ALL
5655

5756

@@ -117,13 +116,13 @@ def _load_extensions(self):
117116
"""Adds commands automatically"""
118117
self.remove_command('help')
119118

120-
print(line + Fore.CYAN)
119+
print(LINE + Fore.CYAN)
121120
print('┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬',
122121
'││││ │ │││││├─┤││',
123122
'┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘', sep='\n')
124123
print(f'v{__version__}')
125124
print('Authors: kyb3r, fourjr, Taaku18' + Style.RESET_ALL)
126-
print(line + Fore.CYAN)
125+
print(LINE + Fore.CYAN)
127126

128127
for file in listdir('cogs'):
129128
if not file.endswith('.py'):
@@ -138,19 +137,18 @@ async def logout(self):
138137
self.autoupdate_task.cancel()
139138
await super().logout()
140139

141-
def run(self):
140+
def run(self, *args, **kwargs):
142141
try:
143-
super().run(self.token)
142+
super().run(self.token, *args, **kwargs)
144143
finally:
145144
print(Fore.RED + ' - Shutting down bot' + Style.RESET_ALL)
146-
145+
147146
@property
148147
def log_channel(self):
149148
channel_id = self.config.get('log_channel_id')
150149
if channel_id is not None:
151150
return self.get_channel(int(channel_id))
152-
else:
153-
return self.main_category.channels[0]
151+
return self.main_category.channels[0]
154152

155153
@property
156154
def snippets(self):
@@ -185,9 +183,8 @@ def modmail_guild(self):
185183
modmail_guild_id = self.config.get('modmail_guild_id')
186184
if not modmail_guild_id:
187185
return self.guild
188-
else:
189-
return discord.utils.get(self.guilds, id=int(modmail_guild_id))
190-
186+
return discord.utils.get(self.guilds, id=int(modmail_guild_id))
187+
191188
@property
192189
def using_multiple_server_setup(self):
193190
return self.modmail_guild != self.guild
@@ -202,6 +199,7 @@ def main_category(self):
202199
if self.modmail_guild:
203200
return discord.utils.get(self.modmail_guild.categories,
204201
name='Modmail')
202+
return None
205203

206204
@property
207205
def blocked_users(self):
@@ -210,7 +208,7 @@ def blocked_users(self):
210208
@property
211209
def prefix(self):
212210
return self.config.get('prefix', '?')
213-
211+
214212
@property
215213
def mod_color(self):
216214
color = self.config.get('mod_color')
@@ -238,19 +236,19 @@ def recipient_color(self):
238236
return color
239237

240238
async def on_connect(self):
241-
print(line)
239+
print(LINE)
242240
print(Fore.CYAN, end='')
243241
if not self.self_hosted:
244242
print('MODE: Using the Modmail API')
245-
print(line)
243+
print(LINE)
246244
await self.validate_api_token()
247-
print(line)
245+
print(LINE)
248246
else:
249247
print('Mode: Self-hosting logs.')
250248
await self.validate_database_connection()
251-
print(line)
249+
print(LINE)
252250
print(Fore.CYAN + 'Connected to gateway.')
253-
251+
254252
await self.config.refresh()
255253

256254
activity_type = self.config.get('activity_type')
@@ -273,13 +271,13 @@ async def on_ready(self):
273271
"""Bot startup, sets uptime."""
274272
await self._connected.wait()
275273
print(dedent(f"""
276-
{line}
274+
{LINE}
277275
{Fore.CYAN}Client ready.
278-
{line}
276+
{LINE}
279277
{Fore.CYAN}Logged in as: {self.user}
280278
{Fore.CYAN}User ID: {self.user.id}
281279
{Fore.CYAN}Guild ID: {self.guild.id if self.guild else 0}
282-
{line}""").strip())
280+
{LINE}""").strip())
283281

284282
if not self.guild:
285283
print(f'{Fore.RED}{Style.BRIGHT}WARNING - The GUILD_ID '
@@ -309,14 +307,12 @@ async def on_ready(self):
309307

310308
# TODO: Low priority,
311309
# Retrieve messages/replies when bot is down, from history?
312-
self.loop.create_task(
313-
thread.close(
314-
closer=self.get_user(items['closer_id']),
315-
after=after,
316-
silent=items['silent'],
317-
delete_channel=items['delete_channel'],
318-
message=items['message']
319-
)
310+
await thread.close(
311+
closer=self.get_user(items['closer_id']),
312+
after=after,
313+
silent=items['silent'],
314+
delete_channel=items['delete_channel'],
315+
message=items['message']
320316
)
321317

322318
async def process_modmail(self, message):
@@ -390,8 +386,8 @@ async def get_context(self, message, *, cls=commands.Context):
390386
alias = self.config.get('aliases', {}).get(invoker)
391387
if alias is not None:
392388
ctx._alias_invoked = True
393-
_len = len(f'{invoked_prefix}{invoker}')
394-
view = StringView(f'{alias}{ctx.message.content[_len:]}')
389+
len_ = len(f'{invoked_prefix}{invoker}')
390+
view = StringView(f'{alias}{ctx.message.content[len_:]}')
395391
ctx.view = view
396392
invoker = view.get_word()
397393

@@ -408,7 +404,7 @@ async def get_context(self, message, *, cls=commands.Context):
408404

409405
async def on_message(self, message):
410406
if message.type == discord.MessageType.pins_add and \
411-
message.author == self.user:
407+
message.author == self.user:
412408
await message.delete()
413409

414410
if message.author.bot:
@@ -431,22 +427,22 @@ async def on_message(self, message):
431427
thread = await self.threads.find(channel=ctx.channel)
432428
if thread is not None:
433429
await self.api.append_log(message, type_='internal')
434-
430+
435431
async def on_guild_channel_delete(self, channel):
436432
if channel.guild != self.modmail_guild:
437-
return
433+
return
438434

439435
audit_logs = self.modmail_guild.audit_logs()
440436
entry = await audit_logs.find(lambda e: e.target.id == channel.id)
441437
mod = entry.user
442438

443439
if mod == self.user:
444440
return
445-
441+
446442
thread = await self.threads.find(channel=channel)
447443
if not thread:
448444
return
449-
445+
450446
await thread.close(closer=mod, silent=True, delete_channel=False)
451447

452448
async def on_message_delete(self, message):
@@ -577,14 +573,14 @@ async def autoupdate_loop(self):
577573

578574
if self.config.get('disable_autoupdates'):
579575
print('Autoupdates disabled.')
580-
print(line)
581-
return
576+
print(LINE)
577+
return
582578

583579
if self.self_hosted and not self.config.get('github_access_token'):
584580
print('Github access token not found.')
585581
print('Autoupdates disabled.')
586-
print(line)
587-
return
582+
print(LINE)
583+
return
588584

589585
while True:
590586
metadata = await self.api.get_metadata()
@@ -614,7 +610,7 @@ async def autoupdate_loop(self):
614610
short_sha = commit_data['sha'][:6]
615611
embed.add_field(name='Merge Commit',
616612
value=f"[`{short_sha}`]({html_url}) "
617-
f"{message} - {user['username']}")
613+
f"{message} - {user['username']}")
618614
print('Updating bot.')
619615
channel = self.log_channel
620616
await channel.send(embed=embed)
@@ -625,7 +621,6 @@ async def get_latest_updates(self, limit=3):
625621
latest_commits = ''
626622

627623
async for commit in Github(self).get_latest_commits(limit=limit):
628-
629624
short_sha = commit['sha'][:6]
630625
html_url = commit['html_url']
631626
message = commit['commit']['message'].splitlines()[0]
@@ -637,5 +632,5 @@ async def get_latest_updates(self, limit=3):
637632

638633
if __name__ == '__main__':
639634
uvloop.install()
640-
bot = ModmailBot()
635+
bot = ModmailBot() # pylint: disable=invalid-name
641636
bot.run()

0 commit comments

Comments
 (0)