Skip to content

Commit 11a31d6

Browse files
committed
Pylint correction
1 parent 90a130d commit 11a31d6

File tree

7 files changed

+75
-52
lines changed

7 files changed

+75
-52
lines changed

bot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _load_extensions(self):
128128
cog = f'cogs.{file[:-3]}'
129129
print(f'Loading {cog}')
130130
self.load_extension(cog)
131-
131+
132132
async def is_owner(self, user):
133133
allowed = [int(x) for x in str(self.config.get('owners', '0')).split(',')]
134134
return user.id in allowed
@@ -257,14 +257,14 @@ async def on_connect(self):
257257
if self.db:
258258
await self.setup_indexes()
259259
self._connected.set()
260-
260+
261261
async def setup_indexes(self):
262262
"""Setup text indexes so we can use the $search operator"""
263-
coll = self.db.logs
263+
coll = self.db.logs
264264
index_name = 'messages.content_text_messages.author.name_text'
265265

266266
index_info = await coll.index_information()
267-
267+
268268
# Backwards compatibility
269269
old_index = 'messages.content_text'
270270
if old_index in index_info:
@@ -416,7 +416,7 @@ async def get_context(self, message, *, cls=commands.Context):
416416

417417
if self._skip_check(message.author.id, self.user.id):
418418
return ctx
419-
419+
420420
ctx.thread = await self.threads.find(channel=ctx.channel)
421421

422422
prefixes = await self.get_prefix()

cogs/modmail.py

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
import discord
66
from dateutil import parser
7-
from natural.date import duration
87
from discord.ext import commands
8+
from natural.date import duration
99

10-
from core import checks
11-
10+
from core import checks
1211
from core.decorators import trigger_typing
1312
from core.models import Bot
1413
from core.paginator import PaginatorSession
1514
from core.time import UserFriendlyTime, human_timedelta
16-
from core.utils import truncate, format_preview, User
15+
from core.utils import format_preview, User
1716

1817

1918
class Modmail:
@@ -366,25 +365,37 @@ def format_log_embeds(self, logs, avatar_url, title='Previous Logs'):
366365
created_at = parser.parse(entry['created_at'])
367366

368367
log_url = (
369-
f"https://logs.modmail.tk/{key}"
370-
if not self.bot.self_hosted else
368+
f"https://logs.modmail.tk/{key}"
369+
if not self.bot.self_hosted else
371370
self.bot.config.log_url.strip('/') + f'/logs/{key}'
372-
)
373-
374-
username = entry['recipient']['name'] + '#' + entry['recipient']['discriminator']
375-
376-
em = discord.Embed(color=discord.Color.blurple(), timestamp=created_at)
377-
em.set_author(name=f'{title} ({index}) - {username}', icon_url=avatar_url, url=log_url)
378-
em.url = log_url
379-
em.add_field(name='Created', value=duration(created_at, now=datetime.utcnow()))
380-
em.add_field(name='Closed By', value=f"<@{entry['closer']['id']}>")
371+
)
372+
373+
username = entry['recipient']['name'] + '#'
374+
username += entry['recipient']['discriminator']
375+
376+
embed = discord.Embed(color=discord.Color.blurple(),
377+
timestamp=created_at)
378+
embed.set_author(name=f'{title} ({index}) - {username}',
379+
icon_url=avatar_url,
380+
url=log_url)
381+
embed.url = log_url
382+
embed.add_field(name='Created',
383+
value=duration(created_at, now=datetime.utcnow()))
384+
embed.add_field(name='Closed By',
385+
value=f"<@{entry['closer']['id']}>")
386+
381387
if entry['recipient']['id'] != entry['creator']['id']:
382-
em.add_field(name='Created by', value=f"<@{entry['creator']['id']}>")
383-
em.add_field(name='Preview', value=format_preview(entry['messages']), inline=False)
384-
em.add_field(name='Link', value=log_url)
385-
em.set_footer(text='Recipient ID: ' + str(entry['recipient']['id']))
386-
387-
embeds.append(em)
388+
embed.add_field(name='Created by',
389+
value=f"<@{entry['creator']['id']}>")
390+
391+
embed.add_field(name='Preview',
392+
value=format_preview(entry['messages']),
393+
inline=False)
394+
embed.add_field(name='Link', value=log_url)
395+
embed.set_footer(
396+
text='Recipient ID: ' + str(entry['recipient']['id'])
397+
)
398+
embeds.append(embed)
388399
return embeds
389400

390401
@commands.group(invoke_without_command=True)
@@ -393,7 +404,7 @@ async def logs(self, ctx, *, member: User = None):
393404
"""Shows a list of previous Modmail thread logs of a member."""
394405

395406
await ctx.trigger_typing()
396-
407+
397408
if not member:
398409
thread = ctx.thread
399410
if not thread:
@@ -419,14 +430,15 @@ async def logs(self, ctx, *, member: User = None):
419430

420431
session = PaginatorSession(ctx, *embeds)
421432
await session.run()
422-
433+
423434
@logs.command(name='closed-by')
424-
async def closed_by(self, ctx, *, user: User=None):
435+
async def closed_by(self, ctx, *, user: User = None):
425436
"""Returns all logs closed by a user."""
426437
if not self.bot.self_hosted:
427438
embed = discord.Embed(
428439
color=discord.Color.red(),
429-
description='This command only works if you are self-hosting your logs.'
440+
description='This command only works if '
441+
'you are self-hosting your logs.'
430442
)
431443
return await ctx.send(embed=embed)
432444

@@ -444,7 +456,9 @@ async def closed_by(self, ctx, *, user: User=None):
444456

445457
entries = await self.bot.db.logs.find(query, projection).to_list(None)
446458

447-
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon_url, title='Search Results')
459+
embeds = self.format_log_embeds(entries,
460+
avatar_url=self.bot.guild.icon_url,
461+
title='Search Results')
448462

449463
if not embeds:
450464
embed = discord.Embed(
@@ -455,17 +469,18 @@ async def closed_by(self, ctx, *, user: User=None):
455469

456470
session = PaginatorSession(ctx, *embeds)
457471
await session.run()
458-
472+
459473
@logs.command(name='search')
460-
async def search(self, ctx, limit: Optional[int]=None, *, query):
461-
'''Searches all logs for a message that contains your query.'''
474+
async def search(self, ctx, limit: Optional[int] = None, *, query):
475+
"""Searches all logs for a message that contains your query."""
462476

463477
await ctx.trigger_typing()
464478

465479
if not self.bot.self_hosted:
466480
embed = discord.Embed(
467481
color=discord.Color.red(),
468-
description='This command only works if you are self-hosting your logs.'
482+
description='This command only works if you '
483+
'are self-hosting your logs.'
469484
)
470485
return await ctx.send(embed=embed)
471486

@@ -483,7 +498,9 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
483498

484499
entries = await self.bot.db.logs.find(query, projection).to_list(limit)
485500

486-
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon_url, title='Search Results')
501+
embeds = self.format_log_embeds(entries,
502+
avatar_url=self.bot.guild.icon_url,
503+
title='Search Results')
487504

488505
if not embeds:
489506
embed = discord.Embed(
@@ -494,7 +511,7 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
494511

495512
session = PaginatorSession(ctx, *embeds)
496513
await session.run()
497-
514+
498515
@commands.command()
499516
@checks.thread_only()
500517
async def reply(self, ctx, *, msg=''):
@@ -510,8 +527,8 @@ async def reply(self, ctx, *, msg=''):
510527
@commands.command()
511528
@checks.thread_only()
512529
async def anonreply(self, ctx, *, msg=''):
513-
"""Reply to a thread anonymously.
514-
530+
"""Reply to a thread anonymously.
531+
515532
You can edit the anonymous user's name,
516533
avatar and tag using the config command.
517534
@@ -570,7 +587,7 @@ async def edit(self, ctx, message_id: Optional[int] = None,
570587
thread.edit_message(linked_message_id, new_message),
571588
self.bot.api.edit_message(linked_message_id, new_message)
572589
)
573-
590+
574591
await ctx.message.add_reaction('✅')
575592

576593
@commands.command()

core/checks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ async def predicate(ctx):
1212
resolved = ctx.channel.permissions_for(ctx.author)
1313

1414
return resolved.administrator or all(
15-
getattr(resolved, name, None) == value for name, value in perms.items()
15+
getattr(resolved, name, None) == value
16+
for name, value in perms.items()
1617
)
17-
18+
1819
return commands.check(predicate)
1920

21+
2022
def thread_only():
2123
"""Checks if the command is being run in a modmail thread"""
2224
async def predicate(ctx):
2325
return ctx.thread is not None
24-
return commands.check(predicate)
26+
return commands.check(predicate)

core/clients.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ async def post_metadata(self, data):
254254

255255
async def get_user_logs(self, user_id):
256256
query = {
257-
'recipient.id': str(user_id),
257+
'recipient.id': str(user_id),
258258
'guild_id': str(self.bot.guild_id)
259259
}
260-
260+
261261
projection = {
262262
'messages': {'$slice': 5}
263263
}

core/thread.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ async def _close(self, closer, silent=False, delete_channel=True,
139139
log_url = f"https://logs.modmail.tk/{log_data['key']}"
140140

141141
if log_data['messages']:
142-
sneak_peak = str(log_data['messages'][0]['content']).replace('\n', '')
142+
content = str(log_data['messages'][0]['content'])
143+
sneak_peak = content.replace('\n', '')
143144
else:
144145
sneak_peak = 'No content'
145146

@@ -410,7 +411,7 @@ async def send(self, message, destination=None,
410411
await destination.send(mentions, embed=embed)
411412

412413
if additional_images:
413-
self.ready = False
414+
self.ready = False
414415
await asyncio.gather(*additional_images)
415416
self.ready = True
416417

core/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ async def convert(self, ctx, argument):
2323
return Object(int(match.group(1)))
2424

2525

26-
def truncate(text: str, max: int=50) -> str:
26+
def truncate(text: str, max: int = 50) -> str:
2727
return text[:max-3].strip() + '...' if len(text) > max else text
2828

29+
2930
def format_preview(messages):
3031
messages = messages[:3]
3132
out = ''
32-
for message in messages:
33+
for message in messages:
3334
if message.get('type') in ('note', 'internal'):
3435
continue
3536
author = message['author']
3637
content = message['content'].replace('\n', ' ')
3738
name = author['name'] + '#' + str(author['discriminator'])
3839
prefix = '[M]' if author['mod'] else '[R]'
3940
out += truncate(f'`{prefix} {name}:` {content}', max=75) + '\n'
40-
41+
4142
return out or 'No Messages'
4243

44+
4345
def is_image_url(url: str, _=None) -> bool:
4446
return bool(parse_image_url(url))
4547

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ python-dateutil>=2.7.0
44
emoji>=0.2
55
uvloop>=0.12.0
66
motor>=2.0.0
7-
natural
7+
natural==0.2.0
88
dnspython~=1.16.0 # required by motor
99
parsedatetime==2.4 # to be replaced by dateparser
10-
aiohttp<3.5 # to comply with discord.py
10+
aiohttp<3.5 # to comply with discord.py
11+
pylint # for style

0 commit comments

Comments
 (0)