/
plugin_channel_scramble.go
66 lines (59 loc) · 1.71 KB
/
plugin_channel_scramble.go
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
55
56
57
58
59
60
61
62
63
64
65
66
package plugins
import (
"context"
"log"
"net/url"
"strings"
. "github.com/2mf8/GoTBot/data"
. "github.com/2mf8/GoTBot/public"
. "github.com/2mf8/GoTBot/utils"
)
type CScramblePlugin struct {
}
func (scramble *CScramblePlugin) ChannelDo(ctx *context.Context, botId, botChannelId int64, guildId, channelId, userId uint64, rawMsg, card string, super, userRole bool, rs, rd, rf int) (retStuct RetChannelStuct) {
s, b := Prefix(rawMsg, ".")
if !b {
return RetChannelStuct{
RetVal: MESSAGE_IGNORE,
}
}
ins := Tnoodle(s).Instruction
shor := Tnoodle(s).ShortName
show := Tnoodle(s).ShowName
if ins == s && ins != "instruction" {
gs := GetScramble(shor)
if StartsWith(gs, "net") || gs == "获取失败" {
log.Printf("[INFO] Bot(%v) GuildId(%v) ChannelId(%v) -> 获取打乱失败", botId, guildId, channelId)
return RetChannelStuct{
RetVal: MESSAGE_BLOCK,
ReplyMsg: &ChannelMsg{
Text: "获取打乱失败",
},
ReqType: GroupMsg,
}
}
if shor == "minx" {
gs = strings.Replace(gs, "U' ", "#\n", -1)
gs = strings.Replace(gs, "U ", "U\n", -1)
gs = strings.Replace(gs, "#", "U'", -1)
}
imgUrl := "http://localhost:2014/view/" + shor + ".png?scramble=" + url.QueryEscape(strings.Replace(gs, "\n", " ", -1))
sc := show + "\n" + gs
log.Printf("[INFO] Bot(%v) GuildId(%v) ChannelId(%v) -> %v\n%v\n<guild_image file=\"%v\" url=\"%v\" />", botId, guildId, channelId, show, gs, shor+".png", imgUrl)
return RetChannelStuct{
RetVal: MESSAGE_BLOCK,
ReplyMsg: &ChannelMsg{
Text: sc,
Image: imgUrl,
File: shor + ".png",
},
ReqType: GroupMsg,
}
}
return RetChannelStuct{
RetVal: MESSAGE_IGNORE,
}
}
func init() {
ChannelRegister("打乱", &CScramblePlugin{})
}