update(core): migrate to py3.10 & dpy2.0
This commit is contained in:
parent
0eca877c1c
commit
1b7f153ec8
17 changed files with 69 additions and 52 deletions
|
@ -1,6 +1,8 @@
|
|||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="romain">
|
||||
<words>
|
||||
<w>aaaa</w>
|
||||
<w>ajout</w>
|
||||
<w>anglais</w>
|
||||
<w>anonyme</w>
|
||||
<w>appdirs</w>
|
||||
|
@ -9,7 +11,9 @@
|
|||
<w>commandstats</w>
|
||||
<w>ctype</w>
|
||||
<w>debian</w>
|
||||
<w>dnskey</w>
|
||||
<w>découverte</w>
|
||||
<w>ffff</w>
|
||||
<w>fonction</w>
|
||||
<w>francais</w>
|
||||
<w>français</w>
|
||||
|
@ -29,6 +33,7 @@
|
|||
<w>outoutxyz</w>
|
||||
<w>outouxyz</w>
|
||||
<w>pacman</w>
|
||||
<w>perso</w>
|
||||
<w>postgre</w>
|
||||
<w>postgresql</w>
|
||||
<w>pred</w>
|
||||
|
@ -36,6 +41,7 @@
|
|||
<w>pylint</w>
|
||||
<w>releaselevel</w>
|
||||
<w>rprint</w>
|
||||
<w>skipcq</w>
|
||||
<w>socketstats</w>
|
||||
<w>soit</w>
|
||||
<w>sondage</w>
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (tuxbot-bot)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tuxbot_bot)" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -6,7 +6,7 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (venv)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (tuxbot_bot)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
|
|
@ -7,6 +7,5 @@
|
|||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/tuxbot/cogs/Crypto/deps/ralgo" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
Makefile
1
Makefile
|
@ -15,7 +15,6 @@ XGETTEXT_FLAGS := --no-wrap --language='python' --keyword=_ --from-code='UTF-8'
|
|||
# Init
|
||||
.PHONY: main
|
||||
main:
|
||||
$(PYTHON_PATH) -m venv --clear $(VENV)
|
||||
$(VIRTUAL_ENV)/bin/pip install -U pip setuptools
|
||||
|
||||
.PHONY: install
|
||||
|
|
22
setup.cfg
22
setup.cfg
|
@ -15,20 +15,20 @@ platforms = linux
|
|||
packages = find_namespace:
|
||||
python_requires = >=3.9
|
||||
install_requires =
|
||||
asyncpg==0.21.0
|
||||
Babel==2.8.0
|
||||
asyncpg>=0.21.0
|
||||
Babel>=2.8.0
|
||||
discord.py @ git+https://github.com/Rapptz/discord.py
|
||||
humanize==2.6.0
|
||||
ipinfo==4.1.0
|
||||
ipwhois==1.2.0
|
||||
humanize>=2.6.0
|
||||
ipinfo>=4.1.0
|
||||
ipwhois>=1.2.0
|
||||
jishaku @ git+https://github.com/Gorialis/jishaku
|
||||
psutil==5.7.2
|
||||
pydig==0.3.0
|
||||
ralgo @ git+https://github.com/Rom1-J/ralgo
|
||||
rich==9.10.0
|
||||
psutil>=5.7.2
|
||||
pydig>=0.3.0
|
||||
; ralgo @ git+https://github.com/Rom1-J/ralgo
|
||||
rich>=9.10.0
|
||||
sentry_sdk>=0.20.2
|
||||
structured_config==4.12
|
||||
tortoise-orm==0.16.17
|
||||
structured_config>=4.12
|
||||
tortoise-orm>=0.16.17
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
|
|
|
@ -14,11 +14,15 @@ def main() -> None:
|
|||
else:
|
||||
raise exc
|
||||
except Exception:
|
||||
console.print_exception(show_locals=True)
|
||||
console.print_exception(
|
||||
show_locals=True, word_wrap=True, extra_lines=5
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception:
|
||||
console.print_exception(show_locals=True)
|
||||
console.print_exception(
|
||||
show_locals=True, word_wrap=True, extra_lines=5
|
||||
)
|
||||
|
|
|
@ -173,9 +173,9 @@ async def run_bot(tux: Tux, cli_flags: Namespace) -> None:
|
|||
try:
|
||||
await tux.load_packages()
|
||||
console.print()
|
||||
await tux.start(token=token, bot=True)
|
||||
await tux.start(token=token)
|
||||
except discord.LoginFailure:
|
||||
log.critical("This token appears to be valid.")
|
||||
log.critical("This token appears to be invalid.")
|
||||
console.print()
|
||||
console.print(
|
||||
"[prompt.invalid]This token appears to be valid. [i]exiting...[/i]"
|
||||
|
|
|
@ -25,6 +25,7 @@ class Dev(commands.Cog, name="Dev"):
|
|||
if crash_type == "ZeroDivisionError":
|
||||
await ctx.send(str(5 / 0))
|
||||
elif crash_type == "TypeError":
|
||||
# noinspection PyTypeChecker
|
||||
await ctx.send(str(int([])))
|
||||
elif crash_type == "IndexError":
|
||||
await ctx.send(str([0][5]))
|
||||
|
|
|
@ -51,9 +51,9 @@ class Logs(commands.Cog, name="Logs"):
|
|||
def __init__(self, bot: Tux):
|
||||
self.bot = bot
|
||||
self.process = psutil.Process()
|
||||
self._batch_lock = asyncio.Lock(loop=bot.loop)
|
||||
self._batch_lock = asyncio.Lock()
|
||||
self._data_batch = []
|
||||
self._gateway_queue = asyncio.Queue(loop=bot.loop)
|
||||
self._gateway_queue = asyncio.Queue()
|
||||
self.gateway_worker.start() # pylint: disable=no-member
|
||||
|
||||
self.__config: LogsConfig = ConfigFile(
|
||||
|
@ -88,7 +88,7 @@ class Logs(commands.Cog, name="Logs"):
|
|||
def webhook(self, log_type):
|
||||
webhook = discord.Webhook.from_url(
|
||||
getattr(self.__config, log_type),
|
||||
adapter=discord.AsyncWebhookAdapter(self.bot.session),
|
||||
session=self.bot.session,
|
||||
)
|
||||
return webhook
|
||||
|
||||
|
|
|
@ -239,6 +239,7 @@ class Utils(commands.Cog, name="Utils"):
|
|||
cmd = self.bot.get_command(name)
|
||||
|
||||
if cmd:
|
||||
# noinspection PyUnresolvedReferences
|
||||
src = cmd.callback.__code__
|
||||
rpath = src.co_filename
|
||||
else:
|
||||
|
|
|
@ -89,11 +89,16 @@ class Tux(commands.AutoShardedBot):
|
|||
self.uptime = None
|
||||
self.last_on_ready = None
|
||||
self._app_owners_fetched = False # to prevent abusive API calls
|
||||
self.loop = asyncio.get_event_loop()
|
||||
|
||||
self.before_invoke(self._typing)
|
||||
|
||||
super().__init__(
|
||||
*args, help_command=None, intents=discord.Intents.all(), **kwargs
|
||||
*args,
|
||||
# help_command=None,
|
||||
intents=discord.Intents.all(),
|
||||
loop=self.loop,
|
||||
**kwargs,
|
||||
)
|
||||
self.session = aiohttp.ClientSession(loop=self.loop)
|
||||
|
||||
|
@ -269,7 +274,7 @@ class Tux(commands.AutoShardedBot):
|
|||
if not await self._is_blacklisted(message):
|
||||
await self.process_commands(message)
|
||||
|
||||
async def start(self, token, bot): # pylint: disable=arguments-differ
|
||||
async def start(self, token): # pylint: disable=arguments-differ
|
||||
"""Connect to Discord and start all connections."""
|
||||
with Progress() as progress:
|
||||
task = progress.add_task(
|
||||
|
@ -309,7 +314,7 @@ class Tux(commands.AutoShardedBot):
|
|||
start=False,
|
||||
)
|
||||
progress.update(task_id)
|
||||
await super().start(token, bot=bot)
|
||||
await super().start(token)
|
||||
|
||||
async def logout(self):
|
||||
"""Disconnect from Discord and closes all actives connections.
|
||||
|
@ -335,7 +340,7 @@ class Tux(commands.AutoShardedBot):
|
|||
task.cancel()
|
||||
await asyncio.gather(*pending, return_exceptions=False)
|
||||
|
||||
await super().logout()
|
||||
await super().close()
|
||||
|
||||
async def shutdown(self, *, restart: bool = False):
|
||||
"""Gracefully quit.
|
||||
|
|
|
@ -14,6 +14,7 @@ __all__ = [
|
|||
"search_for",
|
||||
"set_for_key",
|
||||
"set_for",
|
||||
"set_if_none",
|
||||
]
|
||||
|
||||
log = logging.getLogger("tuxbot.core.config")
|
||||
|
|
|
@ -3,4 +3,4 @@ from rich.traceback import install
|
|||
|
||||
|
||||
console = Console()
|
||||
install(console=console, show_locals=True)
|
||||
install(console=console, show_locals=True, width=console.width)
|
||||
|
|
|
@ -13,6 +13,7 @@ IP_REPLACEMENT = "■" * random.randint(3, 15)
|
|||
|
||||
|
||||
class ContextPlus(commands.Context):
|
||||
# noinspection PyTypedDict
|
||||
async def send(
|
||||
self,
|
||||
content=None,
|
||||
|
@ -31,6 +32,7 @@ class ContextPlus(commands.Context):
|
|||
replace_in_list,
|
||||
)
|
||||
|
||||
# todo: rewrite replacements
|
||||
if content:
|
||||
content = (
|
||||
content.replace(self.bot.config.Core.token, TOKEN_REPLACEMENT)
|
||||
|
|
|
@ -13,6 +13,27 @@ formatter = logging.Formatter(
|
|||
)
|
||||
|
||||
|
||||
def _setup_logging(level: int, location: pathlib.Path, name: str) -> None:
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(level)
|
||||
logger_file = location / f"{name}.log"
|
||||
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
str(logger_file.resolve()),
|
||||
maxBytes=MAX_BYTES,
|
||||
backupCount=MAX_OLD_LOGS,
|
||||
)
|
||||
|
||||
base_handler = logging.handlers.RotatingFileHandler(
|
||||
str(logger_file.resolve()),
|
||||
maxBytes=MAX_BYTES,
|
||||
backupCount=MAX_OLD_LOGS,
|
||||
)
|
||||
|
||||
handler.setFormatter(formatter)
|
||||
base_handler.setFormatter(formatter)
|
||||
|
||||
|
||||
def init_logging(level: int, location: pathlib.Path) -> None:
|
||||
"""Initialize loggers.
|
||||
|
||||
|
@ -24,30 +45,8 @@ def init_logging(level: int, location: pathlib.Path) -> None:
|
|||
Where to store Logs.
|
||||
"""
|
||||
|
||||
# dpy_logger = logging.getLogger("discord")
|
||||
# dpy_logger.setLevel(logging.WARN)
|
||||
# dpy_logger_file = location / "discord.log"
|
||||
|
||||
base_logger = logging.getLogger("tuxbot")
|
||||
base_logger.setLevel(level)
|
||||
base_logger_file = location / "tuxbot.log"
|
||||
|
||||
# dpy_handler = logging.handlers.RotatingFileHandler(
|
||||
# str(dpy_logger_file.resolve()),
|
||||
# maxBytes=MAX_BYTES,
|
||||
# backupCount=MAX_OLD_LOGS,
|
||||
# )
|
||||
base_handler = logging.handlers.RotatingFileHandler(
|
||||
str(base_logger_file.resolve()),
|
||||
maxBytes=MAX_BYTES,
|
||||
backupCount=MAX_OLD_LOGS,
|
||||
)
|
||||
_setup_logging(level, location, "discord")
|
||||
_setup_logging(level, location, "tuxbot")
|
||||
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
stdout_handler.setFormatter(formatter)
|
||||
|
||||
# dpy_handler.setFormatter(formatter)
|
||||
base_handler.setFormatter(formatter)
|
||||
|
||||
# dpy_logger.addHandler(dpy_handler)
|
||||
base_logger.addHandler(base_handler)
|
||||
|
|
|
@ -328,7 +328,7 @@ def update() -> None:
|
|||
)
|
||||
|
||||
if response.get("sha")[:6] == version_info.build:
|
||||
print("Nothing to update, you can run `tuxbot` " "to start the bot")
|
||||
print("Nothing to update, you can run `tuxbot` to start the bot")
|
||||
else:
|
||||
print(f"Updating to {response.get('sha')[:6]}...")
|
||||
|
||||
|
|
Loading…
Reference in a new issue