update
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package lineobj
|
||||
|
||||
// EventObject -
|
||||
type EventObject struct {
|
||||
Source *SourceObject `json:"source" cc:"source"`
|
||||
Type string `json:"type" cc:"type"`
|
||||
Timestamp int32 `json:"timestamp" cc:"timestamp"`
|
||||
ReplyToken string `json:"replyToken" cc:"replyToken"`
|
||||
Message map[string]interface{} `json:"message" cc:"message"`
|
||||
}
|
||||
|
||||
// SourceObject -
|
||||
type SourceObject struct {
|
||||
Type string `json:"type" cc:"type"`
|
||||
UserID string `json:"userId" cc:"userId"`
|
||||
GroupID string `json:"groupId" cc:"groupId"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package linemsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
|
||||
"git.trj.tw/golang/mtfosbot/module/utils"
|
||||
)
|
||||
|
||||
// MessageEvent -
|
||||
func MessageEvent(e *lineobj.EventObject) {
|
||||
fmt.Println(utils.ToMap(e))
|
||||
|
||||
switch e.Type {
|
||||
case "message":
|
||||
messageType(e)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package linemsg
|
||||
|
||||
import (
|
||||
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
|
||||
)
|
||||
|
||||
func messageType(e *lineobj.EventObject) {
|
||||
msg := e.Message
|
||||
mtype, ok := msg["type"]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if t, ok := mtype.(string); ok {
|
||||
switch t {
|
||||
case "text":
|
||||
break
|
||||
case "image":
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func textMsg(e *lineobj.EventObject) {
|
||||
msg := e.Message
|
||||
mtxt, ok := msg["text"]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// group action
|
||||
if e.Source.Type == "group" {
|
||||
if _, ok := mtxt.(string); ok {
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -36,6 +36,26 @@ func InitIRC() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SendMessage -
|
||||
func SendMessage(ch, msg string) {
|
||||
if len(ch) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if indexOf(channels, ch) == -1 {
|
||||
return
|
||||
}
|
||||
|
||||
m := &MsgObj{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{
|
||||
fmt.Sprintf("#%s", ch),
|
||||
fmt.Sprintf(":%s", msg),
|
||||
},
|
||||
}
|
||||
queue.Add(m)
|
||||
}
|
||||
|
||||
// JoinChannel -
|
||||
func JoinChannel(ch string) {
|
||||
if len(ch) == 0 {
|
||||
@@ -88,21 +108,29 @@ func runQueue() {
|
||||
msg := &irc.Message{}
|
||||
msg.Command = m.Command
|
||||
msg.Params = m.Params
|
||||
err := client.WriteMessage(msg)
|
||||
if err == nil {
|
||||
if m.Command == "JOIN" {
|
||||
|
||||
} else if m.Command == "PART" {
|
||||
|
||||
if m.Command == "JOIN" {
|
||||
if indexOf(channels, m.Params[0][1:]) != -1 {
|
||||
continue
|
||||
}
|
||||
channels = append(channels, m.Params[0][1:])
|
||||
} else if m.Command == "PART" {
|
||||
if indexOf(channels, m.Params[0][1:]) == -1 {
|
||||
continue
|
||||
}
|
||||
idx := indexOf(channels, m.Params[0][1:])
|
||||
channels = append(channels[:idx], channels[idx+1:]...)
|
||||
}
|
||||
fmt.Println("< ", msg.String())
|
||||
client.WriteMessage(msg)
|
||||
}
|
||||
|
||||
time.Sleep(time.Microsecond * 1500)
|
||||
}
|
||||
}
|
||||
|
||||
func ircHandle(c *irc.Client, m *irc.Message) {
|
||||
|
||||
fmt.Println("> ", m.String())
|
||||
}
|
||||
|
||||
func indexOf(c []string, data string) int {
|
||||
|
||||
Reference in New Issue
Block a user