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) { func clientMsgMeAck(m *ChatWarsMessageMeAck) {
if _, ok := clientsQueue[m.Msg.UserID64]; ok { if _, ok := clientsQueue[m.Msg.UserID64]; ok {
if c, ok := clientsCW[m.UserID64]; ok { if c, ok := clientsCW[m.Msg.UserID64]; ok {
if c.LastUpdate.Before(m.Msg.Date) { if c.LastUserUpdate.Before(m.Msg.Date) {
c.GuildID64 = m.GuildID64 c.GuildID64 = m.GuildID64
c.State = m.State c.State = m.State
c.LastUpdate = m.Msg.Date c.LastUpdate = m.Msg.Date
@ -27,14 +27,37 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) {
} }
} else { } else {
c := ChatWarsClient{ c := ChatWarsClient{
GuildID64: m.GuildID64, UserID64: m.UserID64,
State: m.State, TelegramID64: m.Msg.UserID64,
LastUpdate: m.Msg.Date, GuildID64: m.GuildID64,
State: m.State,
LastUpdate: m.Msg.Date,
} }
clientsCW[m.UserID64] = &c clientsCW[m.Msg.UserID64] = &c
if cacheObjGuild[``].ObjID64 != m.GuildID64 { if cacheObjGuild[``].ObjID64 != m.GuildID64 {
clientSendCWMsg(m.Msg.UserID64, "/g_roles") 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 { type ChatWarsClient struct {
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"` TelegramID64 int64 `json:"telegram_id"`
Role string `json:"role"` GuildID64 int64 `json:"guild_id"`
State string `json:"state"` Role string `json:"role"`
BusyUntil time.Time `json:"busy_until"` State string `json:"state"`
LastUpdate time.Time `json:"last_update"` BusyUntil time.Time `json:"busy_until"`
LastUpdate time.Time `json:"last_update"`
} }
type TGCommand struct { type TGCommand struct {

20
msg.go
View File

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

View File

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