mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 20:47:44 +00:00
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import aiomysql
|
|
import asyncio
|
|
from bot import CloudKid
|
|
from aiomysql.sa import SAConnection
|
|
from sqlalchemy import Table
|
|
from typing import Sequence
|
|
|
|
|
|
class AutoJoin:
|
|
@staticmethod
|
|
async def get_channels(bot: CloudKid) -> Sequence[tuple]:
|
|
autojoin: Table = bot.database.tables["autojoin"]
|
|
conn: SAConnection = await bot.database.engine.acquire()
|
|
result = await conn.execute(autojoin.select())
|
|
channels: Sequence[tuple] = await result.fetchall()
|
|
return channels
|
|
|
|
@staticmethod
|
|
async def update_channel(bot, guild_id, channel_id):
|
|
autojoin: Table = bot.database.tables["autojoin"]
|
|
conn: SAConnection = await bot.database.engine.acquire()
|
|
await conn.execute(autojoin.insert().values({
|
|
"guild_id": guild_id,
|
|
"channel_id": channel_id
|
|
}))
|
|
|
|
@staticmethod
|
|
async def del_channel(bot, guild_id):
|
|
autojoin: Table = bot.database.tables["autojoin"]
|
|
conn: SAConnection = await bot.database.engine.acquire()
|
|
await conn.execute(
|
|
autojoin.delete().where(autojoin.c.guild_id == guild_id))
|