⭐ starts ⭐
This commit is contained in:
parent
e0b9f35a76
commit
dfdf1217d2
@ -48,7 +48,7 @@ class Reservation:
|
|||||||
def __enter__(self) -> Reserved:
|
def __enter__(self) -> Reserved:
|
||||||
container = self.__container()
|
container = self.__container()
|
||||||
if container is None:
|
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:
|
if self.__rc is None:
|
||||||
other = container.get(self.__key)
|
other = container.get(self.__key)
|
||||||
if other is not None:
|
if other is not None:
|
||||||
|
@ -10,7 +10,7 @@ from .db import AbstractConnection, AbstractDbFactory, AbstractDbManager
|
|||||||
|
|
||||||
|
|
||||||
def _load_key(key: Any, /) -> Hashable:
|
def _load_key(key: Any, /) -> Hashable:
|
||||||
"""note: unstable signature."""
|
"""⭐ note: unstable signature. ⭐"""
|
||||||
match key:
|
match key:
|
||||||
case Hashable():
|
case Hashable():
|
||||||
return key
|
return key
|
||||||
@ -19,7 +19,7 @@ def _load_key(key: Any, /) -> Hashable:
|
|||||||
case dict():
|
case dict():
|
||||||
return tuple((_load_key(k), _load_key(v)) for k, v in key.items())
|
return tuple((_load_key(k), _load_key(v)) for k, v in key.items())
|
||||||
case _:
|
case _:
|
||||||
raise TypeError("unknown json key type, cannot convert to hashable")
|
raise TypeError("⭐ unknown json key type, cannot convert to hashable ⭐")
|
||||||
|
|
||||||
|
|
||||||
class Adapter(AbstractConnection):
|
class Adapter(AbstractConnection):
|
||||||
|
@ -14,9 +14,9 @@ class Instrumentation:
|
|||||||
|
|
||||||
def __init__(self, target, methodname: str):
|
def __init__(self, target, methodname: str):
|
||||||
if not isinstance(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)):
|
if not callable(getattr(target, methodname)):
|
||||||
raise TypeError("target.methodname must be callable")
|
raise TypeError("⭐ target.methodname must be callable ⭐")
|
||||||
self.target = target
|
self.target = target
|
||||||
self.methodname = methodname
|
self.methodname = methodname
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class TypedReservations(Generic[T]):
|
|||||||
with self.reservations.reserve(key, factory) as reserved:
|
with self.reservations.reserve(key, factory) as reserved:
|
||||||
if not isinstance(reserved.value, self.type):
|
if not isinstance(reserved.value, self.type):
|
||||||
if factory_called:
|
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:
|
else:
|
||||||
yield reserved.value
|
yield reserved.value
|
||||||
break
|
break
|
||||||
@ -215,39 +215,39 @@ class Stars(commands.Cog):
|
|||||||
|
|
||||||
@commands.hybrid_command()
|
@commands.hybrid_command()
|
||||||
async def ping(self, ctx: commands.Context):
|
async def ping(self, ctx: commands.Context):
|
||||||
print("ping pong")
|
print("⭐ ping pong ⭐")
|
||||||
await ctx.reply("pong", mention_author=False)
|
await ctx.reply("pong", mention_author=False)
|
||||||
|
|
||||||
@commands.hybrid_command()
|
@commands.hybrid_command()
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def reload(self, ctx: commands.Context):
|
async def reload(self, ctx: commands.Context):
|
||||||
print("reload")
|
print("⭐ reload ⭐")
|
||||||
bot: commands.Bot = ctx.bot
|
bot: commands.Bot = ctx.bot
|
||||||
try:
|
try:
|
||||||
await bot.reload_extension("starbot.stars")
|
await bot.reload_extension("starbot.stars")
|
||||||
except commands.ExtensionNotLoaded:
|
except commands.ExtensionNotLoaded:
|
||||||
await ctx.reply("not loaded")
|
await ctx.reply("⭐ not loaded ⭐")
|
||||||
print("reloaded")
|
print("⭐ reloaded ⭐")
|
||||||
await ctx.reply("reloaded")
|
await ctx.reply("⭐ reloaded ⭐")
|
||||||
|
|
||||||
@commands.hybrid_command()
|
@commands.hybrid_command()
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def sync(self, ctx: commands.Context):
|
async def sync(self, ctx: commands.Context):
|
||||||
await ctx.bot.tree.sync()
|
await ctx.bot.tree.sync()
|
||||||
print("synced")
|
print("⭐ synced ⭐")
|
||||||
await ctx.reply("synced")
|
await ctx.reply("⭐ synced ⭐")
|
||||||
|
|
||||||
@commands.hybrid_command()
|
@commands.hybrid_command()
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def assign(self, ctx: commands.Context, count: int):
|
async def assign(self, ctx: commands.Context, count: int):
|
||||||
await AdminCtx(ctx).assign(count)
|
await AdminCtx(ctx).assign(count)
|
||||||
await ctx.reply("assigned")
|
await ctx.reply("⭐ assigned ⭐")
|
||||||
|
|
||||||
@commands.hybrid_command()
|
@commands.hybrid_command()
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def unassign(self, ctx: commands.Context):
|
async def unassign(self, ctx: commands.Context):
|
||||||
await AdminCtx(ctx).unassign()
|
await AdminCtx(ctx).unassign()
|
||||||
await ctx.reply("unassigned")
|
await ctx.reply("⭐ unassigned ⭐")
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_raw_reaction_add(self, event: discord.RawReactionActionEvent):
|
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):
|
async def throttle(self, ctx: commands.Context, duration: float, delay: float):
|
||||||
with Cooldown(StarEventCtx, "_on", delay):
|
with Cooldown(StarEventCtx, "_on", delay):
|
||||||
await asyncio.sleep(duration)
|
await asyncio.sleep(duration)
|
||||||
await ctx.reply(f"done")
|
await ctx.reply(f"⭐ done ⭐")
|
||||||
|
|
||||||
|
|
||||||
class Cooldown(Instrumentation):
|
class Cooldown(Instrumentation):
|
||||||
@ -293,10 +293,11 @@ async def setup(bot: StarBot):
|
|||||||
global cog
|
global cog
|
||||||
cog = Stars(bot)
|
cog = Stars(bot)
|
||||||
await bot.add_cog(cog)
|
await bot.add_cog(cog)
|
||||||
|
print("⭐ set up ⭐")
|
||||||
|
|
||||||
|
|
||||||
async def teardown(bot: StarBot):
|
async def teardown(bot: StarBot):
|
||||||
global cog
|
global cog
|
||||||
await bot.remove_cog(cog.qualified_name)
|
await bot.remove_cog(cog.qualified_name)
|
||||||
del cog
|
del cog
|
||||||
print("torn down")
|
print("⭐ torn down ⭐")
|
||||||
|
Loading…
Reference in New Issue
Block a user