Skip to content

Commit

Permalink
Fix bot not properly using custom context
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvictorfs committed Jul 13, 2023
1 parent bbfd69a commit 4fb089b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions bot/bot_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions bot/utils/context.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ build-backend = "poetry.masonry.api"

[tool.ruff]
line-length = 120

[tool.mypy]
check_untyped_defs = true

0 comments on commit 4fb089b

Please sign in to comment.