mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Add 5-minute commercial break
This commit is contained in:
parent
677b60c4d1
commit
e9ff060875
1 changed files with 17 additions and 7 deletions
|
@ -17,11 +17,13 @@ class McDataBase:
|
||||||
async def init_db(self):
|
async def init_db(self):
|
||||||
if self._conn:
|
if self._conn:
|
||||||
conn = self._conn
|
conn = self._conn
|
||||||
|
now = round(discord.utils.utcnow().timestamp(), 2)
|
||||||
await conn.execute(
|
await conn.execute(
|
||||||
"""
|
f"""
|
||||||
CREATE TABLE IF NOT EXISTS breaks (
|
CREATE TABLE IF NOT EXISTS breaks (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY,
|
||||||
since FLOAT NOT NULL
|
since FLOAT NOT NULL,
|
||||||
|
started FLOAT NOT NULL DEFAULT {now}
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -34,10 +36,10 @@ class McDataBase:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_break(self, user_id: int) -> typing.Optional[tuple[float]]:
|
async def get_break(self, user_id: int) -> typing.Optional[tuple[float, float]]:
|
||||||
async with self._conn.execute(
|
async with self._conn.execute(
|
||||||
"""
|
"""
|
||||||
SELECT since FROM breaks WHERE user_id = ?;
|
SELECT since, started FROM breaks WHERE user_id = ?;
|
||||||
""",
|
""",
|
||||||
(user_id,)
|
(user_id,)
|
||||||
) as cursor:
|
) as cursor:
|
||||||
|
@ -114,7 +116,7 @@ class McDonaldsCog(commands.Cog):
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
NIGHTMARE_REGEX = re.compile(r"(\|\|.+\|\|)?(?P<username>[a-zA-Z0-9]{2,32}).*")
|
NIGHTMARE_REGEX = re.compile(r"(\|\|.+\|\|)?(?P<username>[a-zA-Z0-9]{2,32}).*")
|
||||||
if m := NIGHTMARE_REGEX.match(message.content):
|
if m := NIGHTMARE_REGEX.match(message.content):
|
||||||
username = m.group(1)
|
username = m.group("username")
|
||||||
member = discord.utils.get(message.guild.members, name=username)
|
member = discord.utils.get(message.guild.members, name=username)
|
||||||
if member:
|
if member:
|
||||||
author = member
|
author = member
|
||||||
|
@ -122,8 +124,16 @@ class McDonaldsCog(commands.Cog):
|
||||||
async with McDataBase() as db:
|
async with McDataBase() as db:
|
||||||
if (last_info := await db.get_break(author.id)) is not None:
|
if (last_info := await db.get_break(author.id)) is not None:
|
||||||
if message.content.upper() != "MCDONALDS!":
|
if message.content.upper() != "MCDONALDS!":
|
||||||
await message.delete()
|
if (message.created_at.timestamp() - last_info[1]) > 300:
|
||||||
if (message.created_at.timestamp() - last_info[0]) > 10:
|
await db.remove_break(author.id)
|
||||||
|
await message.reply(
|
||||||
|
f"Thank you for your patience during this commercial break. You may now resume your"
|
||||||
|
f" activity.",
|
||||||
|
delete_after=120
|
||||||
|
)
|
||||||
|
|
||||||
|
elif (message.created_at.timestamp() - last_info[0]) > 10:
|
||||||
|
await message.delete(delay=0)
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
f"{message.author.mention} Please say `MCDONALDS!` to end commercial.",
|
f"{message.author.mention} Please say `MCDONALDS!` to end commercial.",
|
||||||
delete_after=30
|
delete_after=30
|
||||||
|
|
Loading…
Reference in a new issue