From b690fbe0908eada31a6c347bdb668f27cd2eafd7 Mon Sep 17 00:00:00 2001 From: ziro Date: Wed, 15 Mar 2023 08:15:41 +0700 Subject: [PATCH] chore: Re-add deleted file --- .../models/0_20211009115827_init.sql | 87 +++++++++++++++++++ src/zibot/exts/meta/meta.py | 20 ++--- 2 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 src/main/migrations/models/0_20211009115827_init.sql diff --git a/src/main/migrations/models/0_20211009115827_init.sql b/src/main/migrations/models/0_20211009115827_init.sql new file mode 100644 index 00000000..3dbc6827 --- /dev/null +++ b/src/main/migrations/models/0_20211009115827_init.sql @@ -0,0 +1,87 @@ +-- upgrade -- +CREATE TABLE IF NOT EXISTS "commands" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "type" TEXT NOT NULL, + "name" TEXT NOT NULL, + "category" TEXT NOT NULL, + "description" TEXT, + "content" TEXT NOT NULL, + "url" TEXT, + "uses" BIGINT NOT NULL DEFAULT 0, + "ownerId" BIGINT NOT NULL, + "createdAt" TIMESTAMP NOT NULL, + "visibility" INT NOT NULL DEFAULT 0, + "enabled" INT NOT NULL DEFAULT 1 +); +CREATE TABLE IF NOT EXISTS "guilds" ( + "id" BIGINT NOT NULL PRIMARY KEY +); +CREATE TABLE IF NOT EXISTS "caseLog" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "caseId" BIGINT NOT NULL, + "type" TEXT NOT NULL, + "modId" BIGINT NOT NULL, + "targetId" BIGINT NOT NULL, + "reason" TEXT NOT NULL, + "createdAt" TIMESTAMP NOT NULL, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "commandsLookup" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "name" TEXT NOT NULL, + "cmd_id" BIGINT NOT NULL REFERENCES "commands" ("id") ON DELETE CASCADE, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "disabled" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "command" TEXT NOT NULL, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "guildChannels" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "welcomeCh" BIGINT, + "farewellCh" BIGINT, + "modlogCh" BIGINT, + "purgatoryCh" BIGINT, + "announcementCh" BIGINT, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "guildConfigs" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "ccMode" INT NOT NULL DEFAULT 0, + "tagMode" INT NOT NULL DEFAULT 0, + "welcomeMsg" TEXT, + "farewellMsg" TEXT, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "guildMutes" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "mutedId" BIGINT NOT NULL, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "guildRoles" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "modRole" BIGINT, + "mutedRole" BIGINT, + "autoRole" BIGINT, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "prefixes" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "prefix" TEXT NOT NULL, + "guild_id" BIGINT NOT NULL REFERENCES "guilds" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "timer" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "event" TEXT NOT NULL, + "extra" JSON NOT NULL, + "expires" TIMESTAMP NOT NULL, + "created" TIMESTAMP NOT NULL, + "owner" BIGINT NOT NULL +); +CREATE TABLE IF NOT EXISTS "aerich" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "version" VARCHAR(255) NOT NULL, + "app" VARCHAR(20) NOT NULL, + "content" JSON NOT NULL +); diff --git a/src/zibot/exts/meta/meta.py b/src/zibot/exts/meta/meta.py index 91496678..09dc1cdc 100644 --- a/src/zibot/exts/meta/meta.py +++ b/src/zibot/exts/meta/meta.py @@ -17,6 +17,7 @@ from ...core import checks from ...core import commands as cmds +from ...core.data import ExpiringDict from ...core.context import Context from ...core.embed import ZEmbed, ZEmbedBuilder from ...core.errors import DefaultError @@ -305,7 +306,12 @@ async def onHighlight(self, message: discord.Message): if message.author.bot or not message.content or not guild: return - channel = message.channel + channelId = message.channel.id + authorId = message.author.id + msgId = message.id + if not self.lastSeen.get(channelId): + self.lastSeen[channelId] = ExpiringDict(maxAgeSeconds=1800) + self.lastSeen[channelId][authorId] = msgId if not (guildHighlight := self.highlights.get(guild.id)): return @@ -315,8 +321,8 @@ async def onHighlight(self, message: discord.Message): continue # Getting context - msgs: List[discord.Message] = [message] - async for history in channel.history(limit=4, before=message.created_at): + msgs: list[discord.Message] = [message] + async for history in message.channel.history(limit=4, before=message.created_at): msgs.append(history) context = [] @@ -338,14 +344,8 @@ async def onHighlight(self, message: discord.Message): if owner == message.author.id: continue - # Check if member sent a message 30 minutes prior - if await channel.history( - after=utcnow() - dt.timedelta(minutes=30.0) - ).get(author__id=owner): - continue - user = guild.get_member(owner) or await guild.fetch_member(owner) - if user: + if user and self.lastSeen.get(channelId, {}).get(user.id): await user.send( "In {0.channel.mention} ({0.guild})".format(message), embed=e,