From cd697545e06431e92a512339fbb9952f8b987563 Mon Sep 17 00:00:00 2001 From: ZJY <764763903@qq.com> Date: Thu, 9 Sep 2021 11:22:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=8A=9F=E8=83=BD=20=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/demo_reply.php | 1 + models/bot.go | 5 +++++ models/command.go | 9 +++++++++ models/db.go | 1 + models/useradmin.go | 15 +++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 models/useradmin.go diff --git a/conf/demo_reply.php b/conf/demo_reply.php index bce055f..cee2b3e 100644 --- a/conf/demo_reply.php +++ b/conf/demo_reply.php @@ -61,6 +61,7 @@ return reply( 回复 丨 屏蔽 更新账号 | 清理过期账号 取消屏蔽 | 任务列表 + 设置管理员 ——————————— 京东机器人 ] diff --git a/models/bot.go b/models/bot.go index fe8ec3b..35fb239 100644 --- a/models/bot.go +++ b/models/bot.go @@ -70,6 +70,11 @@ var handleMessage = func(msgs ...interface{}) interface{} { if sender.UserID == Config.TelegramUserID || sender.UserID == int(Config.QQID) { sender.IsAdmin = true } + + if IsUserAdmin(string(sender.UserID)) { + sender.IsAdmin = true + } + for i := range codeSignals { for j := range codeSignals[i].Command { if codeSignals[i].Command[j] == head { diff --git a/models/command.go b/models/command.go index 5caae23..101dbfb 100644 --- a/models/command.go +++ b/models/command.go @@ -302,6 +302,15 @@ var codeSignals = []CodeSignal{ return nil }, }, + { + Command: []string{"设置管理员"}, + Admin: true, + Handle: func(sender *Sender) interface{} { + ctt := sender.JoinContens() + db.Create(&UserAdmin{Content: ctt}) + return "已设置管理员" + }, + }, { Command: []string{"赌一把"}, Handle: func(sender *Sender) interface{} { diff --git a/models/db.go b/models/db.go index 69bb6e9..49ea371 100644 --- a/models/db.go +++ b/models/db.go @@ -129,6 +129,7 @@ var Available = "Available" var UnAvailable = "UnAvailable" var PtKey = "PtKey" var PtPin = "PtPin" +var Content = "Content" var WsKey = "WsKey" var Address = "Address" var Priority = "Priority" diff --git a/models/useradmin.go b/models/useradmin.go new file mode 100644 index 0000000..dc1749d --- /dev/null +++ b/models/useradmin.go @@ -0,0 +1,15 @@ +package models + +type UserAdmin struct { + ID int + Content string +} + +func IsUserAdmin(id string) bool { + user := UserAdmin{} + db.Model(UserAdmin{}).Where(Content+" = ?", id).First(user) + if len(user.Content) > 0 { + return true + } + return false +}