;; SPDX-License-Identifier: EUPL-1.2 ;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs (defpackage :ukkoclot/src/inline-bots (:documentation "This package deals with removing unwanted inline bot usage") (:use :c2cl :ukkoclot/src/tg) (:import-from :conf) (:import-from :log) (:import-from :named-readtables :in-readtable) (:import-from :serapeum :->) (:import-from :state) (:import-from :ukkoclot/src/readtable :readtable) (:local-nicknames (:db :ukkoclot/src/db)) (:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot)) (in-package :ukkoclot/src/inline-bots) (in-readtable readtable) (-> blacklist-inline-bot (integer) (values &optional)) (defun blacklist-inline-bot (inline-bot-id) "Blacklist the given bot. No more messages about deleting its messages will be sent." (db:set-inline-bot-type (state:db) inline-bot-id db:blacklisted)) (-> whitelist-inline-bot (integer) (values &optional)) (defun whitelist-inline-bot (inline-bot-id) "Whitelist the given bot. Its messages will no longer be deleted." (db:set-inline-bot-type (state:db) inline-bot-id db:whitelisted)) (-> on-inline-bot (message user) boolean) (defun on-inline-bot (msg via) (let ((ty (db:get-inline-bot-type (state:db) (user-id via)))) (or (eql ty db:whitelisted) (prog1 nil (log:info "Deleting an unallowed inline bot message from ~A ~A" (user-username via) (user-id via)) (try-delete-message msg) (unless (eql ty db:blacklisted) ;; Not explicitly blacklisted, notify dev group (let ((whitelist (make-inline-keyboard-button :text "Whitelist" :callback-data #f"bwl:{(user-id via)}")) (blacklist (make-inline-keyboard-button :text "Blacklist" :callback-data #f"bbl:{(user-id via)}"))) (send-message :chat-id (conf:dev-group) :text #f"Deleted a message sent via inline bot @{(user-username via)} {(user-id via)}" :parse-mode html :reply-markup (make-inline-keyboard-markup :inline-keyboard (make-array '(1 2) :initial-contents (list (list whitelist blacklist)))))))))))