-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.go
More file actions
52 lines (43 loc) · 1.13 KB
/
echo.go
File metadata and controls
52 lines (43 loc) · 1.13 KB
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
package echo
import (
"strings"
"github.com/gonebot-dev/gonebot/message"
"github.com/gonebot-dev/gonebot/plugin"
"github.com/gonebot-dev/gonebot/plugin/handler"
)
var EchoPlugin plugin.GonePlugin
var echo_prefix string = "echo"
func echoMatcher(msg message.Message) bool {
for _, seg := range msg.Segments {
if seg.Type == "text" {
if strings.HasPrefix(seg.Content, echo_prefix) {
return true
}
}
}
return false
}
func echoHandler(incomingMsg message.Message, resultMsg *message.Message) (block bool) {
for i, seg := range incomingMsg.Segments {
if seg.Type == "text" {
if strings.HasPrefix(seg.Content, echo_prefix) {
incomingMsg.Segments[i].Content = seg.Content[4:]
break
}
}
}
resultMsg.Segments = append(resultMsg.Segments, incomingMsg.Segments...)
return true
}
func init() {
EchoPlugin.Name = "Echo"
EchoPlugin.Version = "v2.0.alpha"
EchoPlugin.Description = "Reply the same message of what you have sent"
EchoPlugin.Handlers = append(EchoPlugin.Handlers, handler.GoneHandler{
Matcher: echoMatcher,
Handler: echoHandler,
})
}
func GetPlugin() plugin.GonePlugin {
return EchoPlugin
}