|
1 | 1 | __version__ = "5.0.0-alpha.1" |
2 | 2 |
|
3 | | - |
4 | 3 | import asyncio |
5 | 4 | import copy |
6 | 5 | import hashlib |
|
10 | 9 | import sys |
11 | 10 | import typing |
12 | 11 | from datetime import datetime, timedelta, timezone |
13 | | -from subprocess import PIPE |
14 | 12 | from types import SimpleNamespace |
| 13 | +from typing import Optional |
15 | 14 |
|
16 | 15 | import discord |
17 | 16 | import isodate |
18 | | -from aiohttp import ClientResponseError, ClientSession |
| 17 | +from aiohttp import ClientSession |
19 | 18 | from dateutil import parser |
20 | 19 | from discord.ext import commands, tasks |
21 | 20 | from discord.ext.commands.view import StringView |
|
33 | 32 | pass |
34 | 33 |
|
35 | 34 | from core import checks |
36 | | -from core.changelog import Changelog |
37 | | -from core.clients import ApiClient, MongoDBClient, PluginDatabaseClient |
| 35 | +from core.clients import MongoDBClient, PluginDatabaseClient |
38 | 36 | from core.config import ConfigManager |
39 | 37 | from core.models import ( |
40 | 38 | DMDisabled, |
41 | 39 | HostingMethod, |
42 | | - InvalidConfigError, |
43 | 40 | PermissionLevel, |
44 | 41 | SafeFormatter, |
45 | 42 | configure_logging, |
46 | 43 | getLogger, |
47 | 44 | ) |
48 | | -from core.thread import ThreadManager |
| 45 | +from core.thread import Thread, ThreadManager |
49 | 46 | from core.time import human_timedelta |
50 | | -from core.utils import human_join, normalize_alias, parse_alias, truncate, tryint, extract_forwarded_content |
| 47 | +from core.utils import extract_forwarded_content, human_join, normalize_alias, parse_alias, truncate, tryint |
51 | 48 |
|
52 | 49 | logger = getLogger(__name__) |
53 | 50 |
|
|
61 | 58 | except AttributeError: |
62 | 59 | logger.error("Failed to use WindowsProactorEventLoopPolicy.", exc_info=True) |
63 | 60 |
|
64 | | - |
| 61 | +class ModmailCommandContext(commands.Context["ModmailBot"]): |
| 62 | + thread: Optional[Thread] |
65 | 63 | class ModmailBot(commands.Bot): |
66 | 64 | def __init__(self): |
67 | 65 | self.config = ConfigManager(self) |
@@ -1416,19 +1414,20 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) |
1416 | 1414 | ctx.command.checks = old_checks |
1417 | 1415 | continue |
1418 | 1416 |
|
1419 | | - async def get_context(self, message, *, cls=commands.Context): |
| 1417 | + async def get_context(self, message, *, cls=ModmailCommandContext): |
1420 | 1418 | """ |
1421 | 1419 | Returns the invocation context from the message. |
1422 | 1420 | Supports getting the prefix from database. |
1423 | 1421 | """ |
1424 | 1422 |
|
1425 | 1423 | view = StringView(message.content) |
1426 | | - ctx = cls(prefix=self.prefix, view=view, bot=self, message=message) |
| 1424 | + ctx: ModmailCommandContext = cls(prefix=self.prefix, view=view, bot=self, message=message) |
1427 | 1425 |
|
1428 | 1426 | if message.author.id == self.user.id: |
1429 | 1427 | return ctx |
1430 | 1428 |
|
1431 | | - ctx.thread = await self.threads.find(channel=ctx.channel) |
| 1429 | + if isinstance(ctx.channel, discord.TextChannel): |
| 1430 | + ctx.thread = await self.threads.find(channel=ctx.channel) |
1432 | 1431 |
|
1433 | 1432 | prefixes = await self.get_prefix() |
1434 | 1433 |
|
|
0 commit comments