mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 01:42:30 -05:00
do better with loop cleanup (#3245)
* do better with loop cleanup * changelog * remove redundant line * Do this a bit better than the initial pass * Improve windows support Make some other things coroutines to work with improved design * Wish we'd have done this right from the start... * Update deps surrounding this - see bpo-23057 - neccessary for windows users - nice for consistent support channel info / feature availability * dep issue * Fix tests * duplication plugin py version * actually handle this * Reconfigure some checks with codeclimate, disable pylint for now * style * Is my exasperation showing yet? * handle some stupid stuff * meh * dep changelog
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import datetime
|
||||
from typing import Union, List, Optional
|
||||
from typing import Union, List, Optional, TYPE_CHECKING
|
||||
from functools import wraps
|
||||
|
||||
import discord
|
||||
@@ -8,9 +10,12 @@ import discord
|
||||
from redbot.core.utils.chat_formatting import humanize_number
|
||||
from . import Config, errors, commands
|
||||
from .i18n import Translator
|
||||
from .bot import Red
|
||||
|
||||
from .errors import BankPruneError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .bot import Red
|
||||
|
||||
_ = Translator("Bank API", __file__)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
@@ -13,8 +14,12 @@ from types import MappingProxyType
|
||||
import discord
|
||||
from discord.ext.commands import when_mentioned_or
|
||||
|
||||
from . import Config, i18n, commands, errors, drivers
|
||||
from .cog_manager import CogManager
|
||||
from . import Config, i18n, commands, errors, drivers, modlog, bank
|
||||
from .cog_manager import CogManager, CogManagerUI
|
||||
from .core_commands import license_info_command, Core
|
||||
from .dev_commands import Dev
|
||||
from .events import init_events
|
||||
from .global_checks import init_global_checks
|
||||
|
||||
from .rpc import RPCMixin
|
||||
from .utils import common_filters
|
||||
@@ -43,6 +48,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
||||
|
||||
def __init__(self, *args, cli_flags=None, bot_dir: Path = Path.cwd(), **kwargs):
|
||||
self._shutdown_mode = ExitCodes.CRITICAL
|
||||
self._cli_flags = cli_flags
|
||||
self._config = Config.get_core_conf(force_registration=False)
|
||||
self._co_owners = cli_flags.co_owner
|
||||
self.rpc_enabled = cli_flags.rpc
|
||||
@@ -392,6 +398,18 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
||||
"""
|
||||
await self._maybe_update_config()
|
||||
|
||||
init_global_checks(self)
|
||||
init_events(self, cli_flags)
|
||||
|
||||
self.add_cog(Core(self))
|
||||
self.add_cog(CogManagerUI())
|
||||
self.add_command(license_info_command)
|
||||
if cli_flags.dev:
|
||||
self.add_cog(Dev())
|
||||
|
||||
await modlog._init(self)
|
||||
bank._init()
|
||||
|
||||
packages = []
|
||||
|
||||
if cli_flags.no_cogs is False:
|
||||
@@ -971,6 +989,10 @@ class Red(RedBase, discord.AutoShardedClient):
|
||||
"""Logs out of Discord and closes all connections."""
|
||||
await super().logout()
|
||||
await drivers.get_driver_class().teardown()
|
||||
try:
|
||||
await self.rpc.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
async def shutdown(self, *, restart: bool = False):
|
||||
"""Gracefully quit Red.
|
||||
@@ -990,6 +1012,7 @@ class Red(RedBase, discord.AutoShardedClient):
|
||||
self._shutdown_mode = ExitCodes.RESTART
|
||||
|
||||
await self.logout()
|
||||
sys.exit(self._shutdown_mode)
|
||||
|
||||
|
||||
class ExitCodes(Enum):
|
||||
|
||||
@@ -33,9 +33,8 @@ def confirm(text: str, default: Optional[bool] = None) -> bool:
|
||||
print("Error: invalid input")
|
||||
|
||||
|
||||
def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
loop = asyncio.get_event_loop()
|
||||
token = ""
|
||||
async def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
token = None
|
||||
|
||||
if print_header:
|
||||
print("Red - Discord Bot | Configuration process\n")
|
||||
@@ -51,9 +50,9 @@ def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
token = input("> ")
|
||||
if not len(token) >= 50:
|
||||
print("That doesn't look like a valid token.")
|
||||
token = ""
|
||||
token = None
|
||||
if token:
|
||||
loop.run_until_complete(red._config.token.set(token))
|
||||
await red._config.token.set(token)
|
||||
|
||||
if not prefix_set:
|
||||
prefix = ""
|
||||
@@ -70,7 +69,7 @@ def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
if not confirm("Your prefix seems overly long. Are you sure that it's correct?"):
|
||||
prefix = ""
|
||||
if prefix:
|
||||
loop.run_until_complete(red._config.prefix.set([prefix]))
|
||||
await red._config.prefix.set([prefix])
|
||||
|
||||
return token
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import codecs
|
||||
import datetime
|
||||
import logging
|
||||
import traceback
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
|
||||
import aiohttp
|
||||
@@ -17,7 +16,6 @@ from redbot.core.commands import RedHelpFormatter
|
||||
from .. import __version__ as red_version, version_info as red_version_info, VersionInfo
|
||||
from . import commands
|
||||
from .config import get_latest_confs
|
||||
from .data_manager import storage_type
|
||||
from .utils.chat_formatting import inline, bordered, format_perms_list, humanize_timedelta
|
||||
from .utils import fuzzy_command_search, format_fuzzy_results
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List, Union, Optional, cast
|
||||
from typing import List, Union, Optional, cast, TYPE_CHECKING
|
||||
|
||||
import discord
|
||||
|
||||
from redbot.core import Config
|
||||
from redbot.core.bot import Red
|
||||
|
||||
from .utils.common_filters import (
|
||||
filter_invites,
|
||||
@@ -17,6 +18,9 @@ from .i18n import Translator
|
||||
|
||||
from .generic_casetypes import all_generics
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from redbot.core.bot import Red
|
||||
|
||||
__all__ = [
|
||||
"Case",
|
||||
"CaseType",
|
||||
|
||||
Reference in New Issue
Block a user