o
    ®¤±jÑ`  ã                   @   s  d dl Z d dlZd dlmZmZ e j e j e j e¡¡d¡Z	de
de
fdd„Zde
fdd	„Zde
d
e
de
fdd„Zde
d
e
de
fdd„Zde
defdd„Zde
dede
dB de
def
dd„Zde
dededB fdd„Zde
dedefdd„Zde
dee fdd„Zde
dee fdd„Z		dude
ded ed!ed"ed#edefd$d%„Zde
ded ed!efd&d'„Zde
ded ed"ed#ef
d(d)„Zde
ded ed*ed+ef
d,d-„Zde
ded ededB fd.d/„Zde
d!ededB fd0d1„Zde
d"ed#ededB fd2d3„Zde
d*ededB fd4d5„Z de
d+ededB fd6d7„Z!de
dede
dB de
fd8d9„Z"de
defd:d;„Z#de
dee fd<d=„Z$de
dedefd>d?„Z%de
fd@dA„Z&	Bdvde
dCedDe
dEe
dB dFe
dB dGe
fdHdI„Z'de
dee fdJdK„Z(de
dLefdMdN„Z)de
dLedFe
fdOdP„Z*de
dQedRe
de
dB dFe
dB f
dSdT„Z+de
dee fdUdV„Z,de
dWefdXdY„Z-de
fdZd[„Z.de
fd\d]„Z/de
defd^d_„Z0d`da„ Z1de
dbe
dce
dde
def
dedf„Z2de
dee fdgdh„Z3de
diededB fdjdk„Z4			l	dwde
diedbe
dce
dde
dme
dne
doe
dpefdqdr„Z5de
diefdsdt„Z6dS )xé    N)ÚdatetimeÚ	timedeltaÚdatabaseÚbot_usernameÚreturnc                 C   s&   t jtdd� t j t|  ¡ › d�¡S )NT)Úexist_okz.db)ÚosÚmakedirsÚDB_DIRÚpathÚjoinÚlower)r   © r   úcobots/communication/db.pyÚget_db_path   s   r   c              	   Ã   s4  �t | ƒ}t |¡4 I d H š}| d¡I d H  | d¡I d H  | d¡I d H  | d¡I d H  | d¡I d H  | d¡I d H  | d¡I d H  | d¡I d H  | d	¡I d H  g d
¢}|D ]\}}| d||f¡I d H  q]| dt ¡  ¡ f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s“w   Y  d S )NzŒ
            CREATE TABLE IF NOT EXISTS settings (
                key   TEXT PRIMARY KEY,
                value TEXT
            )
        aj  
            CREATE TABLE IF NOT EXISTS users (
                id            INTEGER PRIMARY KEY,
                username      TEXT,
                first_name    TEXT,
                is_muted      INTEGER DEFAULT 0,
                is_blocked    INTEGER DEFAULT 0,
                last_active   TEXT,
                joined_at     TEXT
            )
        zÙ
            CREATE TABLE IF NOT EXISTS admins (
                id         INTEGER PRIMARY KEY,
                username   TEXT,
                first_name TEXT,
                added_at   TEXT
            )
        a  
            CREATE TABLE IF NOT EXISTS messages (
                id                  INTEGER PRIMARY KEY AUTOINCREMENT,
                user_id             INTEGER NOT NULL,
                user_message_id     INTEGER NOT NULL,
                dev_message_id      INTEGER,
                group_message_id    INTEGER,
                group_chat_id       INTEGER,
                reply_message_id    INTEGER,
                reply_dev_msg_id    INTEGER,
                created_at          TEXT
            )
        z[
            CREATE INDEX IF NOT EXISTS idx_messages_user_id ON messages (user_id)
        aâ  
            CREATE TABLE IF NOT EXISTS mandatory_channels (
                id               INTEGER PRIMARY KEY AUTOINCREMENT,
                channel_id       INTEGER UNIQUE NOT NULL,
                channel_username TEXT,
                channel_title    TEXT NOT NULL,
                invite_link      TEXT,
                display_type     TEXT DEFAULT 'buttons',
                is_active        INTEGER DEFAULT 1,
                added_at         TEXT
            )
        az  
            CREATE TABLE IF NOT EXISTS groups (
                id          INTEGER PRIMARY KEY AUTOINCREMENT,
                chat_id     INTEGER UNIQUE NOT NULL,
                chat_title  TEXT NOT NULL,
                username    TEXT,
                invite_link TEXT,
                is_active   INTEGER DEFAULT 1,
                added_at    TEXT
            )
        a  
            CREATE TABLE IF NOT EXISTS message_stats (
                id          INTEGER PRIMARY KEY AUTOINCREMENT,
                sent        INTEGER DEFAULT 0,
                received    INTEGER DEFAULT 0,
                updated_at  TEXT
            )
        a_  
            CREATE TABLE IF NOT EXISTS custom_buttons (
                id          INTEGER PRIMARY KEY AUTOINCREMENT,
                btn_type    TEXT NOT NULL,
                label       TEXT NOT NULL,
                content     TEXT NOT NULL,
                position    INTEGER DEFAULT 0,
                created_at  TEXT
            )
        ))Úis_openÚ1)Únotify_new_usersr   )Únotify_blockedr   )Úreceive_in_groupÚ0)Úwelcome_messageÚ )Úsend_btn_labelu
   Ø¥Ø±Ø³Ø§Ù„)Úsend_btn_colorÚdefault)Úsend_btn_emojir   )Úback_btn_labelu   Ø±Ø¬ÙˆØ¹)Úback_btn_colorr   )Úback_btn_emojir   z9INSERT OR IGNORE INTO settings (key, value) VALUES (?, ?)zXINSERT OR IGNORE INTO message_stats (id, sent, received, updated_at) VALUES (1, 0, 0, ?))r   Ú	aiosqliteÚconnectÚexecuter   ÚutcnowÚ	isoformatÚcommit)r   Údb_pathÚdbÚdefaultsÚkeyÚvaluer   r   r   Úinit_db   s0   €		þ
þ.‹r+   r)   c              
   Ã   s¾   �t  t| ƒ¡4 I d H šF}| d|f¡4 I d H š$}| ¡ I d H }|r&|d ndW  d   ƒI d H  W  d   ƒI d H  S 1 I d H sBw   Y  W d   ƒI d H  d S 1 I d H sXw   Y  d S )Nz(SELECT value FROM settings WHERE key = ?r   r   ©r    r!   r   r"   Úfetchone)r   r)   r'   ÚcurÚrowr   r   r   Úget_settingŒ   s   €þÿ.ÿr0   r*   c              	   Ã   sn   �t  t| ƒ¡4 I d H š}| d||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s0w   Y  d S )Nz:INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)©r    r!   r   r"   r%   )r   r)   r*   r'   r   r   r   Úset_setting“   ó   €
þ.ûr2   c              
   Ã   ó¸   �t  t| ƒ¡4 I d H šC}| d¡4 I d H š#}| ¡ I d H }dd„ |D ƒW  d   ƒI d H  W  d   ƒI d H  S 1 I d H s?w   Y  W d   ƒI d H  d S 1 I d H sUw   Y  d S )NzSELECT key, value FROM settingsc                 S   s   i | ]	}|d  |d “qS )r   é   r   )Ú.0r/   r   r   r   Ú
<dictcomp>    s    z$get_all_settings.<locals>.<dictcomp>©r    r!   r   r"   Úfetchall©r   r'   r.   Úrowsr   r   r   Úget_all_settingsœ   ó   €þÿ.ÿr<   Úuser_idÚusernameÚ
first_namec              
   Ã   sP  �t  ¡  ¡ }t t| ƒ¡4 I d H š‰}| d|f¡4 I d H š}| ¡ I d H }W d   ƒI d H  n1 I d H s6w   Y  |se| d|||||f¡I d H  | ¡ I d H  |||dd|dœW  d   ƒI d H  S | d||||f¡I d H  | ¡ I d H  |d |d |d |d |d	 |d
 |d dœW  d   ƒI d H  S 1 I d H s¡w   Y  d S )Nú SELECT * FROM users WHERE id = ?z[INSERT INTO users (id, username, first_name, last_active, joined_at) VALUES (?, ?, ?, ?, ?)r   )Úidr?   r@   Úis_mutedÚ
is_blockedÚ	joined_atzKUPDATE users SET username = ?, first_name = ?, last_active = ? WHERE id = ?r5   é   é   é   é   é   ©rB   r?   r@   rC   rD   Úlast_activerE   )	r   r#   r$   r    r!   r   r"   r-   r%   )r   r>   r?   r@   Únowr'   r.   r/   r   r   r   Úget_or_create_user£   s4   €(ÿ
þÿ÷

þþ0ïrN   c              
   Ã   s  �t  t| ƒ¡4 I d H šm}| d|f¡4 I d H šK}| ¡ I d H }|s7	 W d   ƒI d H  W d   ƒI d H  d S |d |d |d |d |d |d |d d	œW  d   ƒI d H  W  d   ƒI d H  S 1 I d H siw   Y  W d   ƒI d H  d S 1 I d H sw   Y  d S )
NrA   r   r5   rF   rG   rH   rI   rJ   rK   r,   )r   r>   r'   r.   r/   r   r   r   Úget_user¼   s    €ýÿþüÿ.ÿrO   Úmutedc              	   Ã   sv   �t  t| ƒ¡4 I d H š"}| d|rdnd|f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s4w   Y  d S )Nz*UPDATE users SET is_muted = ? WHERE id = ?r5   r   r1   )r   r>   rP   r'   r   r   r   Úset_user_mutedÇ   s
   €.þrQ   c              
   Ã   r4   )Nz(SELECT * FROM users WHERE is_blocked = 0c                 S   ó0   g | ]}|d  |d |d |d |d dœ‘qS )r   r5   rF   rG   rH   )rB   r?   r@   rC   rD   r   ©r6   Úrr   r   r   Ú
<listcomp>Ó   ó
    ÿ
ÿz(get_all_active_users.<locals>.<listcomp>r8   r:   r   r   r   Úget_all_active_usersÍ   s   €ÿÿüÿ.ÿrW   c              
   Ã   r4   )Nz&SELECT * FROM users WHERE is_muted = 1c                 S   ó$   g | ]}|d  |d |d dœ‘qS ©r   r5   rF   )rB   r?   r@   r   rS   r   r   r   rU   Û   ó   $ z#get_muted_users.<locals>.<listcomp>r8   r:   r   r   r   Úget_muted_users×   r=   r[   Úuser_message_idÚdev_message_idÚgroup_message_idÚgroup_chat_idc           	   
   Ã   s†   �t  ¡  ¡ }t t| ƒ¡4 I d H š$}| d||||||f¡I d H }| ¡ I d H  |jW  d   ƒI d H  S 1 I d H s<w   Y  d S )Nz¤INSERT INTO messages
               (user_id, user_message_id, dev_message_id, group_message_id, group_chat_id, created_at)
               VALUES (?, ?, ?, ?, ?, ?))	r   r#   r$   r    r!   r   r"   r%   Ú	lastrowid)	r   r>   r\   r]   r^   r_   rM   r'   r.   r   r   r   Úsave_messageÞ   s   €
ü0øra   c              	   Ã   sp   �t  t| ƒ¡4 I d H š}| d|||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s1w   Y  d S )Nz_UPDATE messages SET dev_message_id = ?
               WHERE user_id = ? AND user_message_id = ?r1   )r   r>   r\   r]   r'   r   r   r   Úupdate_dev_message_idí   s   €
ý.úrb   c              	   Ã   ór   �t  t| ƒ¡4 I d H š }| d||||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s2w   Y  d S )NztUPDATE messages SET group_message_id = ?, group_chat_id = ?
               WHERE user_id = ? AND user_message_id = ?r1   )r   r>   r\   r^   r_   r'   r   r   r   Úupdate_group_message_idø   s   €

ý.úrd   Úreply_message_idÚreply_dev_msg_idc              	   Ã   rc   )NzwUPDATE messages SET reply_message_id = ?, reply_dev_msg_id = ?
               WHERE user_id = ? AND user_message_id = ?r1   )r   r>   r\   re   rf   r'   r   r   r   Ú
save_reply  s   €

ý.úrg   c                 Ã   ó  �t  t| ƒ¡4 I d H šq}| d||f¡4 I d H šN}| ¡ I d H }|s8	 W d   ƒI d H  W d   ƒI d H  d S |d |d |d |d |d |d |d |d	 d
œW  d   ƒI d H  W  d   ƒI d H  S 1 I d H smw   Y  W d   ƒI d H  d S 1 I d H sƒw   Y  d S )Nz@SELECT * FROM messages WHERE user_id = ? AND user_message_id = ?r   r5   rF   rG   rH   rI   rJ   é   ©rB   r>   r\   r]   r^   r_   re   rf   r,   )r   r>   r\   r'   r.   r/   r   r   r   Úget_message_by_user_msg_id  ó*   €þúÿ	üùÿ.ÿrk   c                 Ã   ó  �t  t| ƒ¡4 I d H šp}| d|f¡4 I d H šN}| ¡ I d H }|s7	 W d   ƒI d H  W d   ƒI d H  d S |d |d |d |d |d |d |d |d	 d
œW  d   ƒI d H  W  d   ƒI d H  S 1 I d H slw   Y  W d   ƒI d H  d S 1 I d H s‚w   Y  d S )Nz/SELECT * FROM messages WHERE dev_message_id = ?r   r5   rF   rG   rH   rI   rJ   ri   rj   r,   )r   r]   r'   r.   r/   r   r   r   Úget_message_by_dev_msg_id!  s*   €þúÿ	üùÿ.ÿrn   c                 Ã   rh   )NzGSELECT * FROM messages WHERE group_message_id = ? AND group_chat_id = ?r   r5   rF   rG   rH   rI   rJ   ri   rj   r,   )r   r^   r_   r'   r.   r/   r   r   r   Úget_message_by_group_msg_id2  rl   ro   c                 Ã   rm   )Nz1SELECT * FROM messages WHERE reply_message_id = ?r   r5   rF   rG   rH   rI   rJ   ri   rj   r,   )r   re   r'   r.   r/   r   r   r   Úget_message_by_reply_message_idD  ó*   €þúÿ	üùÿ.ÿrp   c                 Ã   rm   )Nz1SELECT * FROM messages WHERE reply_dev_msg_id = ?r   r5   rF   rG   rH   rI   rJ   ri   rj   r,   )r   rf   r'   r.   r/   r   r   r   Úget_message_by_reply_dev_msg_idV  rq   rr   c              	   Ã   s~   �t  ¡  ¡ }t t| ƒ¡4 I d H š }| d||||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s8w   Y  d S )NzVINSERT OR REPLACE INTO admins (id, username, first_name, added_at) VALUES (?, ?, ?, ?)©r   r#   r$   r    r!   r   r"   r%   )r   r>   r?   r@   rM   r'   r   r   r   Ú	add_adminh  s   €

þ.ûrt   c              	   Ã   ól   �t  t| ƒ¡4 I d H š}| d|f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s/w   Y  d S )NzDELETE FROM admins WHERE id = ?r1   )r   r>   r'   r   r   r   Úremove_admins  ó
   €.þrv   c              
   Ã   r4   )NzSELECT * FROM adminsc                 S   rX   rY   r   rS   r   r   r   rU   }  rZ   zget_admins.<locals>.<listcomp>r8   r:   r   r   r   Ú
get_adminsy  r=   rx   c              
   Ã   s²   �t  t| ƒ¡4 I d H š@}| d|f¡4 I d H š}| ¡ I d H d uW  d   ƒI d H  W  d   ƒI d H  S 1 I d H s<w   Y  W d   ƒI d H  d S 1 I d H sRw   Y  d S )Nz"SELECT id FROM admins WHERE id = ?r,   )r   r>   r'   r.   r   r   r   Úis_admin€  s   €ÿÿ.ÿry   c              	   Ã   sh   �t  t| ƒ¡4 I d H š}| d¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s-w   Y  d S )NzDELETE FROM adminsr1   ©r   r'   r   r   r   Úclear_admins†  s
   €.þr{   ÚbuttonsÚ
channel_idÚchannel_titleÚchannel_usernameÚinvite_linkÚdisplay_typec              
   Ã   s‚   �t  ¡  ¡ }t t| ƒ¡4 I d H š"}| d||||||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s:w   Y  d S )NzÂINSERT OR REPLACE INTO mandatory_channels
               (channel_id, channel_username, channel_title, invite_link, display_type, is_active, added_at)
               VALUES (?, ?, ?, ?, ?, 1, ?)rs   )r   r}   r~   r   r€   r�   rM   r'   r   r   r   Úadd_mandatory_channelŒ  s   €
ü.ùr‚   c              
   Ã   r4   )Nz4SELECT * FROM mandatory_channels WHERE is_active = 1c              	   S   s6   g | ]}|d  |d |d |d |d |d dœ‘qS )r   r5   rF   rG   rH   rI   )rB   r}   r   r~   r€   r�   r   rS   r   r   r   rU      s    þ
þz*get_mandatory_channels.<locals>.<listcomp>r8   r:   r   r   r   Úget_mandatory_channelsš  s   €ÿþüÿ.ÿrƒ   Úchannel_db_idc              	   Ã   ru   )Nz8UPDATE mandatory_channels SET is_active = 0 WHERE id = ?r1   )r   r„   r'   r   r   r   Úremove_mandatory_channel¥  s   €
þ.ûr…   c              	   Ã   sn   �t  t| ƒ¡4 I d H š}| d||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s0w   Y  d S )Nz:UPDATE mandatory_channels SET invite_link = ? WHERE id = ?r1   )r   r„   r€   r'   r   r   r   Úupdate_mandatory_channel_link®  r3   r†   Úchat_idÚ
chat_titlec              	   Ã   s€   �t  ¡  ¡ }t t| ƒ¡4 I d H š!}| d|||||f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s9w   Y  d S )Nz—INSERT OR REPLACE INTO groups
               (chat_id, chat_title, username, invite_link, is_active, added_at)
               VALUES (?, ?, ?, ?, 1, ?)rs   )r   r‡   rˆ   r?   r€   rM   r'   r   r   r   Ú	add_group·  s   €
ü.ùr‰   c              
   Ã   r4   )Nz(SELECT * FROM groups WHERE is_active = 1c                 S   rR   )r   r5   rF   rG   rH   )rB   r‡   rˆ   r?   r€   r   rS   r   r   r   rU   È  rV   zget_groups.<locals>.<listcomp>r8   r:   r   r   r   Ú
get_groupsÄ  s   €ÿþÿ.ÿrŠ   Úgroup_db_idc              	   Ã   ru   )Nz,UPDATE groups SET is_active = 0 WHERE id = ?r1   )r   r‹   r'   r   r   r   Úremove_groupÌ  rw   rŒ   c              	   Ã   ót   �t  t| ƒ¡4 I d H š!}| dt ¡  ¡ f¡I d H  | ¡ I d H  W d   ƒI d H  d S 1 I d H s3w   Y  d S )NzEUPDATE message_stats SET sent = sent + 1, updated_at = ? WHERE id = 1©r    r!   r   r"   r   r#   r$   r%   rz   r   r   r   Úincrement_sentÒ  ó   €
þ.ûr�   c              	   Ã   r�   )NzMUPDATE message_stats SET received = received + 1, updated_at = ? WHERE id = 1rŽ   rz   r   r   r   Úincrement_receivedÛ  r�   r‘   c              
   Ã   sx  �t  ¡ }|tdd�  ¡ }t t| ƒ¡4 I d H �š}| d¡4 I d H š}| ¡ I d H d }W d   ƒI d H  n1 I d H s>w   Y  | d|f¡4 I d H š}| ¡ I d H d }W d   ƒI d H  n1 I d H shw   Y  | d¡4 I d H š}| ¡ I d H d }W d   ƒI d H  n1 I d H s�w   Y  | d¡4 I d H š}| ¡ I d H d }W d   ƒI d H  n1 I d H s¸w   Y  | d¡4 I d H š"}| ¡ I d H }	|	rÔ|	d nd}
|	rÜ|	d	 nd}W d   ƒI d H  n1 I d H sîw   Y  | d
¡4 I d H š}| ¡ I d H d }W d   ƒI d H  n1 I d H �sw   Y  W d   ƒI d H  n1 I d H �s-w   Y  |||||
||dœS )Né   )ÚhourszSELECT COUNT(*) FROM usersr   z1SELECT COUNT(*) FROM users WHERE last_active >= ?z-SELECT COUNT(*) FROM users WHERE is_muted = 1z/SELECT COUNT(*) FROM users WHERE is_blocked = 1z5SELECT sent, received FROM message_stats WHERE id = 1r5   z;SELECT COUNT(*) FROM mandatory_channels WHERE is_active = 1)Útotal_usersÚ
active_24hÚmuted_usersÚblocked_usersÚsentÚreceivedÚ
mand_count)	r   r#   r   r$   r    r!   r   r"   r-   )r   rM   Úlast_24hr'   r.   r”   r•   r–   r—   r/   r˜   Úrecvrš   r   r   r   Úget_statisticsä  sT   €(ÿÿ(ý(ÿ(ÿÿ(ûÿ,ý*êùr�   c              	   Ã   s:   �dD ]\}}z
|   |¡I d H  W q ty   Y qw d S )N))Úemojiz0ALTER TABLE custom_buttons ADD COLUMN emoji TEXT)Úcustom_emoji_idz:ALTER TABLE custom_buttons ADD COLUMN custom_emoji_id TEXT)Úcolorz0ALTER TABLE custom_buttons ADD COLUMN color TEXT)Ú
is_visiblezBALTER TABLE custom_buttons ADD COLUMN is_visible INTEGER DEFAULT 1)r"   Ú	Exception)r'   ÚcolÚddlr   r   r   Ú_ensure_cbtn_columns  s   €ÿør¥   Úbtn_typeÚlabelÚcontentc              	   Ã   s˜   �ddl m } t t| ƒ¡4 I d H š-}t|ƒI d H  | d|||| ¡  ¡ f¡I d H }| ¡ I d H  |j	W  d   ƒI d H  S 1 I d H sEw   Y  d S )Nr   )r   z¨INSERT INTO custom_buttons (btn_type, label, content, position, created_at, is_visible) VALUES (?, ?, ?, (SELECT COALESCE(MAX(position),0)+1 FROM custom_buttons), ?, 1))
r   r    r!   r   r¥   r"   r#   r$   r%   r`   )r   r¦   r§   r¨   Ú_dtr'   r.   r   r   r   Úadd_custom_button  s   €
ý0ørª   c              
   Ã   sÆ   �t  t| ƒ¡4 I d H šJ}t|ƒI d H  | d¡4 I d H š#}| ¡ I d H }dd„ |D ƒW  d   ƒI d H  W  d   ƒI d H  S 1 I d H sFw   Y  W d   ƒI d H  d S 1 I d H s\w   Y  d S )NzŠSELECT id, btn_type, label, content, position, emoji, custom_emoji_id, color, COALESCE(is_visible,1) FROM custom_buttons ORDER BY positionc                 S   sH   g | ] }|d  |d |d |d |d |d |d |d |d d	œ	‘qS )
r   r5   rF   rG   rH   rI   rJ   ri   é   ©	rB   r¦   r§   r¨   Úpositionrž   rŸ   r    r¡   r   rS   r   r   r   rU   /  s    þÿÿz&get_custom_buttons.<locals>.<listcomp>)r    r!   r   r¥   r"   r9   r:   r   r   r   Úget_custom_buttons'  s   €ÿýûþ.þr®   Úbtn_idc                 Ã   s&  �t  t| ƒ¡4 I d H šz}t|ƒI d H  | d|f¡4 I d H šQ}| ¡ I d H }|s>	 W d   ƒI d H  W d   ƒI d H  d S |d |d |d |d |d |d |d |d	 |d
 dœ	W  d   ƒI d H  W  d   ƒI d H  S 1 I d H svw   Y  W d   ƒI d H  d S 1 I d H sŒw   Y  d S )Nz…SELECT id, btn_type, label, content, position, emoji, custom_emoji_id, color, COALESCE(is_visible,1) FROM custom_buttons WHERE id = ?r   r5   rF   rG   rH   rI   rJ   ri   r«   r¬   )r    r!   r   r¥   r"   r-   )r   r¯   r'   r.   rT   r   r   r   Úget_custom_button6  s(   €ýùþ
ÿøþ.þr°   Ú__keep__rž   rŸ   r    r¡   c	              	   Ã   sz  �t  t| ƒ¡4 I d H š¤}	t|	ƒI d H  g g }
}|d ur'|
 d¡ | |¡ |d ur5|
 d¡ | |¡ |d urC|
 d¡ | |¡ |dkrQ|
 d¡ | |¡ |dkr_|
 d¡ | |¡ |dkrm|
 d¡ | |¡ |d ur{|
 d¡ | |¡ |
s‰	 W d   ƒI d H  d S | |¡ |	 d	d
 |
¡› d�|¡I d H  |	 ¡ I d H  W d   ƒI d H  d S 1 I d H s¶w   Y  d S )Nzbtn_type = ?z	label = ?zcontent = ?r±   z	emoji = ?zcustom_emoji_id = ?z	color = ?zis_visible = ?zUPDATE custom_buttons SET z, z WHERE id = ?)r    r!   r   r¥   Úappendr"   r   r%   )r   r¯   r¦   r§   r¨   rž   rŸ   r    r¡   r'   ÚsetsÚvalsr   r   r   Úupdate_custom_buttonE  s2   €
î
 .ërµ   c              	   Ã   ru   )Nz'DELETE FROM custom_buttons WHERE id = ?r1   )r   r¯   r'   r   r   r   Údelete_custom_buttona  rw   r¶   )NNN)r|   )NNNr±   r±   r±   N)7r   r    r   r   r   r   ÚdirnameÚabspathÚ__file__r
   Ústrr   r+   r0   r2   Údictr<   ÚintrN   rO   ÚboolrQ   ÚlistrW   r[   ra   rb   rd   rg   rk   rn   ro   rp   rr   rt   rv   rx   ry   r{   r‚   rƒ   r…   r†   r‰   rŠ   rŒ   r�   r‘   r�   r¥   rª   r®   r°   rµ   r¶   r   r   r   r   Ú<module>   sö   z	
ÿÿ
ÿ
þÿÿþ
þ
ÿ
ÿ
ÿÿ
þÿ
ÿ
ÿ
ÿ
ÿ
ÿÿ
ÿÿ
ÿ
ÿ
ÿþÿÿþ
þ		ÿ
ÿ		)ýÿÿþþý
ý