-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
767 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package hkbot | ||
|
||
import ( | ||
. "github.com/CuteReimu/onebot" | ||
"log/slog" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func init() { | ||
addCmdListener(&delAdmin{}) | ||
addCmdListener(&addAdmin{}) | ||
addCmdListener(&listAllAdmin{}) | ||
} | ||
|
||
type delAdmin struct{} | ||
|
||
func (d *delAdmin) Name() string { | ||
return "删除管理员" | ||
} | ||
|
||
func (d *delAdmin) ShowTips(int64, int64) string { | ||
return "删除管理员 对方QQ号" | ||
} | ||
|
||
func (d *delAdmin) CheckAuth(_ int64, senderId int64) bool { | ||
return IsSuperAdmin(senderId) | ||
} | ||
|
||
func (d *delAdmin) Execute(_ *GroupMessage, content string) MessageChain { | ||
ss := strings.Split(content, " ") | ||
qqNumbers := make([]int64, 0, len(ss)) | ||
for _, s := range ss { | ||
s = strings.TrimSpace(s) | ||
if len(s) == 0 { | ||
continue | ||
} | ||
qq, err := strconv.ParseInt(s, 10, 64) | ||
if err != nil { | ||
slog.Error("parse failed: "+s, "error", err) | ||
return nil | ||
} | ||
if IsSuperAdmin(qq) { | ||
return MessageChain{&Text{Text: "你不能删除自己"}} | ||
} | ||
if !IsAdmin(qq) { | ||
return MessageChain{&Text{Text: s + "并不是管理员"}} | ||
} | ||
qqNumbers = append(qqNumbers, qq) | ||
} | ||
if len(qqNumbers) == 0 { | ||
return nil | ||
} | ||
for _, qq := range qqNumbers { | ||
RemoveAdmin(qq) | ||
} | ||
ret := "已删除管理员" | ||
if len(qqNumbers) == 1 { | ||
ret += ":" + strconv.FormatInt(qqNumbers[0], 10) | ||
} | ||
return MessageChain{&Text{Text: ret}} | ||
} | ||
|
||
type addAdmin struct{} | ||
|
||
func (a *addAdmin) Name() string { | ||
return "增加管理员" | ||
} | ||
|
||
func (a *addAdmin) ShowTips(int64, int64) string { | ||
return "增加管理员 对方QQ号" | ||
} | ||
|
||
func (a *addAdmin) CheckAuth(_ int64, senderId int64) bool { | ||
return IsSuperAdmin(senderId) | ||
} | ||
|
||
func (a *addAdmin) Execute(_ *GroupMessage, content string) MessageChain { | ||
ss := strings.Split(content, " ") | ||
qqNumbers := make([]int64, 0, len(ss)) | ||
for _, s := range ss { | ||
s = strings.TrimSpace(s) | ||
if len(s) == 0 { | ||
continue | ||
} | ||
qq, err := strconv.ParseInt(s, 10, 64) | ||
if err != nil { | ||
slog.Error("parse failed: "+s, "error", err) | ||
return nil | ||
} | ||
if IsSuperAdmin(qq) || IsAdmin(qq) { | ||
return MessageChain{&Text{Text: s + "已经是管理员了"}} | ||
} | ||
qqNumbers = append(qqNumbers, qq) | ||
} | ||
if len(qqNumbers) == 0 { | ||
return nil | ||
} | ||
for _, qq := range qqNumbers { | ||
AddAdmin(qq) | ||
} | ||
ret := "已增加管理员" | ||
if len(qqNumbers) == 1 { | ||
ret += ":" + strconv.FormatInt(qqNumbers[0], 10) | ||
} | ||
return MessageChain{&Text{Text: ret}} | ||
} | ||
|
||
type listAllAdmin struct{} | ||
|
||
func (l *listAllAdmin) Name() string { | ||
return "查看管理员" | ||
} | ||
|
||
func (l *listAllAdmin) ShowTips(int64, int64) string { | ||
return "" | ||
} | ||
|
||
func (l *listAllAdmin) CheckAuth(int64, int64) bool { | ||
return true | ||
} | ||
|
||
func (l *listAllAdmin) Execute(*GroupMessage, string) MessageChain { | ||
superAdmin := hkConfig.GetInt64("qq.super_admin_qq") | ||
admin := permData.GetIntSlice("admin") | ||
s := make([]string, 0, len(admin)+2) | ||
s = append(s, "管理员列表:") | ||
s = append(s, strconv.FormatInt(superAdmin, 10)) | ||
for _, qq := range admin { | ||
s = append(s, strconv.Itoa(qq)) | ||
} | ||
return MessageChain{&Text{Text: strings.Join(s, "\n")}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package hkbot | ||
|
||
import ( | ||
. "github.com/CuteReimu/onebot" | ||
"math/rand/v2" | ||
"slices" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func init() { | ||
addCmdListener(&showTips{}) | ||
addCmdListener(&ping{}) | ||
addCmdListener(&roll{}) | ||
} | ||
|
||
type showTips struct{} | ||
|
||
func (t *showTips) Name() string { | ||
return "查看帮助" | ||
} | ||
|
||
func (t *showTips) ShowTips(int64, int64) string { | ||
return "" | ||
} | ||
|
||
func (t *showTips) CheckAuth(int64, int64) bool { | ||
return true | ||
} | ||
|
||
func (t *showTips) Execute(msg *GroupMessage, _ string) MessageChain { | ||
var ret []string | ||
for _, h := range cmdMap { | ||
if h.CheckAuth(msg.GroupId, msg.Sender.UserId) { | ||
if tip := h.ShowTips(msg.GroupId, msg.Sender.UserId); len(tip) > 0 { | ||
ret = append(ret, tip) | ||
} | ||
} | ||
} | ||
slices.Sort(ret) | ||
return MessageChain{&Text{Text: "你可以使用以下功能:\n" + strings.Join(ret, "\n")}} | ||
} | ||
|
||
type ping struct{} | ||
|
||
func (p *ping) Name() string { | ||
return "ping" | ||
} | ||
|
||
func (p *ping) ShowTips(int64, int64) string { | ||
return "" | ||
} | ||
|
||
func (p *ping) CheckAuth(int64, int64) bool { | ||
return true | ||
} | ||
|
||
func (p *ping) Execute(_ *GroupMessage, content string) MessageChain { | ||
if len(content) == 0 { | ||
return MessageChain{&Text{Text: "pong"}} | ||
} | ||
return nil | ||
} | ||
|
||
type roll struct{} | ||
|
||
func (r *roll) Name() string { | ||
return "roll" | ||
} | ||
|
||
func (r *roll) ShowTips(int64, int64) string { | ||
return "" | ||
} | ||
|
||
func (r *roll) CheckAuth(int64, int64) bool { | ||
return true | ||
} | ||
|
||
func (r *roll) Execute(message *GroupMessage, content string) MessageChain { | ||
if len(content) == 0 { | ||
replyGroupMessage(true, message, &Text{Text: "roll: " + strconv.Itoa(rand.IntN(100))}) //nolint:gosec | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.