summaryrefslogtreecommitdiff
path: root/src/inline-bots.lisp
blob: db9d8ff6e35f6a0fc41fe565f907a3b995209027 (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
53
54
;; SPDX-License-Identifier: EUPL-1.2
;; SPDX-FileCopyrightText: 2025 Uko Kokņevičs <perkontevs@gmail.com>
(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)} <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)))))))))))