Skip to content

Commit 78ce754

Browse files
committed
flake8 and change copyright year
1 parent f5dc6a1 commit 78ce754

File tree

7 files changed

+235
-251
lines changed

7 files changed

+235
-251
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 kyb3r
3+
Copyright (c) 2017-2019 kyb3r
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

bot.py

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'''
1+
"""
22
MIT License
33
4-
Copyright (c) 2017 kyb3r
4+
Copyright (c) 2017-2019 kyb3r
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -20,42 +20,32 @@
2020
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
23-
'''
23+
"""
2424

2525
__version__ = '2.0.0'
2626

27-
from contextlib import redirect_stdout
28-
from copy import deepcopy
29-
import functools
3027
import asyncio
3128
import textwrap
32-
import traceback
3329
import datetime
34-
import inspect
35-
import string
36-
import time
37-
import json
3830
import os
3931
import re
40-
import io
4132

42-
from colorama import init, Fore, Back, Style
43-
import dateutil.parser
44-
45-
init()
46-
47-
from discord.ext import commands
48-
from discord.ext.commands.view import StringView
4933
import discord
5034
import aiohttp
35+
from discord.ext import commands
36+
from discord.ext.commands.view import StringView
37+
from colorama import init, Fore, Style
5138

52-
from core.paginator import PaginatorSession
5339
from core.api import Github, ModmailApiClient
5440
from core.thread import ThreadManager
5541
from core.config import ConfigManager
5642

43+
44+
init()
45+
5746
line = Fore.BLACK + Style.BRIGHT + '-------------------------' + Style.RESET_ALL
5847

48+
5949
class ModmailBot(commands.Bot):
6050

6151
mutable_config_keys = ['prefix', 'status', 'guild_id', 'mention', 'autoupdates', 'modmail_guild_id']
@@ -64,7 +54,7 @@ def __init__(self):
6454
super().__init__(command_prefix=self.get_pre)
6555
self.version = __version__
6656
self.start_time = datetime.datetime.utcnow()
67-
self.threads = ThreadManager(self)
57+
self.threads = ThreadManager(self)
6858
self.session = aiohttp.ClientSession(loop=self.loop)
6959
self.config = ConfigManager(self)
7060
self.modmail_api = ModmailApiClient(self)
@@ -73,7 +63,7 @@ def __init__(self):
7363
self._add_commands()
7464

7565
def _add_commands(self):
76-
'''Adds commands automatically'''
66+
"""Adds commands automatically"""
7767
self.remove_command('help')
7868

7969
print(line + Fore.CYAN)
@@ -84,33 +74,32 @@ def _add_commands(self):
8474
print('Authors: kyb3r, fourjr' + Style.RESET_ALL)
8575
print(line + Fore.CYAN)
8676

87-
8877
for file in os.listdir('cogs'):
8978
if not file.endswith('.py'):
9079
continue
9180
cog = f'cogs.{file[:-3]}'
9281
print(f'Loading {cog}')
9382
self.load_extension(cog)
94-
83+
9584
async def logout(self):
9685
await self.session.close()
9786
self.data_task.cancel()
9887
self.autoupdate_task.cancel()
9988
await super().logout()
100-
89+
10190
def run(self):
10291
try:
10392
super().run(self.token)
10493
finally:
10594
print(Fore.CYAN + ' Shutting down bot' + Style.RESET_ALL)
106-
95+
10796
@property
10897
def snippets(self):
10998
return {k: v for k, v in self.config.get('snippets', {}).items() if v}
11099

111100
@property
112101
def aliases(self):
113-
return {k: v for k, v in self.config.get('aliases', {}).items() if v}
102+
return {k: v for k, v in self.config.get('aliases', {}).items() if v}
114103

115104
@property
116105
def token(self):
@@ -119,16 +108,16 @@ def token(self):
119108
@property
120109
def guild_id(self):
121110
return int(self.config.guild_id)
122-
111+
123112
@property
124113
def guild(self):
125114
return discord.utils.get(self.guilds, id=self.guild_id)
126-
115+
127116
@property
128117
def modmail_guild(self):
129118
modmail_guild_id = self.config.get('modmail_guild_id')
130119
if not modmail_guild_id:
131-
return self.guild
120+
return self.guild
132121
else:
133122
return discord.utils.get(self.guilds, id=int(modmail_guild_id))
134123

@@ -142,14 +131,14 @@ def blocked_users(self):
142131
if self.modmail_guild:
143132
top_chan = self.main_category.channels[0]
144133
return [int(i) for i in re.findall(r'\d+', top_chan.topic)]
145-
134+
146135
@property
147136
def prefix(self):
148137
return self.config.get('prefix', '?')
149138

150139
@staticmethod
151140
async def get_pre(bot, message):
152-
'''Returns the prefix.'''
141+
"""Returns the prefix."""
153142
return [bot.prefix, f'<@{bot.user.id}> ', f'<@!{bot.user.id}> ']
154143

155144
async def on_connect(self):
@@ -161,21 +150,21 @@ async def on_connect(self):
161150
await self.change_presence(activity=discord.Game(status))
162151

163152
async def on_ready(self):
164-
'''Bot startup, sets uptime.'''
165-
print(textwrap.dedent(f'''
153+
"""Bot startup, sets uptime."""
154+
print(textwrap.dedent(f"""
166155
{line}
167156
{Fore.CYAN}Client ready.
168157
{line}
169158
{Fore.CYAN}Logged in as: {self.user}
170159
{Fore.CYAN}User ID: {self.user.id}
171160
{Fore.CYAN}Guild ID: {self.guild.id if self.guild else 0}
172161
{line}
173-
''').strip())
174-
162+
""").strip())
163+
175164
await self.threads.populate_cache()
176165

177166
async def process_modmail(self, message):
178-
'''Processes messages sent to the bot.'''
167+
"""Processes messages sent to the bot."""
179168

180169
reaction = '🚫' if message.author.id in self.blocked_users else '✅'
181170

@@ -185,10 +174,10 @@ async def process_modmail(self, message):
185174
pass
186175

187176
blocked_em = discord.Embed(
188-
title='Message not sent!',
177+
title='Message not sent!',
189178
color=discord.Color.red(),
190179
description='You have been blocked from using modmail.'
191-
)
180+
)
192181

193182
if str(message.author.id) in self.blocked_users:
194183
await message.author.send(embed=blocked_em)
@@ -207,7 +196,6 @@ async def get_context(self, message, *, cls=commands.Context):
207196

208197
if self._skip_check(message.author.id, self.user.id):
209198
return ctx
210-
211199

212200
prefixes = [self.prefix, f'<@{bot.user.id}> ', f'<@!{bot.user.id}>']
213201

@@ -226,7 +214,7 @@ async def get_context(self, message, *, cls=commands.Context):
226214
invoker = view.get_word()
227215

228216
ctx.invoked_with = invoker
229-
ctx.prefix = self.prefix # Sane prefix (No mentions)
217+
ctx.prefix = self.prefix # Sane prefix (No mentions)
230218
ctx.command = self.all_commands.get(invoker)
231219

232220
# if hasattr(ctx, '_alias_invoked'):
@@ -246,11 +234,11 @@ async def on_message(self, message):
246234
cmd = message.content[len(prefix):].strip()
247235
if cmd in self.snippets:
248236
message.content = f'{prefix}reply {self.snippets[cmd]}'
249-
237+
250238
await self.process_commands(message)
251-
239+
252240
async def on_message_delete(self, message):
253-
'''Support for deleting linked messages'''
241+
"""Support for deleting linked messages"""
254242
if message.embeds and not isinstance(message.channel, discord.DMChannel):
255243
matches = re.findall(r'\d+', str(message.embeds[0].author.url))
256244
if matches:
@@ -261,10 +249,10 @@ async def on_message_delete(self, message):
261249

262250
async for msg in channel.history():
263251
if msg.embeds and msg.embeds[0].author:
264-
url = msg.embeds[0].author.url
252+
url = msg.embeds[0].author.url
265253
if message_id == re.findall(r'\d+', url):
266254
return await msg.delete()
267-
255+
268256
async def on_message_edit(self, before, after):
269257
if before.author.bot:
270258
return
@@ -279,15 +267,15 @@ async def on_message_edit(self, before, after):
279267
embed.description = after.content
280268
await msg.edit(embed=embed)
281269
break
282-
270+
283271
async def on_command_error(self, ctx, error):
284272
if isinstance(error, (commands.MissingRequiredArgument, commands.UserInputError)):
285273
await ctx.invoke(self.get_command('help'), command=str(ctx.command))
286274
else:
287275
raise error
288276

289277
def overwrites(self, ctx):
290-
'''Permision overwrites for the guild.'''
278+
"""Permision overwrites for the guild."""
291279
overwrites = {
292280
ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False)
293281
}
@@ -297,7 +285,7 @@ def overwrites(self, ctx):
297285
overwrites[role] = discord.PermissionOverwrite(read_messages=True)
298286

299287
return overwrites
300-
288+
301289
async def data_loop(self):
302290
await self.wait_until_ready()
303291

@@ -315,7 +303,7 @@ async def data_loop(self):
315303
await self.session.post('https://api.modmail.tk/metadata', json=data)
316304

317305
await asyncio.sleep(3600)
318-
306+
319307
async def autoupdate_loop(self):
320308
while True:
321309
if not self.config.get('autoupdates'):
@@ -334,7 +322,7 @@ async def autoupdate_loop(self):
334322
commit_data = data['data']
335323
user = data['user']
336324
em.set_author(name=user['username'], icon_url=user['avatar_url'], url=user['url'])
337-
em.set_footer(text=f"Updating modmail v{self.version} -> v{metadata['latest_version']}")
325+
em.set_footer(text=f"Updating modmail v{self.version} -> v{metadata['latest_version']}")
338326

339327
if commit_data:
340328
em.description = 'Bot successfully updated, the bot will restart momentarily'
@@ -344,15 +332,14 @@ async def autoupdate_loop(self):
344332
em.add_field(name='Merge Commit', value=f"[`{short_sha}`]({html_url}) {message} - {user['username']}")
345333
else:
346334
em.description = 'Already up to date with master repository.'
347-
335+
348336
em.add_field(name='Latest Commit', value=await self.get_latest_updates(limit=1), inline=False)
349337

350338
channel = self.main_category.channels[0]
351339
await channel.send(embed=em)
352340

353341
await asyncio.sleep(3600)
354342

355-
356343
async def get_latest_updates(self, limit=3):
357344
latest_commits = ''
358345

@@ -361,7 +348,6 @@ async def get_latest_updates(self, limit=3):
361348
short_sha = commit['sha'][:6]
362349
html_url = commit['html_url']
363350
message = commit['commit']['message'].splitlines()[0]
364-
author_name = commit['author']['login']
365351

366352
latest_commits += f'[`{short_sha}`]({html_url}) {message}\n'
367353

@@ -381,6 +367,7 @@ def uptime(self):
381367

382368
return fmt.format(d=days, h=hours, m=minutes, s=seconds)
383369

370+
384371
if __name__ == '__main__':
385372
bot = ModmailBot()
386373
bot.run()

0 commit comments

Comments
 (0)