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() {
|
||||
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
|
||||
clientsKeepAlive.Range(func(k, v interface{}) bool {
|
||||
ka := v.(*MQKeepAlive)
|
||||
if v2, ok2 := clientsCW.Load(ka.UserID64); ok2 {
|
||||
clt := v2.(*ChatWarsClient)
|
||||
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d\n", ret, ka.Nickname, clt.UserID64, ka.UserID64)
|
||||
for id, c := range clients {
|
||||
if c.Active {
|
||||
ret = fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d (online)\n", ret, c.MQ.User, c.CWUserID64, c.TGUserID64)
|
||||
} 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{
|
||||
Type: commandReplyMsg,
|
||||
Text: ret,
|
||||
@ -201,7 +202,8 @@ func botMsgRescan(m *tb.Message) {
|
||||
if !m.Private() {
|
||||
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{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Client not registered",
|
||||
@ -211,6 +213,17 @@ func botMsgRescan(m *tb.Message) {
|
||||
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]+$")
|
||||
if r.MatchString(m.Payload) {
|
||||
p := JobPayloadRescanMsg{
|
||||
@ -251,7 +264,8 @@ func botMsgRescanAll(m *tb.Message) {
|
||||
if !m.Private() {
|
||||
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{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Client not registered",
|
||||
@ -261,6 +275,17 @@ func botMsgRescanAll(m *tb.Message) {
|
||||
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
|
||||
}
|
||||
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),
|
||||
MsgID64: int64(m.ID),
|
||||
@ -294,7 +319,8 @@ func botBackupExport(m *tb.Message) {
|
||||
if !m.Private() {
|
||||
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{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Client not registered",
|
||||
@ -304,6 +330,17 @@ func botBackupExport(m *tb.Message) {
|
||||
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
|
||||
}
|
||||
|
||||
p := JobPayloadBackupExport{
|
||||
MsgID64: int64(m.ID),
|
||||
@ -320,7 +357,8 @@ func botBackupImport(m *tb.Message) {
|
||||
if !m.Private() {
|
||||
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{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Client not registered",
|
||||
@ -330,6 +368,17 @@ func botBackupImport(m *tb.Message) {
|
||||
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(`^((http[s]?\:)\/\/)?([^\?\:\/#]+)(\:([0-9]+))?(\/[^\?\#]*)?(\?([^#]*))?(#.*)?.zip$`)
|
||||
if !r.MatchString(m.Payload) {
|
||||
c := TGCommand{
|
||||
@ -356,6 +405,32 @@ func botBackupImport(m *tb.Message) {
|
||||
|
||||
func botMsgDump(m *tb.Message) {
|
||||
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]+$")
|
||||
if r.MatchString(m.Payload) {
|
||||
objId, _ := strconv.ParseInt(m.Payload, 10, 64)
|
||||
@ -390,6 +465,28 @@ func botListParsingRules(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()
|
||||
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 {
|
||||
s = fmt.Sprintf("%s[%d] %s\n", s, v.ID, v.Description)
|
||||
@ -409,6 +506,28 @@ func botListParsingRule(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()
|
||||
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]+$")
|
||||
if r.MatchString(m.Payload) {
|
||||
i, _ := strconv.ParseInt(m.Payload, 10, 64)
|
||||
@ -465,6 +584,22 @@ func botGStock(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>(.*))\"$")
|
||||
if r.MatchString(m.Payload) {
|
||||
d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}"))
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
||||
muxClients.Lock()
|
||||
muxClients.RLock()
|
||||
if c, ok := clients[id]; ok {
|
||||
c.Mux.Lock()
|
||||
return c, true
|
||||
@ -20,7 +20,7 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
||||
} else {
|
||||
return 0, false
|
||||
}
|
||||
defer muxClients.Unlock()
|
||||
defer muxClients.RUnlock()
|
||||
}
|
||||
|
||||
func clientSendCWMsg(userID64 int64, s string) {
|
||||
|
Loading…
Reference in New Issue
Block a user