fixes
This commit is contained in:
parent
0794a9392d
commit
4bf043d140
@ -49,8 +49,10 @@ def main():
|
|||||||
try:
|
try:
|
||||||
loop.run_until_complete(task)
|
loop.run_until_complete(task)
|
||||||
except (KeyboardInterrupt, InterruptedError, RuntimeError):
|
except (KeyboardInterrupt, InterruptedError, RuntimeError):
|
||||||
close(bot, loop)
|
try:
|
||||||
loop.run_until_complete(task)
|
close(bot, loop)
|
||||||
|
finally:
|
||||||
|
loop.run_until_complete(task)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -6,8 +6,6 @@ from typing import Any
|
|||||||
|
|
||||||
import aiosqlite
|
import aiosqlite
|
||||||
|
|
||||||
from starbot.db import AbstractDbManager
|
|
||||||
|
|
||||||
from .db import AbstractConnection, AbstractDbFactory, AbstractDbManager
|
from .db import AbstractConnection, AbstractDbFactory, AbstractDbManager
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ class Adapter(AbstractConnection):
|
|||||||
async def manager(path: Path):
|
async def manager(path: Path):
|
||||||
async with aiosqlite.connect(path) as connection:
|
async with aiosqlite.connect(path) as connection:
|
||||||
db: dict[Hashable, Any] = {}
|
db: dict[Hashable, Any] = {}
|
||||||
await connection.execute("CREATE TABLE IF NOT EXISTS kv(key, value)")
|
await connection.execute("CREATE TABLE IF NOT EXISTS kv(key PRIMARY KEY, value)")
|
||||||
for key, value in await connection.execute_fetchall("SELECT key, value FROM kv"):
|
for key, value in await connection.execute_fetchall("SELECT key, value FROM kv"):
|
||||||
db[_load_key(json.loads(key))] = json.loads(value)
|
db[_load_key(json.loads(key))] = json.loads(value)
|
||||||
yield Adapter(connection, db)
|
yield Adapter(connection, db)
|
||||||
|
@ -8,10 +8,9 @@ from typing import AsyncContextManager, Callable, Generic, Hashable, Type, TypeV
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from starbot.instrumentation import Instrumentation
|
|
||||||
|
|
||||||
from .bot import Reservations, StarBot, StarState
|
from .bot import Reservations, StarBot, StarState
|
||||||
from .db import AbstractConnection
|
from .db import AbstractConnection
|
||||||
|
from .instrumentation import Instrumentation
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ class MessageState:
|
|||||||
|
|
||||||
return inner()
|
return inner()
|
||||||
|
|
||||||
async def __aexit__(self, et, ev, tb, /):
|
async def __aexit__(self, et, _ev, _tb, /):
|
||||||
return et and issubclass(et, EventuallyConsistent)
|
return et and issubclass(et, EventuallyConsistent)
|
||||||
|
|
||||||
|
|
||||||
@ -199,10 +198,11 @@ class ReactionCtx:
|
|||||||
async def on(self) -> None:
|
async def on(self) -> None:
|
||||||
if self.name != "⭐":
|
if self.name != "⭐":
|
||||||
return
|
return
|
||||||
assignment: dict[str, int] | None = self.connection.get(("assign", self.guild_id), None)
|
match self.connection.get(("assign", self.guild_id), None):
|
||||||
if assignment is None:
|
case {"channel": int() as star_channel_id, "count": int() as count}:
|
||||||
return
|
pass
|
||||||
star_channel_id, count = assignment["channel"], assignment["count"]
|
case _:
|
||||||
|
return
|
||||||
if self.channel_id == star_channel_id:
|
if self.channel_id == star_channel_id:
|
||||||
return
|
return
|
||||||
await StarEventCtx(self, star_channel_id, count).on()
|
await StarEventCtx(self, star_channel_id, count).on()
|
||||||
|
Loading…
Reference in New Issue
Block a user