2019-05-06 04:54:24 +02:00
|
|
|
|
package main
|
|
|
|
|
|
2019-05-09 11:19:55 +02:00
|
|
|
|
import (
|
|
|
|
|
"regexp"
|
2019-05-09 12:36:45 +02:00
|
|
|
|
"time"
|
2019-05-17 10:09:09 +02:00
|
|
|
|
|
|
|
|
|
"github.com/streadway/amqp"
|
|
|
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
2019-05-09 11:19:55 +02:00
|
|
|
|
)
|
|
|
|
|
|
2019-05-17 09:02:35 +02:00
|
|
|
|
type MQKeepAlive struct {
|
|
|
|
|
UserID64 int64 `json:"user_id"`
|
|
|
|
|
Nickname string `json:"nick"`
|
|
|
|
|
Queue string `json:"queue"`
|
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-17 10:09:09 +02:00
|
|
|
|
type MQClient struct {
|
2019-05-17 10:10:14 +02:00
|
|
|
|
Connection *amqp.Connection
|
|
|
|
|
Channel *amqp.Channel
|
|
|
|
|
Queue amqp.Queue
|
2019-05-17 10:09:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 12:03:18 +02:00
|
|
|
|
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"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 04:16:35 +02:00
|
|
|
|
type TGCommand struct {
|
2019-05-15 10:58:25 +02:00
|
|
|
|
Type int64 `json:"type"`
|
|
|
|
|
FromChatID64 int64 `json:"from_chat_id"`
|
|
|
|
|
FromUserID64 int64 `json:"from_user_id"`
|
|
|
|
|
FromMsgID64 int64 `json:"from_msg_id"`
|
|
|
|
|
ToChatID64 int64 `json:"to_chat_id"`
|
|
|
|
|
ToUserID64 int64 `json:"to_user_id"`
|
|
|
|
|
Text string `json:"text"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-25 09:25:11 +02:00
|
|
|
|
type ChatWarsCastle struct {
|
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
Logo string `json:"logo"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChatWarsGuild struct {
|
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-25 10:56:13 +02:00
|
|
|
|
type ChatWarsUser struct {
|
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 04:54:24 +02:00
|
|
|
|
type ChatWarsMessage struct {
|
2019-05-25 09:25:11 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
2019-05-09 12:36:45 +02:00
|
|
|
|
UserID64 int64 `json:"user_id"`
|
|
|
|
|
SenderUserID64 int64 `json:"sender_user_id"`
|
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
|
ID64 int64 `json:"id"`
|
|
|
|
|
ChatID64 int64 `json:"chat_id"`
|
|
|
|
|
Text string `json:"text"`
|
2019-05-06 04:54:24 +02:00
|
|
|
|
}
|
2019-05-06 05:59:19 +02:00
|
|
|
|
|
2019-05-19 06:19:24 +02:00
|
|
|
|
type ChatWarsMessageReportAck struct {
|
2019-05-18 09:44:25 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-18 16:15:24 +02:00
|
|
|
|
type ChatWarsMessageDuelFight struct {
|
2019-05-19 14:01:32 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
WinCastle string `json:"win_castle"`
|
|
|
|
|
WinGuild string `json:"win_guild"`
|
|
|
|
|
WinUser string `json:"win_user"`
|
|
|
|
|
WinLife int64 `json:"win_life"`
|
|
|
|
|
LossCastle string `json:"loss_castle"`
|
|
|
|
|
LossGuild string `json:"loss_guild"`
|
|
|
|
|
LossUser string `json:"loss_user"`
|
|
|
|
|
LossLife int64 `json:"loss_life"`
|
|
|
|
|
Exp int64 `json:"exp"`
|
|
|
|
|
Weapon string `json:"weapon"`
|
2019-05-18 16:15:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 11:19:02 +02:00
|
|
|
|
type ChatWarsMessageAuctionAnnounce struct {
|
2019-05-11 07:41:05 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
2019-05-09 12:36:45 +02:00
|
|
|
|
LotID int32 `json:"lot_id"`
|
|
|
|
|
Item string `json:"item"`
|
|
|
|
|
Cond string `json:"cond"`
|
|
|
|
|
Quality string `json:"quality"`
|
|
|
|
|
Seller string `json:"seller"`
|
|
|
|
|
Buyer string `json:"buyer"`
|
|
|
|
|
Price int32 `json:"price"`
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
End time.Time `json:"end"`
|
2019-05-09 11:19:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 12:02:17 +02:00
|
|
|
|
type ChatWarsMessagePillageInc struct {
|
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
Attacker string `json:"attacker"`
|
|
|
|
|
Guild string `json:"guild"`
|
|
|
|
|
Castle string `json:"castle"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 12:45:05 +02:00
|
|
|
|
type ChatWarsMessageMiniWar struct {
|
2019-05-14 04:28:26 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
|
|
|
|
Report map[string]*ChatWarsMessageMiniWarCastle `json:"castle"`
|
|
|
|
|
Time time.Time `json:"time"`
|
2019-05-11 12:45:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChatWarsMessageMiniWarCastle struct {
|
2019-05-11 13:22:50 +02:00
|
|
|
|
Gardian string `json:"gardian"`
|
|
|
|
|
Result string `json:"result"`
|
2019-05-13 08:12:31 +02:00
|
|
|
|
Gold int64 `json:"gold"`
|
|
|
|
|
Stock int64 `json:"stock"`
|
|
|
|
|
Points int64 `json:"points"`
|
2019-05-11 12:45:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-25 13:12:31 +02:00
|
|
|
|
type ChatWarsMessageUnionWar struct {
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 13:15:25 +02:00
|
|
|
|
type MessageParsingRule struct {
|
|
|
|
|
ID int32
|
|
|
|
|
Priority int32
|
|
|
|
|
Description string
|
|
|
|
|
Rule string
|
|
|
|
|
MsgTypeID int32
|
2019-05-08 12:33:52 +02:00
|
|
|
|
re *regexp.Regexp
|
2019-05-07 13:15:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 05:15:42 +02:00
|
|
|
|
type BotMsg struct {
|
|
|
|
|
To tb.Recipient
|
|
|
|
|
Text string
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 11:23:47 +02:00
|
|
|
|
type Job struct {
|
|
|
|
|
ID64 int64
|
|
|
|
|
JobTypeID int32
|
2019-05-11 06:54:12 +02:00
|
|
|
|
Status int32
|
2019-05-15 12:31:03 +02:00
|
|
|
|
UserID64 int64
|
2019-05-10 11:23:47 +02:00
|
|
|
|
Payload []byte
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadPillage struct {
|
2019-05-18 12:33:53 +02:00
|
|
|
|
ObjID64 int64 `json:"obj_id"`
|
2019-05-10 11:23:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadTribute struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadStatus struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadWithdrawal struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadGStock struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type JobPayloadRescanMsg struct {
|
2019-05-15 12:31:03 +02:00
|
|
|
|
Query string `json:"query"`
|
|
|
|
|
MsgID64 int64 `json:"msg_id"`
|
|
|
|
|
ChatID64 int64 `json:"chat_id"`
|
2019-05-10 13:33:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 06:54:12 +02:00
|
|
|
|
type JobPayloadSetDone struct {
|
2019-05-16 04:49:34 +02:00
|
|
|
|
JobID64 int64 `json:"job_id"`
|
|
|
|
|
MsgID64 int64 `json:"msg_id"`
|
|
|
|
|
ChatID64 int64 `json:"chat_id"`
|
|
|
|
|
Text string `json:"test"`
|
2019-05-11 06:54:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 05:59:19 +02:00
|
|
|
|
const (
|
2019-05-17 10:30:01 +02:00
|
|
|
|
userID64ChtWrsBot = 408101137
|
|
|
|
|
|
2019-05-15 10:58:25 +02:00
|
|
|
|
commandForwardMsg = 1
|
|
|
|
|
commandReplyMsg = 2
|
|
|
|
|
commandSendMsg = 3
|
|
|
|
|
commandDeleteMsg = 4
|
|
|
|
|
commandRefreshMsg = 5
|
|
|
|
|
|
2019-05-07 05:12:03 +02:00
|
|
|
|
objTypeUser = 1
|
|
|
|
|
objTypeGuild = 2
|
|
|
|
|
objTypeMessage = 3
|
|
|
|
|
objTypeWar = 4
|
|
|
|
|
objTypeWarReport = 5
|
2019-05-07 13:15:25 +02:00
|
|
|
|
objTypeJob = 6
|
2019-05-09 09:17:59 +02:00
|
|
|
|
objTypeItem = 7
|
2019-05-25 09:25:11 +02:00
|
|
|
|
objTypeCastle = 8
|
2019-05-25 09:37:45 +02:00
|
|
|
|
objTypeFair = 9
|
|
|
|
|
objTypeUnion = 10
|
2019-05-06 05:59:19 +02:00
|
|
|
|
|
2019-05-14 04:28:26 +02:00
|
|
|
|
castleDeer = 1
|
|
|
|
|
castleDragon = 2
|
|
|
|
|
castleHighnest = 3
|
|
|
|
|
castleMoon = 4
|
|
|
|
|
castlePotato = 5
|
|
|
|
|
castleShark = 6
|
|
|
|
|
castleWolf = 7
|
|
|
|
|
|
2019-05-25 09:25:11 +02:00
|
|
|
|
objSubTypeUser = 101
|
|
|
|
|
objSubTypeGuild = 201
|
2019-05-08 16:34:47 +02:00
|
|
|
|
objSubTypeMessageUnknown = 301
|
2019-05-19 06:05:04 +02:00
|
|
|
|
objSubTypeMessageWar = 302 // from Chat Wars Reports (not done)
|
|
|
|
|
objSubTypeMessageMiniWar = 303 // from Chat Wars Mini Reports (done)
|
|
|
|
|
objSubTypeMessageGuildWar = 304 // from Chat Wars Reports (not done)
|
|
|
|
|
objSubTypeMessageReportReq = 305 // /report (done)
|
2019-05-19 06:19:24 +02:00
|
|
|
|
objSubTypeMessageReportAck = 306 // result from /report (done)
|
2019-05-19 06:05:04 +02:00
|
|
|
|
objSubTypeMessageGReportReq = 307 // /g_report (done)
|
|
|
|
|
objSubTypeMessageGReportAck = 308 // result from /g_report (not done)
|
|
|
|
|
objSubTypeMessageQuestResult = 309 // result from going to quest (not done)
|
|
|
|
|
objSubTypeMessageDuelFight = 310 // result from going to duel fight (done)
|
|
|
|
|
objSubTypeMessageHeroReq = 311 // /hero (done)
|
|
|
|
|
objSubTypeMessageHeroAck = 312 // result from /hero (not done)
|
|
|
|
|
objSubTypeMessageMeReq = 313 // 🏅Me (done)
|
|
|
|
|
objSubTypeMessageMeAck = 314 // result from 🏅Me (not done)
|
|
|
|
|
objSubTypeMessageInventoryReq = 315 // /inv (done)
|
|
|
|
|
objSubTypeMessageInventoryAck = 316 // result from /inv (not done)
|
|
|
|
|
objSubTypeMessagePillageInc = 317 // random incoming pillage (done)
|
|
|
|
|
objSubTypeMessagePillageGo = 318 // ack from /go (done)
|
|
|
|
|
objSubTypeMessagePillageTimeout = 319 // ack from lack of /go (done)
|
|
|
|
|
objSubTypeMessagePillageWin = 320 // pillage successfully intercepted (done)
|
|
|
|
|
objSubTypeMessagePillageLoss = 321 // pillage not intercepted (done)
|
|
|
|
|
objSubTypeMessageTributeInc = 322 // request for a /pledge (not done)
|
|
|
|
|
objSubTypeMessageTributeAck = 323 // pledge accepted (not done)
|
|
|
|
|
objSubTypeMessageAuctionAnnounce = 324 // from Boris and Co, Ltd (done)
|
|
|
|
|
objSubTypeMessageAuctionUpdReq = 325 // /l_123456 msg (not done)
|
|
|
|
|
objSubTypeMessageAuctionUpdAck = 326 // result from /l_123456 (not done)
|
|
|
|
|
objSubTypeMessageTimeAck = 327 // result from /time (done)
|
|
|
|
|
objSubTypeMessageTimeReq = 328 // /time (done)
|
|
|
|
|
objSubTypeMessageGo = 329 // /go (done)
|
|
|
|
|
objSubTypeMessagePledge = 330 // /pledge (done)
|
|
|
|
|
objSubTypeMessageGoQuest = 331 // 🌲Forest or 🍄Swamp or ⛰️Valley (not done)
|
|
|
|
|
objSubTypeMessageGoFastFight = 332 // ▶️Fast fight (not done)
|
|
|
|
|
objSubTypeMessageGoArena = 333 // 📯Arena (not done)
|
2019-05-19 06:13:33 +02:00
|
|
|
|
objSubTypeMessageTop = 334 // any /topXX (not done)
|
|
|
|
|
objSubTypeMessageMenu = 335 // main menu (not done)
|
2019-05-19 08:35:26 +02:00
|
|
|
|
objSubTypeMessageBuyReq = 336 // /wtb_xx (done)
|
|
|
|
|
objSubTypeMessageSellReq = 337 // /wts_xx (done)
|
|
|
|
|
objSubTypeMessageOrderbookReq = 338 // /t_xx (done)
|
2019-05-19 14:00:18 +02:00
|
|
|
|
objSubTypeMessageOrderbookAck = 339 // orderbook summary (not done)
|
2019-05-20 16:16:49 +02:00
|
|
|
|
objSubTypeMessageWithdrawReq = 340 // /g_withdraw (done)
|
|
|
|
|
objSubTypeMessageWithdrawCode = 341 // code to receive (done)
|
|
|
|
|
objSubTypeMessageWithdrawRcv = 342 // Received msg (done)
|
|
|
|
|
objSubTypeMessageDepositReq = 343 // /g_deposit (done)
|
|
|
|
|
objSubTypeMessageDepositAck = 344 // Deposited successfully (done)
|
|
|
|
|
objSubTypeMessageStockReq = 345 // /stock (done)
|
|
|
|
|
objSubTypeMessageStockAck = 346 // result from /stock (not done)
|
|
|
|
|
objSubTypeMessageMiscReq = 347 // /misc (done)
|
|
|
|
|
objSubTypeMEssageMiscAck = 348 // result from /misc (not done)
|
2019-05-25 09:25:11 +02:00
|
|
|
|
objSubTypeMessageUnionWar = 349 // from Chat Wars Reports (not done)
|
2019-05-25 12:59:27 +02:00
|
|
|
|
objSubTypeMessageTUReportReq = 350 // /tu_report (not done)
|
|
|
|
|
objSubTypeMessageTUReportAck = 351 // result from /tu_report (not done)
|
2019-05-27 06:03:04 +02:00
|
|
|
|
objSubTypeMessageTimeout = 352 // generic timeout for action
|
2019-05-08 16:34:47 +02:00
|
|
|
|
objSubTypeJobPillage = 601
|
|
|
|
|
objSubTypeJobTribute = 602
|
|
|
|
|
objSubTypeJobStatus = 603
|
|
|
|
|
objSubTypeJobWithdrawal = 604
|
|
|
|
|
objSubTypeJobGStock = 605
|
2019-05-10 11:23:47 +02:00
|
|
|
|
objSubTypeJobRescanMsg = 606
|
2019-05-19 05:20:01 +02:00
|
|
|
|
objSubTypeJobSetJobDone = 607
|
2019-05-26 15:06:12 +02:00
|
|
|
|
objSubTypeJobMsgClient = 608
|
2019-05-09 09:17:59 +02:00
|
|
|
|
objSubTypeItemResource = 701
|
|
|
|
|
objSubTypeItemAlch = 702
|
|
|
|
|
objSubTypeItemMisc = 703
|
|
|
|
|
objSubTypeItemRecipe = 704
|
|
|
|
|
objSubTypeItemPart = 705
|
|
|
|
|
objSubTypeItemOther = 706
|
2019-05-25 09:25:11 +02:00
|
|
|
|
objSubTypeCastle = 801
|
2019-05-25 09:37:45 +02:00
|
|
|
|
objSubTypeFair = 901
|
|
|
|
|
objSubTypeUnion = 1001
|
2019-05-06 09:25:57 +02:00
|
|
|
|
|
2019-05-18 12:33:53 +02:00
|
|
|
|
objJobStatusNew = 0
|
|
|
|
|
objJobStatusPillageGo = 1
|
|
|
|
|
objJonStatusPending = 10
|
|
|
|
|
objJobStatusDone = 20
|
2019-05-10 11:23:47 +02:00
|
|
|
|
|
2019-05-19 05:20:01 +02:00
|
|
|
|
objJobPriority = 1
|
|
|
|
|
objJobPriorityRescanMsg = 2
|
|
|
|
|
objJobPriorityRescanAllMsg = 3
|
2019-05-11 06:54:12 +02:00
|
|
|
|
|
2019-05-18 16:29:48 +02:00
|
|
|
|
MQGetMsgWorkers = 12
|
|
|
|
|
MQCWMsgQueueSize = 100
|
|
|
|
|
SQLCWMsgWorkers = 6
|
|
|
|
|
SQLIdentifyMsgWorkers = 6
|
2019-05-19 04:54:34 +02:00
|
|
|
|
SQLMsgIdentifyQueueSize = 100
|
|
|
|
|
SQLMsgRescanJobSize = 25
|
2019-05-18 16:29:48 +02:00
|
|
|
|
SQLJobWorkers = 12
|
|
|
|
|
TGCmdWorkers = 3
|
|
|
|
|
TGCmdQueueSize = 100
|
|
|
|
|
MQTGCmdWorkers = 3
|
|
|
|
|
MQTGCmdQueueSize = 100
|
2019-05-19 04:54:34 +02:00
|
|
|
|
SQLJobSliceSize = 25
|
2019-05-06 05:59:19 +02:00
|
|
|
|
)
|
2019-05-08 17:18:17 +02:00
|
|
|
|
|
2019-05-09 04:27:21 +02:00
|
|
|
|
var (
|
|
|
|
|
chatWarsMonth = map[string]int{
|
|
|
|
|
"Wintar": 1,
|
|
|
|
|
"Hornung": 2,
|
|
|
|
|
"Lenzin": 3,
|
|
|
|
|
"Ōstar": 4,
|
|
|
|
|
"Winni": 5,
|
|
|
|
|
"Brāh": 6,
|
|
|
|
|
"Hewi": 7,
|
|
|
|
|
"Aran": 8,
|
|
|
|
|
"Witu": 9,
|
|
|
|
|
"Wīndume": 10,
|
|
|
|
|
"Herbist": 11,
|
|
|
|
|
"Hailag": 12}
|
2019-05-09 04:28:06 +02:00
|
|
|
|
|
|
|
|
|
chatWarsDaysSpecial = map[int]map[int]int{
|
|
|
|
|
2: {1060: 29},
|
|
|
|
|
4: {1060: 29}}
|
|
|
|
|
|
2019-05-09 04:27:21 +02:00
|
|
|
|
chatWarsDays = map[int]int{
|
|
|
|
|
1: 31,
|
|
|
|
|
2: 28,
|
|
|
|
|
3: 31,
|
|
|
|
|
4: 30,
|
|
|
|
|
5: 31,
|
|
|
|
|
6: 30,
|
|
|
|
|
7: 31,
|
|
|
|
|
8: 31,
|
|
|
|
|
9: 30,
|
|
|
|
|
10: 31,
|
|
|
|
|
11: 30,
|
|
|
|
|
12: 31}
|
|
|
|
|
)
|