starts

This commit is contained in:
AF 2024-03-30 15:15:10 +00:00
parent e0b9f35a76
commit dfdf1217d2
4 changed files with 18 additions and 17 deletions

View File

@ -48,7 +48,7 @@ class Reservation:
def __enter__(self) -> Reserved:
container = self.__container()
if container is None:
raise RuntimeError("can't reserve in a non-existent container")
raise RuntimeError("can't reserve in a non-existent container")
if self.__rc is None:
other = container.get(self.__key)
if other is not None:

View File

@ -10,7 +10,7 @@ from .db import AbstractConnection, AbstractDbFactory, AbstractDbManager
def _load_key(key: Any, /) -> Hashable:
"""note: unstable signature."""
"""note: unstable signature."""
match key:
case Hashable():
return key
@ -19,7 +19,7 @@ def _load_key(key: Any, /) -> Hashable:
case dict():
return tuple((_load_key(k), _load_key(v)) for k, v in key.items())
case _:
raise TypeError("unknown json key type, cannot convert to hashable")
raise TypeError("unknown json key type, cannot convert to hashable")
class Adapter(AbstractConnection):

View File

@ -14,9 +14,9 @@ class Instrumentation:
def __init__(self, target, methodname: str):
if not isinstance(methodname, str):
raise TypeError("methodname must be str")
raise TypeError("methodname must be str")
if not callable(getattr(target, methodname)):
raise TypeError("target.methodname must be callable")
raise TypeError("target.methodname must be callable")
self.target = target
self.methodname = methodname

View File

@ -35,7 +35,7 @@ class TypedReservations(Generic[T]):
with self.reservations.reserve(key, factory) as reserved:
if not isinstance(reserved.value, self.type):
if factory_called:
raise TypeError("factory seems to have returned a value of incorrect type")
raise TypeError("factory seems to have returned a value of incorrect type")
else:
yield reserved.value
break
@ -215,39 +215,39 @@ class Stars(commands.Cog):
@commands.hybrid_command()
async def ping(self, ctx: commands.Context):
print("ping pong")
print("ping pong")
await ctx.reply("pong", mention_author=False)
@commands.hybrid_command()
@commands.is_owner()
async def reload(self, ctx: commands.Context):
print("reload")
print("reload")
bot: commands.Bot = ctx.bot
try:
await bot.reload_extension("starbot.stars")
except commands.ExtensionNotLoaded:
await ctx.reply("not loaded")
print("reloaded")
await ctx.reply("reloaded")
await ctx.reply("not loaded")
print("reloaded")
await ctx.reply("reloaded")
@commands.hybrid_command()
@commands.is_owner()
async def sync(self, ctx: commands.Context):
await ctx.bot.tree.sync()
print("synced")
await ctx.reply("synced")
print("synced")
await ctx.reply("synced")
@commands.hybrid_command()
@commands.has_permissions(administrator=True)
async def assign(self, ctx: commands.Context, count: int):
await AdminCtx(ctx).assign(count)
await ctx.reply("assigned")
await ctx.reply("assigned")
@commands.hybrid_command()
@commands.has_permissions(administrator=True)
async def unassign(self, ctx: commands.Context):
await AdminCtx(ctx).unassign()
await ctx.reply("unassigned")
await ctx.reply("unassigned")
@commands.Cog.listener()
async def on_raw_reaction_add(self, event: discord.RawReactionActionEvent):
@ -265,7 +265,7 @@ class Stars(commands.Cog):
async def throttle(self, ctx: commands.Context, duration: float, delay: float):
with Cooldown(StarEventCtx, "_on", delay):
await asyncio.sleep(duration)
await ctx.reply(f"done")
await ctx.reply(f"done")
class Cooldown(Instrumentation):
@ -293,10 +293,11 @@ async def setup(bot: StarBot):
global cog
cog = Stars(bot)
await bot.add_cog(cog)
print("⭐ set up ⭐")
async def teardown(bot: StarBot):
global cog
await bot.remove_cog(cog.qualified_name)
del cog
print("torn down")
print("torn down")