mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
chore: clean up message_context function
remove CTEs that were confusing and led to developer error
This commit is contained in:
parent
b2322c6366
commit
f65c20f31e
1 changed files with 41 additions and 36 deletions
|
|
@ -21,50 +21,55 @@
|
||||||
deny_bot_usage bool
|
deny_bot_usage bool
|
||||||
)
|
)
|
||||||
as $$
|
as $$
|
||||||
-- CTEs to query "static" (accessible only through args) data
|
|
||||||
with
|
|
||||||
system as (select systems.*, system_config.latch_timeout, system_guild.tag as guild_tag, system_guild.tag_enabled as tag_enabled,
|
|
||||||
system_guild.avatar_url as guild_avatar,
|
|
||||||
allow_autoproxy as account_autoproxy, system_config.case_sensitive_proxy_tags, system_config.proxy_error_message_enabled from accounts
|
|
||||||
left join systems on systems.id = accounts.system
|
|
||||||
left join system_config on system_config.system = accounts.system
|
|
||||||
left join system_guild on system_guild.system = accounts.system and system_guild.guild = guild_id
|
|
||||||
where accounts.uid = account_id),
|
|
||||||
guild as (select * from servers where id = guild_id)
|
|
||||||
select
|
select
|
||||||
system.id as system_id,
|
-- accounts table
|
||||||
guild.log_channel,
|
accounts.allow_autoproxy as allow_autoproxy,
|
||||||
((channel_id = any (guild.blacklist))
|
|
||||||
or (thread_id = any (guild.blacklist))) as in_blacklist,
|
-- systems table
|
||||||
((channel_id = any (guild.log_blacklist))
|
systems.id as system_id,
|
||||||
or (thread_id = any (guild.log_blacklist))) as in_log_blacklist,
|
systems.tag as system_tag,
|
||||||
coalesce(guild.log_cleanup_enabled, false),
|
systems.avatar_url as system_avatar,
|
||||||
coalesce(system_guild.proxy_enabled, true) as proxy_enabled,
|
|
||||||
system_last_switch.switch as last_switch,
|
-- system_config table
|
||||||
system_last_switch.members as last_switch_members,
|
system_config.latch_timeout as latch_timeout,
|
||||||
system_last_switch.timestamp as last_switch_timestamp,
|
system_config.case_sensitive_proxy_tags as case_sensitive_proxy_tags,
|
||||||
system.tag as system_tag,
|
system_config.proxy_error_message_enabled as proxy_error_message_enabled
|
||||||
system.guild_tag as system_guild_tag,
|
|
||||||
coalesce(system.tag_enabled, true) as tag_enabled,
|
-- system_guild table
|
||||||
system.avatar_url as system_avatar,
|
coalesce(system_guild.tag_enabled, true) as tag_enabled,
|
||||||
system.guild_avatar as system_guild_avatar,
|
coalesce(system_guild.proxy_enabled, true) as proxy_enabled,
|
||||||
system.account_autoproxy as allow_autoproxy,
|
system_guild.tag as system_guild_tag,
|
||||||
system.latch_timeout as latch_timeout,
|
system_guild.avatar_url as system_guild_avatar,
|
||||||
system.case_sensitive_proxy_tags as case_sensitive_proxy_tags,
|
|
||||||
system.proxy_error_message_enabled as proxy_error_message_enabled,
|
-- system_last_switch view
|
||||||
coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage
|
system_last_switch.switch as last_switch,
|
||||||
|
system_last_switch.members as last_switch_members,
|
||||||
|
system_last_switch.timestamp as last_switch_timestamp,
|
||||||
|
|
||||||
|
-- servers table
|
||||||
|
servers.log_channel as log_channel,
|
||||||
|
((channel_id = any (servers.blacklist))
|
||||||
|
or (thread_id = any (servers.blacklist))) as in_blacklist,
|
||||||
|
((channel_id = any (servers.log_blacklist))
|
||||||
|
or (thread_id = any (servers.log_blacklist))) as in_log_blacklist,
|
||||||
|
coalesce(servers.log_cleanup_enabled, false) as log_cleanup_enabled,
|
||||||
|
|
||||||
|
-- abuse_logs table
|
||||||
|
coalesce(abuse_logs.deny_bot_usage, false) as deny_bot_usage
|
||||||
|
|
||||||
-- We need a "from" clause, so we just use some bogus data that's always present
|
-- We need a "from" clause, so we just use some bogus data that's always present
|
||||||
-- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data
|
-- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data
|
||||||
from (select 1) as _placeholder
|
from (select 1) as _placeholder
|
||||||
left join system on true
|
|
||||||
left join guild on true
|
|
||||||
left join accounts on accounts.uid = account_id
|
left join accounts on accounts.uid = account_id
|
||||||
left join system_last_switch on system_last_switch.system = system.id
|
left join servers on servers.id = guild_id
|
||||||
left join system_guild on system_guild.system = system.id and system_guild.guild = guild_id
|
left join systems on systems.id = accounts.system
|
||||||
|
left join system_config on system_config.system = accounts.system
|
||||||
|
left join system_guild on system_guild.system = accounts.system
|
||||||
|
and system_guild.guild = guild_id
|
||||||
|
left join system_last_switch on system_last_switch.system = accounts.system
|
||||||
left join abuse_logs on abuse_logs.id = accounts.abuse_log
|
left join abuse_logs on abuse_logs.id = accounts.abuse_log
|
||||||
$$ language sql stable rows 1;
|
$$ language sql stable rows 1;
|
||||||
|
|
||||||
|
|
||||||
-- Fetches info about proxying related to a given account/guild
|
-- Fetches info about proxying related to a given account/guild
|
||||||
-- Returns one row per member in system, should be used in conjuction with `message_context` too
|
-- Returns one row per member in system, should be used in conjuction with `message_context` too
|
||||||
create function proxy_members(account_id bigint, guild_id bigint)
|
create function proxy_members(account_id bigint, guild_id bigint)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue