blob: 47dd81baedba22e8e57262b04486dcab36c549ef (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
;; SPDX-License-Identifier: EUPL-1.2
;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
(defpackage :ukkoclot/inline-bots
(:documentation "This package deals with removing unwanted inline bot usage")
(:use :c2cl :ukkoclot/tg)
(:import-from :com.dieggsy.f-string :enable-f-strings)
(:import-from :conf)
(:import-from :log)
(:import-from :ukkoclot/tg :send-message :try-delete-message)
(:import-from :ukkoclot/state :bot-db)
(:local-nicknames (:db :ukkoclot/db))
(:export :blacklist-inline-bot :on-inline-bot :whitelist-inline-bot))
(in-package :ukkoclot/inline-bots)
(enable-f-strings)
(defun blacklist-inline-bot (bot inline-bot-id)
"Blacklist the given bot.
No more messages about deleting its messages will be sent."
(db:set-inline-bot-type (bot-db bot) inline-bot-id :blacklisted))
(defun whitelist-inline-bot (bot inline-bot-id)
"Whitelist the given bot.
Its messages will no longer be deleted."
(db:set-inline-bot-type (bot-db bot) inline-bot-id :whitelisted))
(defun on-inline-bot (bot msg via)
(let ((ty (db:get-inline-bot-type (bot-db bot) (user-id via))))
(or (eql ty :whitelisted)
(prog1 nil
(log:info "Deleting an unallowed inline bot message from ~A ~A"
(user-username via)
(user-id via))
(try-delete-message bot msg)
(unless (eql ty :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
bot
:chat-id (conf:dev-group)
:text #f"Deleted a message sent via inline bot @{(user-username via)} <code>{(user-id via)}</code>"
:parse-mode html
:reply-markup (make-inline-keyboard-markup
:inline-keyboard
(make-array '(1 2)
:initial-contents
(list (list whitelist blacklist)))))))))))
|