feat: sync built-in sticker bot
This commit is contained in:
parent
7096625e13
commit
6867d201ed
60 changed files with 7063 additions and 144 deletions
1
deploy/migrations/0041_user_sticker_sets.down.sql
Normal file
1
deploy/migrations/0041_user_sticker_sets.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS public.user_sticker_sets;
|
||||
14
deploy/migrations/0041_user_sticker_sets.up.sql
Normal file
14
deploy/migrations/0041_user_sticker_sets.up.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
CREATE TABLE IF NOT EXISTS public.user_sticker_sets (
|
||||
owner_user_id bigint NOT NULL,
|
||||
sticker_set_id bigint NOT NULL,
|
||||
set_kind text DEFAULT 'stickers'::text NOT NULL,
|
||||
archived boolean DEFAULT false NOT NULL,
|
||||
installed_date integer DEFAULT 0 NOT NULL,
|
||||
order_value bigint DEFAULT 0 NOT NULL,
|
||||
updated_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT user_sticker_sets_pkey PRIMARY KEY (owner_user_id, sticker_set_id),
|
||||
CONSTRAINT user_sticker_sets_kind_check CHECK ((set_kind = ANY (ARRAY['stickers'::text, 'emoji'::text, 'masks'::text])))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS user_sticker_sets_order_idx
|
||||
ON public.user_sticker_sets USING btree (owner_user_id, set_kind, archived, order_value DESC, sticker_set_id DESC);
|
||||
14
deploy/migrations/0042_sticker_set_creator.down.sql
Normal file
14
deploy/migrations/0042_sticker_set_creator.down.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
DROP INDEX IF EXISTS public.sticker_sets_creator_idx;
|
||||
DROP INDEX IF EXISTS public.sticker_sets_short_name_lower_idx;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS sticker_sets_short_name_idx
|
||||
ON public.sticker_sets USING btree (short_name)
|
||||
WHERE (short_name <> ''::text);
|
||||
|
||||
ALTER TABLE public.sticker_sets
|
||||
DROP COLUMN IF EXISTS updated_at,
|
||||
DROP COLUMN IF EXISTS keywords,
|
||||
DROP COLUMN IF EXISTS software,
|
||||
DROP COLUMN IF EXISTS deleted,
|
||||
DROP COLUMN IF EXISTS text_color,
|
||||
DROP COLUMN IF EXISTS creator_user_id;
|
||||
17
deploy/migrations/0042_sticker_set_creator.up.sql
Normal file
17
deploy/migrations/0042_sticker_set_creator.up.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
ALTER TABLE public.sticker_sets
|
||||
ADD COLUMN IF NOT EXISTS creator_user_id bigint DEFAULT 0 NOT NULL,
|
||||
ADD COLUMN IF NOT EXISTS text_color boolean DEFAULT false NOT NULL,
|
||||
ADD COLUMN IF NOT EXISTS deleted boolean DEFAULT false NOT NULL,
|
||||
ADD COLUMN IF NOT EXISTS software text DEFAULT ''::text NOT NULL,
|
||||
ADD COLUMN IF NOT EXISTS keywords jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL;
|
||||
|
||||
DROP INDEX IF EXISTS public.sticker_sets_short_name_idx;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS sticker_sets_short_name_lower_idx
|
||||
ON public.sticker_sets USING btree (lower(short_name))
|
||||
WHERE (short_name <> ''::text AND deleted = false);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS sticker_sets_creator_idx
|
||||
ON public.sticker_sets USING btree (creator_user_id, id DESC)
|
||||
WHERE (creator_user_id <> 0 AND deleted = false);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
UPDATE sticker_sets
|
||||
SET installed = true,
|
||||
installed_date = CASE WHEN installed_date = 0 THEN 1 ELSE installed_date END
|
||||
WHERE set_kind <> 'system'
|
||||
AND creator_user_id IS NULL
|
||||
AND deleted = false;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
UPDATE sticker_sets
|
||||
SET installed = false,
|
||||
installed_date = 0
|
||||
WHERE installed = true
|
||||
OR installed_date <> 0;
|
||||
14
deploy/migrations/0044_stickers_service_bot.down.sql
Normal file
14
deploy/migrations/0044_stickers_service_bot.down.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
DELETE FROM public.bot_chat_states
|
||||
WHERE bot_user_id = 1063110917;
|
||||
|
||||
DELETE FROM public.bots
|
||||
WHERE bot_user_id = 1063110917;
|
||||
|
||||
DELETE FROM public.peer_usernames
|
||||
WHERE peer_type = 'user' AND peer_id = 1063110917;
|
||||
|
||||
DELETE FROM public.read_model_versions
|
||||
WHERE owner_user_id = 1063110917 AND peer_type = 'user' AND peer_id = 1063110917;
|
||||
|
||||
DELETE FROM public.users
|
||||
WHERE id = 1063110917;
|
||||
74
deploy/migrations/0044_stickers_service_bot.up.sql
Normal file
74
deploy/migrations/0044_stickers_service_bot.up.sql
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
INSERT INTO public.users (
|
||||
id, access_hash, phone, first_name, last_name, username, country_code,
|
||||
created_at, updated_at, verified, support, about, last_seen_at,
|
||||
default_history_ttl_period, is_bot, bot_info_version, premium_expires_at,
|
||||
emoji_status_document_id, emoji_status_until, color_set, color,
|
||||
color_background_emoji_id, profile_color_set, profile_color,
|
||||
profile_color_background_emoji_id
|
||||
) VALUES (
|
||||
1063110917, 5213187021149032991, '', 'Stickers', '', 'Stickers', '',
|
||||
now(), now(), true, false, 'Create custom sticker and emoji packs for telesrv.',
|
||||
0, 0, true, 2, NULL, 0, 0, false, 0, 0, false, 0, 0
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
access_hash = EXCLUDED.access_hash,
|
||||
phone = EXCLUDED.phone,
|
||||
first_name = EXCLUDED.first_name,
|
||||
last_name = EXCLUDED.last_name,
|
||||
username = EXCLUDED.username,
|
||||
verified = EXCLUDED.verified,
|
||||
support = EXCLUDED.support,
|
||||
about = EXCLUDED.about,
|
||||
is_bot = EXCLUDED.is_bot,
|
||||
bot_info_version = GREATEST(public.users.bot_info_version, EXCLUDED.bot_info_version),
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.bots (
|
||||
bot_user_id, owner_user_id, token_secret, description, commands,
|
||||
bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at,
|
||||
menu_button_type, menu_button_text, menu_button_url, bot_inline_geo
|
||||
) VALUES (
|
||||
1063110917, 1063110917, '',
|
||||
'Create custom sticker and emoji packs for telesrv.',
|
||||
'[
|
||||
{"command": "start", "description": "start the sticker pack assistant"},
|
||||
{"command": "help", "description": "show help"},
|
||||
{"command": "newpack", "description": "create a sticker pack"},
|
||||
{"command": "newemoji", "description": "create a custom emoji pack"},
|
||||
{"command": "addsticker", "description": "add to one of your packs"},
|
||||
{"command": "delsticker", "description": "remove one item from a pack"},
|
||||
{"command": "publish", "description": "publish the current pack"},
|
||||
{"command": "cancel", "description": "cancel the current operation"},
|
||||
{"command": "packs", "description": "list your created packs"}
|
||||
]'::jsonb,
|
||||
false, false, '', now(), now(), 0, '', '', false
|
||||
)
|
||||
ON CONFLICT (bot_user_id) DO UPDATE SET
|
||||
owner_user_id = EXCLUDED.owner_user_id,
|
||||
token_secret = EXCLUDED.token_secret,
|
||||
description = EXCLUDED.description,
|
||||
commands = EXCLUDED.commands,
|
||||
bot_chat_history = EXCLUDED.bot_chat_history,
|
||||
bot_nochats = EXCLUDED.bot_nochats,
|
||||
inline_placeholder = EXCLUDED.inline_placeholder,
|
||||
menu_button_type = EXCLUDED.menu_button_type,
|
||||
menu_button_text = EXCLUDED.menu_button_text,
|
||||
menu_button_url = EXCLUDED.menu_button_url,
|
||||
bot_inline_geo = EXCLUDED.bot_inline_geo,
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.peer_usernames (username_lower, peer_type, peer_id, updated_at)
|
||||
VALUES ('stickers', 'user', 1063110917, now())
|
||||
ON CONFLICT (username_lower) DO UPDATE SET
|
||||
peer_type = EXCLUDED.peer_type,
|
||||
peer_id = EXCLUDED.peer_id,
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.read_model_versions (model, owner_user_id, peer_type, peer_id, version, updated_at, hash)
|
||||
VALUES
|
||||
('contact_account', 1063110917, 'user', 1063110917, 1, now(), 6110917000001),
|
||||
('channel_active_memberships', 1063110917, 'user', 1063110917, 1, now(), 6110917000002)
|
||||
ON CONFLICT (model, owner_user_id, peer_type, peer_id) DO UPDATE SET
|
||||
version = GREATEST(public.read_model_versions.version, EXCLUDED.version),
|
||||
updated_at = now(),
|
||||
hash = EXCLUDED.hash;
|
||||
12
deploy/migrations/0045_stickers_bot_edit_commands.down.sql
Normal file
12
deploy/migrations/0045_stickers_bot_edit_commands.down.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
UPDATE public.bots
|
||||
SET commands = '[
|
||||
{"command": "start", "description": "start the sticker pack assistant"},
|
||||
{"command": "help", "description": "show help"},
|
||||
{"command": "newpack", "description": "create a sticker pack"},
|
||||
{"command": "newemoji", "description": "create a custom emoji pack"},
|
||||
{"command": "publish", "description": "publish the current pack"},
|
||||
{"command": "cancel", "description": "cancel the current operation"},
|
||||
{"command": "packs", "description": "list your created packs"}
|
||||
]'::jsonb,
|
||||
updated_at = now()
|
||||
WHERE bot_user_id = 1063110917;
|
||||
19
deploy/migrations/0045_stickers_bot_edit_commands.up.sql
Normal file
19
deploy/migrations/0045_stickers_bot_edit_commands.up.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
UPDATE public.users
|
||||
SET bot_info_version = GREATEST(bot_info_version, 2),
|
||||
updated_at = now()
|
||||
WHERE id = 1063110917;
|
||||
|
||||
UPDATE public.bots
|
||||
SET commands = '[
|
||||
{"command": "start", "description": "start the sticker pack assistant"},
|
||||
{"command": "help", "description": "show help"},
|
||||
{"command": "newpack", "description": "create a sticker pack"},
|
||||
{"command": "newemoji", "description": "create a custom emoji pack"},
|
||||
{"command": "addsticker", "description": "add to one of your packs"},
|
||||
{"command": "delsticker", "description": "remove one item from a pack"},
|
||||
{"command": "publish", "description": "publish the current pack"},
|
||||
{"command": "cancel", "description": "cancel the current operation"},
|
||||
{"command": "packs", "description": "list your created packs"}
|
||||
]'::jsonb,
|
||||
updated_at = now()
|
||||
WHERE bot_user_id = 1063110917;
|
||||
Loading…
Add table
Add a link
Reference in a new issue