compilation fix for client revamping
This commit is contained in:
parent
f66f8af0cd
commit
ad026c4b68
161
bot.go
161
bot.go
@ -165,18 +165,19 @@ func botGetClients(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := clientsKeepAlive.Load(m.Chat.ID); ok {
|
if clt, ok := getLockedClient(m.Chat.ID, false); ok {
|
||||||
|
clt.Unlock()
|
||||||
|
muxClients.RLock()
|
||||||
var ret string
|
var ret string
|
||||||
clientsKeepAlive.Range(func(k, v interface{}) bool {
|
for id, c := range clients {
|
||||||
ka := v.(*MQKeepAlive)
|
if c.Active {
|
||||||
if v2, ok2 := clientsCW.Load(ka.UserID64); ok2 {
|
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d (online)\n", ret, c.MQ.User, c.CWUserID64, c.TGUserID64)
|
||||||
clt := v2.(*ChatWarsClient)
|
|
||||||
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d\n", ret, ka.Nickname, clt.UserID64, ka.UserID64)
|
|
||||||
} else {
|
} else {
|
||||||
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d\n", ret, ka.Nickname, 0, ka.UserID64)
|
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d (offline)\n", ret, c.MQ.User, c.CWUserID64, c.TGUserID64)
|
||||||
}
|
}
|
||||||
return true
|
}
|
||||||
})
|
muxClients.RUnlock()
|
||||||
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: ret,
|
Text: ret,
|
||||||
@ -201,7 +202,8 @@ func botMsgRescan(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := clientsKeepAlive.Load(m.Chat.ID); !ok && m.Chat.ID != cfg.Bot.Admin {
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Client not registered",
|
Text: "Client not registered",
|
||||||
@ -211,6 +213,17 @@ func botMsgRescan(m *tb.Message) {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
r := regexp.MustCompile("^[0-9]+$")
|
r := regexp.MustCompile("^[0-9]+$")
|
||||||
if r.MatchString(m.Payload) {
|
if r.MatchString(m.Payload) {
|
||||||
p := JobPayloadRescanMsg{
|
p := JobPayloadRescanMsg{
|
||||||
@ -251,7 +264,8 @@ func botMsgRescanAll(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := clientsKeepAlive.Load(m.Chat.ID); !ok && m.Chat.ID != cfg.Bot.Admin {
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Client not registered",
|
Text: "Client not registered",
|
||||||
@ -261,6 +275,17 @@ func botMsgRescanAll(m *tb.Message) {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
p := JobPayloadRescanMsg{
|
p := JobPayloadRescanMsg{
|
||||||
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;", objTypeMessage, objSubTypeMessageUnknown),
|
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;", objTypeMessage, objSubTypeMessageUnknown),
|
||||||
MsgID64: int64(m.ID),
|
MsgID64: int64(m.ID),
|
||||||
@ -294,7 +319,8 @@ func botBackupExport(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := clientsKeepAlive.Load(m.Chat.ID); !ok && m.Chat.ID != cfg.Bot.Admin {
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Client not registered",
|
Text: "Client not registered",
|
||||||
@ -304,6 +330,17 @@ func botBackupExport(m *tb.Message) {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
p := JobPayloadBackupExport{
|
p := JobPayloadBackupExport{
|
||||||
MsgID64: int64(m.ID),
|
MsgID64: int64(m.ID),
|
||||||
@ -320,7 +357,8 @@ func botBackupImport(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := clientsKeepAlive.Load(m.Chat.ID); !ok && m.Chat.ID != cfg.Bot.Admin {
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Client not registered",
|
Text: "Client not registered",
|
||||||
@ -330,6 +368,17 @@ func botBackupImport(m *tb.Message) {
|
|||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
r := regexp.MustCompile(`^((http[s]?\:)\/\/)?([^\?\:\/#]+)(\:([0-9]+))?(\/[^\?\#]*)?(\?([^#]*))?(#.*)?.zip$`)
|
r := regexp.MustCompile(`^((http[s]?\:)\/\/)?([^\?\:\/#]+)(\:([0-9]+))?(\/[^\?\#]*)?(\?([^#]*))?(#.*)?.zip$`)
|
||||||
if !r.MatchString(m.Payload) {
|
if !r.MatchString(m.Payload) {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
@ -356,6 +405,32 @@ func botBackupImport(m *tb.Message) {
|
|||||||
|
|
||||||
func botMsgDump(m *tb.Message) {
|
func botMsgDump(m *tb.Message) {
|
||||||
var res string
|
var res string
|
||||||
|
if !m.Private() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
r := regexp.MustCompile("^[0-9]+$")
|
r := regexp.MustCompile("^[0-9]+$")
|
||||||
if r.MatchString(m.Payload) {
|
if r.MatchString(m.Payload) {
|
||||||
objId, _ := strconv.ParseInt(m.Payload, 10, 64)
|
objId, _ := strconv.ParseInt(m.Payload, 10, 64)
|
||||||
@ -390,6 +465,28 @@ func botListParsingRules(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range msgParsingRules {
|
for _, v := range msgParsingRules {
|
||||||
s = fmt.Sprintf("%s[%d] %s\n", s, v.ID, v.Description)
|
s = fmt.Sprintf("%s[%d] %s\n", s, v.ID, v.Description)
|
||||||
@ -409,6 +506,28 @@ func botListParsingRule(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
if clt.TGUserID64 != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Admin only",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
r := regexp.MustCompile("^[0-9]+$")
|
r := regexp.MustCompile("^[0-9]+$")
|
||||||
if r.MatchString(m.Payload) {
|
if r.MatchString(m.Payload) {
|
||||||
i, _ := strconv.ParseInt(m.Payload, 10, 64)
|
i, _ := strconv.ParseInt(m.Payload, 10, 64)
|
||||||
@ -465,6 +584,22 @@ func botGStock(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botTimer(m *tb.Message) {
|
func botTimer(m *tb.Message) {
|
||||||
|
if !m.Private() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt, ok := getLockedClient(m.Chat.ID, false)
|
||||||
|
if !ok {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt.Unlock()
|
||||||
|
|
||||||
r := regexp.MustCompile("^(?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
|
r := regexp.MustCompile("^(?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
|
||||||
if r.MatchString(m.Payload) {
|
if r.MatchString(m.Payload) {
|
||||||
d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}"))
|
d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}"))
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
||||||
muxClients.Lock()
|
muxClients.RLock()
|
||||||
if c, ok := clients[id]; ok {
|
if c, ok := clients[id]; ok {
|
||||||
c.Mux.Lock()
|
c.Mux.Lock()
|
||||||
return c, true
|
return c, true
|
||||||
@ -20,7 +20,7 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
|||||||
} else {
|
} else {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
defer muxClients.Unlock()
|
defer muxClients.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func clientSendCWMsg(userID64 int64, s string) {
|
func clientSendCWMsg(userID64 int64, s string) {
|
||||||
|
2
main.go
2
main.go
@ -62,7 +62,7 @@ var (
|
|||||||
msgParsingRules map[int]MessageParsingRule
|
msgParsingRules map[int]MessageParsingRule
|
||||||
|
|
||||||
clients map[int64]*ChirpClient
|
clients map[int64]*ChirpClient
|
||||||
muxClients sync.Mutex
|
muxClients sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrintText(m *tb.Message) {
|
func PrintText(m *tb.Message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user