Skip to content

Commit

Permalink
Resume rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Jun 4, 2024
1 parent b217fca commit 50387cd
Show file tree
Hide file tree
Showing 21 changed files with 966 additions and 1,188 deletions.
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ select = [
ignore = ["F405", "F403", "E501", "D203", "D205", "D213", "RUF001"]
fixable = ["I", "TCH", "D"]
line-length = 120
target-version = "py311"
target-version = "py312"

[tool.mypy]
ignore_errors = true # I use pyright only because mypy dumb

[tool.pyright]
pythonVersion = "3.11"
pythonVersion = "3.12"
typeCheckingMode = "basic"
reportPrivateUsage = "none"

[tool.poetry]
name = "snedbot"
version = "0.1.0" # I do not actually update this, lol
version = "0.1.0"
description = "Your friendly neighbourhood multi-purpose Discord bot."
authors = ["hypergonial <[email protected]>"]
license = "GNU GPL-v3"

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
python = ">=3.12,<3.13"
dateparser = "^1.1.8"
psutil = "^5.9.6"
Pillow = "^10.2.0"
Expand All @@ -49,13 +49,13 @@ aiodns = "~=3.1.1"
Brotli = "~=1.0"
ciso8601 = "~=2.3"
kosu = { git = "https://github.com/hypergonial/kosu.git" }
hikari-arc = "~=1.2.0"
hikari-arc = "~=1.3.4"
hikari-toolbox = "~=0.1.6"
hikari-miru = "~=4.0.0"
hikari-miru = "~=4.1.1"

[tool.poetry.dev-dependencies]
nox = "^2023.4.22"
ruff = "^0.1.14"
ruff = "^0.4.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
52 changes: 24 additions & 28 deletions src/extensions/command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
RoleHierarchyError,
UserBlacklistedError,
)
from src.utils import helpers

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -202,6 +201,15 @@ async def application_error_handler(ctx: SnedContext, error: BaseException) -> N
),
flags=hikari.MessageFlag.EPHEMERAL,
)
elif isinstance(error, arc.OptionConverterFailureError):
await ctx.respond(
embed=hikari.Embed(
title="❌ Option Conversion Error",
description=f"Failed to convert option `{error.option.name}` to `{error.option.option_type}`.",
color=const.ERROR_COLOR,
),
flags=hikari.MessageFlag.EPHEMERAL,
)
else:
logger.error("Ignoring exception in command {}:".format(ctx.command.name))
exception_msg = "\n".join(traceback.format_exception(type(error), error, error.__traceback__))
Expand All @@ -227,18 +235,12 @@ async def command_error_handler(event: arc.CommandErrorEvent[t.Any]) -> None:
await application_error_handler(event.context, event.exception)


# FIXME: Figure this out
@plugin.listener(lightbulb.UserCommandCompletionEvent)
@plugin.listener(lightbulb.SlashCommandCompletionEvent)
@plugin.listener(lightbulb.MessageCommandCompletionEvent)
async def application_command_completion_handler(event: lightbulb.events.CommandCompletionEvent):
if event.context.author.id in event.context.app.owner_ids and (
cm := event.command.cooldown_manager
): # Ignore cooldowns for owner c:
await cm.reset_cooldown(event.context)
async def client_post_hook(ctx: SnedContext) -> None:
if ctx.author.id in ctx.client.owner_ids:
ctx.command.reset_all_limiters(ctx)


@plugin.listener(lightbulb.PrefixCommandErrorEvent)
""" @plugin.listener(lightbulb.PrefixCommandErrorEvent)
async def prefix_error_handler(event: lightbulb.PrefixCommandErrorEvent) -> None:
if event.context.author.id not in event.app.owner_ids:
return
Expand All @@ -256,17 +258,9 @@ async def prefix_error_handler(event: lightbulb.PrefixCommandErrorEvent) -> None
color=const.ERROR_COLOR,
)
)
raise event.exception


@plugin.listener(lightbulb.events.CommandInvocationEvent)
async def command_invoke_listener(event: lightbulb.events.CommandInvocationEvent) -> None:
logger.info(
f"Command {event.command.name} was invoked by {event.context.author} in guild {event.context.guild_id}."
)
raise event.exception """


@plugin.listener(lightbulb.PrefixCommandInvocationEvent)
""" @plugin.listener(lightbulb.PrefixCommandInvocationEvent)
async def prefix_command_invoke_listener(event: lightbulb.PrefixCommandInvocationEvent) -> None:
if event.context.author.id not in event.app.owner_ids:
return
Expand All @@ -280,10 +274,14 @@ async def prefix_command_invoke_listener(event: lightbulb.PrefixCommandInvocatio
return
assert isinstance(event.context, SnedPrefixContext)
await event.context.event.message.add_reaction("▶️")
await event.context.event.message.add_reaction("▶️") """


async def on_command_invoke(ctx: SnedContext) -> None:
logger.info(f"Command '{ctx.command.qualified_name}' was invoked by '{ctx.author}' in guild {ctx.guild_id}.")

@plugin.listener(hikari.ExceptionEvent)

@plugin.listen()
async def event_error_handler(event: hikari.ExceptionEvent) -> None:
logging.error("Ignoring exception in listener {}:".format(event.failed_event.__class__.__name__))
exception_msg = "\n".join(traceback.format_exception(*event.exc_info))
Expand All @@ -294,11 +292,9 @@ async def event_error_handler(event: hikari.ExceptionEvent) -> None:
@arc.loader
def load(client: SnedClient) -> None:
client.add_plugin(plugin)


@arc.unloader
def unload(client: SnedClient) -> None:
client.remove_plugin(plugin)
client.add_hook(on_command_invoke)
client.add_post_hook(client_post_hook)
client.set_error_handler(application_error_handler)


# Copyright (C) 2022-present hypergonial
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def on_timeout(self) -> None:

class TrashView(AuthorOnlyView):
@miru.button(emoji="🗑️", style=hikari.ButtonStyle.SECONDARY)
async def trash(self, button: miru.Button, ctx: miru.ViewContext) -> None:
async def trash(self, ctx: miru.ViewContext, button: miru.Button) -> None:
assert self.message is not None
await self.message.delete()
self.stop()
Expand Down Expand Up @@ -79,7 +79,7 @@ async def send_paginated(

if len(text) <= 2000:
if channel_id:
view = TrashView(ctx, timeout=300)
view = TrashView(ctx.author, timeout=300)
message = await ctx.app.rest.create_message(
channel_id, f"{prefix}{format_output(text)}{suffix}", components=view
)
Expand All @@ -102,7 +102,7 @@ async def send_paginated(
for line in text.split("\n"):
paginator.add_line(format_output(line))

navmenu = OutputNav(ctx, pages=list(paginator.build_pages()), items=buttons, timeout=300)
navmenu = OutputNav(ctx.author, pages=list(paginator.build_pages()), items=buttons, timeout=300)

if not channel_id:
assert isinstance(messageable, hikari.User)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def check_winner(self) -> WinState | None:
value_1 += self.board[i][diag_offset_1]
value_2 += self.board[i][diag_offset_2]
diag_offset_1 -= 1
diag_offset_2 += 1
diag_offset_2 += 1 # noqa: SIM113
if value_1 == self.size or value_2 == self.size:
return WinState.PLAYER_O
elif value_1 == -self.size or value_2 == -self.size:
Expand Down
Loading

0 comments on commit 50387cd

Please sign in to comment.