This commit is contained in:
shoopea 2019-05-30 18:57:00 +08:00
parent 9868acd014
commit 2c0b361edd
4 changed files with 48 additions and 21 deletions

View File

@ -16,8 +16,8 @@ func clientSendCWMsg(userID64 int64, s string) {
func clientMsgMeAck(m *ChatWarsMessageMeAck) {
if _, ok := clientsQueue[m.Msg.UserID64]; ok {
if c, ok := clientsCW[m.UserID64]; ok {
if c.LastUpdate.Before(m.Msg.Date) {
if c, ok := clientsCW[m.Msg.UserID64]; ok {
if c.LastUserUpdate.Before(m.Msg.Date) {
c.GuildID64 = m.GuildID64
c.State = m.State
c.LastUpdate = m.Msg.Date
@ -27,14 +27,37 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) {
}
} else {
c := ChatWarsClient{
GuildID64: m.GuildID64,
State: m.State,
LastUpdate: m.Msg.Date,
UserID64: m.UserID64,
TelegramID64: m.Msg.UserID64,
GuildID64: m.GuildID64,
State: m.State,
LastUpdate: m.Msg.Date,
}
clientsCW[m.UserID64] = &c
clientsCW[m.Msg.UserID64] = &c
if cacheObjGuild[``].ObjID64 != m.GuildID64 {
clientSendCWMsg(m.Msg.UserID64, "/g_roles")
}
}
}
}
func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) {
if _, ok := clientsQueue[m.Msg.UserID64]; ok {
if c, ok := clientsCW[m.Msg.UserID64]; ok {
if c.LastUpdate.Before(m.Msg.Date) {
if m.CommanderID64 == c.UserID64 {
c.Role = `commander`
} else if m.BartenderID64 == c.UserID64 {
c.Role = `bartender`
} else if m.SquireID64 == c.UserID64 {
c.Role = `squire`
} else if m.TreasurerID64 == c.UserID64 {
c.Role = `treasurer`
} else {
c.role = `none`
}
c.LastUpdate = m.Msg.Date
}
}
}
}

13
def.go
View File

@ -22,12 +22,13 @@ type MQClient struct {
}
type ChatWarsClient struct {
UserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"`
Role string `json:"role"`
State string `json:"state"`
BusyUntil time.Time `json:"busy_until"`
LastUpdate time.Time `json:"last_update"`
UserID64 int64 `json:"user_id"`
TelegramID64 int64 `json:"telegram_id"`
GuildID64 int64 `json:"guild_id"`
Role string `json:"role"`
State string `json:"state"`
BusyUntil time.Time `json:"busy_until"`
LastUpdate time.Time `json:"last_update"`
}
type TGCommand struct {

20
msg.go
View File

@ -100,15 +100,17 @@ func parseSubTypeMessageGRolesAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
} else {
cwm.TreasurerID64 = 0
}
log.Printf("parseSubTypeMessageGRolesAck : Guild roles Ack identified\n")
log.Printf("parseSubTypeMessageGRolesAck : Bartender : %s\n", r.ReplaceAllString(m.Text, "${Bartender}"))
log.Printf("parseSubTypeMessageGRolesAck : Commander : %s\n", r.ReplaceAllString(m.Text, "${Commander}"))
log.Printf("parseSubTypeMessageGRolesAck : Squire : %s\n", r.ReplaceAllString(m.Text, "${Squire}"))
log.Printf("parseSubTypeMessageGRolesAck : Treasurer : %s\n", r.ReplaceAllString(m.Text, "${Treasurer}"))
log.Printf("cwm.BartenderID64 : %d\n", cwm.BartenderID64)
log.Printf("cwm.CommanderID64 : %d\n", cwm.CommanderID64)
log.Printf("cwm.SquireID64 : %d\n", cwm.SquireID64)
log.Printf("cwm.TreasurerID64 : %d\n", cwm.TreasurerID64)
/*
log.Printf("parseSubTypeMessageGRolesAck : Guild roles Ack identified\n")
log.Printf("parseSubTypeMessageGRolesAck : Bartender : %s\n", r.ReplaceAllString(m.Text, "${Bartender}"))
log.Printf("parseSubTypeMessageGRolesAck : Commander : %s\n", r.ReplaceAllString(m.Text, "${Commander}"))
log.Printf("parseSubTypeMessageGRolesAck : Squire : %s\n", r.ReplaceAllString(m.Text, "${Squire}"))
log.Printf("parseSubTypeMessageGRolesAck : Treasurer : %s\n", r.ReplaceAllString(m.Text, "${Treasurer}"))
log.Printf("cwm.BartenderID64 : %d\n", cwm.BartenderID64)
log.Printf("cwm.CommanderID64 : %d\n", cwm.CommanderID64)
log.Printf("cwm.SquireID64 : %d\n", cwm.SquireID64)
log.Printf("cwm.TreasurerID64 : %d\n", cwm.TreasurerID64)
*/
return &cwm, nil
}

View File

@ -241,6 +241,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageGRolesAck:
cwm, err := parseSubTypeMessageGRolesAck(m, r)
cwm.Msg = m
clientMsgGRolesAck(cwm)
err = setObjSubTypeId(objId, objSubTypeMessageGRolesAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GRolesAck)")
case objSubTypeMessageAuctionAnnounce: