|
@@ -0,0 +1,44 @@
|
|
|
|
|
+(in-package :cl-user)
|
|
|
|
|
+(defpackage chatikbot.plugins.massmention
|
|
|
|
|
+ (:use :cl :chatikbot.common))
|
|
|
|
|
+(in-package :chatikbot.plugins.massmention)
|
|
|
|
|
+
|
|
|
|
|
+(defparameter +default-group+ "all")
|
|
|
|
|
+
|
|
|
|
|
+(defun format-mention-group (group)
|
|
|
|
|
+ (format nil "Але!~{ ~a~^~}" (loop for (user-name) in (db-select "select user_tag from mention_groups where mention_group = ?" group)
|
|
|
|
|
+ collect (format nil "@~a" user-name))))
|
|
|
|
|
+(defun handle-mass-mention (group)
|
|
|
|
|
+ (bot-send-message (format-mention-group group) :reply-to *message-id*))
|
|
|
|
|
+
|
|
|
|
|
+(defun add-user-to-group (group mentions)
|
|
|
|
|
+ (apply-to-mentions group mentions #'db/add-user-to-group "Добавил ~{~a~^,~} в группу ~a."))
|
|
|
|
|
+
|
|
|
|
|
+(defun remove-user-from-group (group mentions)
|
|
|
|
|
+ (apply-to-mentions group mentions #'db/remove-user-from-group "Удалил ~{~a~^,~} из группы ~a."))
|
|
|
|
|
+
|
|
|
|
|
+(defun apply-to-mentions (group mentions func message)
|
|
|
|
|
+ (handler-case (progn
|
|
|
|
|
+ (loop for name in mentions
|
|
|
|
|
+ do (funcall func group (subseq name 1)))
|
|
|
|
|
+ (bot-send-message (format nil message mentions group)))
|
|
|
|
|
+ (error (e) (progn
|
|
|
|
|
+ (bot-send-message "Не получилось, попробуй еще раз.")
|
|
|
|
|
+ (log:error "~A" e)))))
|
|
|
|
|
+
|
|
|
|
|
+(defun db/add-user-to-group (group user-tag)
|
|
|
|
|
+ (db-execute "insert or ignore into mention_groups (mention_group, user_tag) VALUES (?, ?)" group user-tag))
|
|
|
|
|
+
|
|
|
|
|
+(defun db/remove-user-from-group (group user-tag)
|
|
|
|
|
+ (db-execute "delete from mention_groups where mention_group = ? and user_tag = ?" group user-tag))
|
|
|
|
|
+
|
|
|
|
|
+(def-db-init
|
|
|
|
|
+ (db-execute "create table if not exists mention_groups (mention_group TEXT, user_tag TEXT, primary key (mention_group, user_tag)) without rowid"))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+(def-message-cmd-handler handle-cmd-all (:all)
|
|
|
|
|
+ (cond
|
|
|
|
|
+ ((= 1 (length *args*)) (handle-mass-mention (car *args*)))
|
|
|
|
|
+ ((equalp "add" (car *args*)) (add-user-to-group (second *args*) (subseq *args* 2)))
|
|
|
|
|
+ ((equalp "remove" (car *args*)) (remove-user-from-group (second *args*) (subseq *args* 2)))
|
|
|
|
|
+ (:otherwise (handle-mass-mention +default-group+))))
|