From 23ba0fb8fc5070ba30a43035970775247da370f3 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Tue, 26 Mar 2024 15:26:06 -0400 Subject: teleport: don't teleport within same channel, better text --- markov/data/init.sql | 45 ----------------------------------------- markov/data/migrations/init.sql | 45 +++++++++++++++++++++++++++++++++++++++++ markov/markov.py | 5 +++-- teleport/teleport.py | 30 ++++++++++++++++++--------- 4 files changed, 68 insertions(+), 57 deletions(-) delete mode 100644 markov/data/init.sql create mode 100644 markov/data/migrations/init.sql diff --git a/markov/data/init.sql b/markov/data/init.sql deleted file mode 100644 index 71ec073..0000000 --- a/markov/data/init.sql +++ /dev/null @@ -1,45 +0,0 @@ -CREATE TABLE IF NOT EXISTS guild_total_completion_count ( - guild_id BLOB, - first_token TEXT, - total_completion_count INTEGER, - UNIQUE (guild_id, first_token) -) STRICT; - -CREATE TABLE IF NOT EXISTS guild_pairs ( - guild_id BLOB, - first_token TEXT, - second_token TEXT, - frequency INTEGER, - UNIQUE (guild_id, first_token, second_token) -) STRICT; - -CREATE INDEX IF NOT EXISTS idx_guild_pairs__guild_id__first_token__frequency__second_token ON guild_pairs (guild_id, first_token, frequency, second_token); - -CREATE TABLE IF NOT EXISTS member_total_completion_count ( - guild_id BLOB, - member_id BLOB, - first_token TEXT, - total_completion_count INTEGER, - UNIQUE (guild_id, member_id, first_token) -) STRICT; - -CREATE TABLE IF NOT EXISTS member_pairs ( - guild_id BLOB, - member_id BLOB, - first_token TEXT, - second_token TEXT, - frequency INTEGER, - UNIQUE (guild_id, member_id, first_token, second_token) -) STRICT; - -CREATE INDEX IF NOT EXISTS idx_member_pairs__guild_id__member_id__first_token__frequency__second_token ON member_pairs ( - guild_id, - member_id, - first_token, - frequency, - second_token -); - -PRAGMA analysis_limit = 1000; - -PRAGMA optimize; diff --git a/markov/data/migrations/init.sql b/markov/data/migrations/init.sql new file mode 100644 index 0000000..71ec073 --- /dev/null +++ b/markov/data/migrations/init.sql @@ -0,0 +1,45 @@ +CREATE TABLE IF NOT EXISTS guild_total_completion_count ( + guild_id BLOB, + first_token TEXT, + total_completion_count INTEGER, + UNIQUE (guild_id, first_token) +) STRICT; + +CREATE TABLE IF NOT EXISTS guild_pairs ( + guild_id BLOB, + first_token TEXT, + second_token TEXT, + frequency INTEGER, + UNIQUE (guild_id, first_token, second_token) +) STRICT; + +CREATE INDEX IF NOT EXISTS idx_guild_pairs__guild_id__first_token__frequency__second_token ON guild_pairs (guild_id, first_token, frequency, second_token); + +CREATE TABLE IF NOT EXISTS member_total_completion_count ( + guild_id BLOB, + member_id BLOB, + first_token TEXT, + total_completion_count INTEGER, + UNIQUE (guild_id, member_id, first_token) +) STRICT; + +CREATE TABLE IF NOT EXISTS member_pairs ( + guild_id BLOB, + member_id BLOB, + first_token TEXT, + second_token TEXT, + frequency INTEGER, + UNIQUE (guild_id, member_id, first_token, second_token) +) STRICT; + +CREATE INDEX IF NOT EXISTS idx_member_pairs__guild_id__member_id__first_token__frequency__second_token ON member_pairs ( + guild_id, + member_id, + first_token, + frequency, + second_token +); + +PRAGMA analysis_limit = 1000; + +PRAGMA optimize; diff --git a/markov/markov.py b/markov/markov.py index d7cf14b..9965d65 100644 --- a/markov/markov.py +++ b/markov/markov.py @@ -36,7 +36,8 @@ class Markov(commands.Cog): async def cog_load(self): with open( - redbot.core.data_manager.bundled_data_path(self) / "init.sql", "r" + redbot.core.data_manager.bundled_data_path(self) / "migrations/init.sql", + "r", ) as setup_script_file: async with aiosqlite.connect(self.db_path) as db: await db.executescript(setup_script_file.read()) @@ -92,7 +93,7 @@ class Markov(commands.Cog): + [ token for token in re.findall( - r"[\w']+|[\.,!?\/;\(\)]||<#\d+>|<@!?\d+>", content + r"[\w']+|[\.,!?/;()]||<#\d+>|<@!?\d+>", content ) if len(token) <= MAX_TOKEN_LENGTH ] diff --git a/teleport/teleport.py b/teleport/teleport.py index a4c8100..f529e91 100644 --- a/teleport/teleport.py +++ b/teleport/teleport.py @@ -2,6 +2,7 @@ import discord from redbot.core import commands import redbot.core + class Teleport(commands.Cog): def __init__(self, bot): self.bot = bot @@ -13,7 +14,7 @@ class Teleport(commands.Cog): ctx: commands.GuildContext, destination: discord.abc.GuildChannel | discord.Thread, *, - reason: str | None + topic: str | None, ): if isinstance(destination, discord.Thread): parent = destination.parent @@ -27,26 +28,35 @@ class Teleport(commands.Cog): not isinstance(destination, discord.Thread) or parent.permissions_for(ctx.author).send_messages_in_threads ) + ) or ( + (type(ctx.channel) is type(destination)) + and ctx.channel.id == destination.id ): await ctx.react_quietly("❌") return - formatted_reason = redbot.core.utils.chat_formatting.italics(reason) if reason else "" + formatted_topic = ( + redbot.core.utils.chat_formatting.italics(topic) if topic else "" + ) - portal_to_template = "Portal opened to {dest}" f" : {formatted_reason}\n*(done by {ctx.author.mention})*" + # The space before the colon is necessary to prevent unwanted embeds + # of the link due to the way Discord parses messages as of 2024-03-24. + portal_to_template = ( + "Portal opened to {dest}" + + (f" : {formatted_topic}" if formatted_topic else "") + + f"\n*(done by {ctx.author.mention})*" + ) source_message = await ctx.send( - portal_to_template.format( - dest=destination.mention - ), + portal_to_template.format(dest=destination.mention), allowed_mentions=discord.AllowedMentions.none(), ) dest_message = await destination.send( - f"Portal opened from {source_message.jump_url} : {formatted_reason}\n*(done by {ctx.author.mention})*", + f"Portal opened from {source_message.jump_url}" + + (f" : {formatted_topic}" if formatted_topic else "") + + f"\n*(done by {ctx.author.mention})*", allowed_mentions=discord.AllowedMentions.none(), ) await source_message.edit( - content=portal_to_template.format( - dest=dest_message.jump_url - ), + content=portal_to_template.format(dest=dest_message.jump_url), allowed_mentions=discord.AllowedMentions.none(), ) -- cgit v1.2.3-57-g22cb