|
@@ -32,11 +32,16 @@ async def count_command(message, context):
|
|
|
args = message.text.split("count", maxsplit=1)[1].strip().split()
|
|
|
name = args[0] if len(args) > 0 else "main"
|
|
|
async with context.database() as db:
|
|
|
- await db.execute("INSERT INTO counter VALUES (?, 1) \
|
|
|
+ await db.execute(
|
|
|
+ "INSERT INTO counter VALUES (?, 1) \
|
|
|
ON CONFLICT (name) DO \
|
|
|
- UPDATE SET count=count + 1", (name,))
|
|
|
+ UPDATE SET count=count + 1",
|
|
|
+ (name,),
|
|
|
+ )
|
|
|
await db.commit()
|
|
|
- async with db.execute("SELECT count FROM counter WHERE name = ?", (name,)) as cursor:
|
|
|
+ async with db.execute(
|
|
|
+ "SELECT count FROM counter WHERE name = ?", (name,)
|
|
|
+ ) as cursor:
|
|
|
res = (await cursor.fetchone())[0]
|
|
|
await context.respond(rollbot.Response.from_message(message, f"{name} = {res}"))
|
|
|
|
|
@@ -44,16 +49,20 @@ async def count_command(message, context):
|
|
|
@rollbot.on_startup
|
|
|
async def make_table(context):
|
|
|
async with context.database() as db:
|
|
|
- await db.execute("CREATE TABLE IF NOT EXISTS counter ( \
|
|
|
+ await db.execute(
|
|
|
+ "CREATE TABLE IF NOT EXISTS counter ( \
|
|
|
name TEXT NOT NULL PRIMARY KEY, \
|
|
|
count INTEGER NOT NULL DEFAULT 0 \
|
|
|
- );")
|
|
|
+ );"
|
|
|
+ )
|
|
|
await db.commit()
|
|
|
|
|
|
|
|
|
@rollbot.on_shutdown
|
|
|
async def shutdown(context):
|
|
|
- await context.respond(rollbot.Response(origin_id="REPL", channel_id=".", text="Shutting down!"))
|
|
|
+ await context.respond(
|
|
|
+ rollbot.Response(origin_id="REPL", channel_id=".", text="Shutting down!")
|
|
|
+ )
|
|
|
|
|
|
|
|
|
@rollbot.as_command
|
|
@@ -77,7 +86,7 @@ async def coroutine():
|
|
|
async def asyncgen():
|
|
|
yield "This is"
|
|
|
await asyncio.sleep(0.5)
|
|
|
- yield "an async"
|
|
|
+ yield "an async"
|
|
|
await asyncio.sleep(0.5)
|
|
|
yield "generator!"
|
|
|
|
|
@@ -102,6 +111,7 @@ config = rollbot.get_command_config().extend(
|
|
|
|
|
|
bot = MyBot(config, "/tmp/my.db")
|
|
|
|
|
|
+
|
|
|
async def run():
|
|
|
await bot.on_startup()
|
|
|
try:
|
|
@@ -112,4 +122,4 @@ async def run():
|
|
|
await bot.on_shutdown()
|
|
|
|
|
|
|
|
|
-asyncio.run(run())
|
|
|
+asyncio.run(run())
|