From 4fb089b3cf0b95cc2a127983ccff2e17727d0fa0 Mon Sep 17 00:00:00 2001 From: johnvictorfs <37747572+johnvictorfs@users.noreply.github.com> Date: Thu, 13 Jul 2023 11:36:26 -0300 Subject: [PATCH] Fix bot not properly using custom context --- bot/bot_client.py | 16 ++++++++-------- bot/utils/context.py | 6 +++--- pyproject.toml | 3 +++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bot/bot_client.py b/bot/bot_client.py index 32344c4..6a452a4 100644 --- a/bot/bot_client.py +++ b/bot/bot_client.py @@ -67,17 +67,17 @@ async def post_data( return request - # async def process_commands(self, message: discord.Message): - # """ - # Source: https://github.com/Rapptz/RoboDanny/blob/0c9216245b035fa4655f740c3ce602a5e15bff90/bot.py#L164 - # """ + async def process_commands(self, message: discord.Message): + """ + Source: https://discordpy.readthedocs.io/en/latest/migrating_to_v1.html#subclassing-context + """ - # ctx = await self.get_context(message, cls=context.Context) + ctx = await self.get_context(message, cls=context.Context) - # if not ctx.command: - # return + if not ctx.command: + return - # await self.invoke(ctx) + await self.invoke(ctx) async def close(self): """ diff --git a/bot/utils/context.py b/bot/utils/context.py index 3864d9e..5a3dc9d 100644 --- a/bot/utils/context.py +++ b/bot/utils/context.py @@ -1,11 +1,11 @@ from atlantisbot_api.models import DiscordUser -from bot.settings import Settings import io import discord import asyncio from typing import Optional from discord.ext import commands +from bot.bot_client import Bot class Context(commands.Context): @@ -15,8 +15,8 @@ class Context(commands.Context): def __init__(self, *args, **kwargs): super(Context, self).__init__(*args, **kwargs) - self.bot = self.bot - self.setting: Settings = self.bot.setting + self.bot: Bot = self.bot + self.setting = self.bot.setting async def entry_to_code(self, entries): width = max(len(a) for a, b in entries) diff --git a/pyproject.toml b/pyproject.toml index 146827e..2727a56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,3 +37,6 @@ build-backend = "poetry.masonry.api" [tool.ruff] line-length = 120 + +[tool.mypy] +check_untyped_defs = true