add opay background check

This commit is contained in:
Jay
2018-09-17 21:46:59 +08:00
parent cfc1e43192
commit 67eeab4ba1
3 changed files with 154 additions and 4 deletions
+24 -2
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"time"
"git.trj.tw/golang/mtfosbot/model"
"gopkg.in/irc.v2"
"git.trj.tw/golang/mtfosbot/module/config"
@@ -28,6 +30,7 @@ func InitIRC() {
channels = make([]string, 0)
queue = NewQueue()
runQueue()
ReJoin()
config := irc.ClientConfig{
Nick: "mtfos",
@@ -57,12 +60,26 @@ func SendMessage(ch, msg string) {
Command: "PRIVMSG",
Params: []string{
fmt.Sprintf("#%s", ch),
fmt.Sprintf(":%s", msg),
fmt.Sprintf("%s", msg),
},
}
queue.Add(m)
}
// ReJoin -
func ReJoin() {
ch, err := model.GetAllTwitchChannel()
if err != nil {
return
}
LeaveAllChannel()
for _, v := range ch {
if v.Join {
JoinChannel(v.Name)
}
}
}
// JoinChannel -
func JoinChannel(ch string) {
if len(ch) == 0 {
@@ -103,6 +120,9 @@ func LeaveChannel(ch string) {
// LeaveAllChannel -
func LeaveAllChannel() {
if len(channels) == 0 {
return
}
for _, v := range channels {
m := &MsgObj{
Command: "PART",
@@ -118,7 +138,7 @@ func runQueue() {
go func() {
cnt := 0
for {
if !queue.IsEmpty() {
if !queue.IsEmpty() && client != nil {
m := queue.Get()
msg := &irc.Message{}
msg.Command = m.Command
@@ -142,6 +162,8 @@ func runQueue() {
cnt++
if cnt > 1800 {
// call rejoin
ReJoin()
cnt = 0
}
time.Sleep(time.Second * 1)
}