285 lines
8.1 KiB
Go
285 lines
8.1 KiB
Go
package main
|
||
|
||
import (
|
||
"regexp"
|
||
"time"
|
||
|
||
"github.com/streadway/amqp"
|
||
tb "gopkg.in/tucnak/telebot.v2"
|
||
)
|
||
|
||
type MQKeepAlive struct {
|
||
UserID64 int64 `json:"user_id"`
|
||
Nickname string `json:"nick"`
|
||
Queue string `json:"queue"`
|
||
Date time.Time `json:"date"`
|
||
}
|
||
|
||
type MQClient struct {
|
||
Connection *amqp.Connection
|
||
Channel *amqp.Channel
|
||
Queue amqp.Queue
|
||
}
|
||
|
||
type TGCommand struct {
|
||
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"`
|
||
}
|
||
|
||
type ChatWarsMessage struct {
|
||
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"`
|
||
}
|
||
|
||
type ChatWarsMessageReportAck struct {
|
||
ObjID64 int64 `json:"obj_id"`
|
||
}
|
||
|
||
type ChatWarsMessageDuelFight struct {
|
||
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"`
|
||
}
|
||
|
||
type ChatWarsMessageAuctionAnnounce struct {
|
||
ObjID64 int64 `json:"obj_id"`
|
||
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"`
|
||
}
|
||
|
||
type ChatWarsMessagePillageInc struct {
|
||
ObjID64 int64 `json:"obj_id"`
|
||
Attacker string `json:"attacker"`
|
||
Guild string `json:"guild"`
|
||
Castle string `json:"castle"`
|
||
}
|
||
|
||
type ChatWarsMessageMiniWar struct {
|
||
ObjID64 int64 `json:"obj_id"`
|
||
Report map[string]*ChatWarsMessageMiniWarCastle `json:"castle"`
|
||
Time time.Time `json:"time"`
|
||
}
|
||
|
||
type ChatWarsMessageMiniWarCastle struct {
|
||
Gardian string `json:"gardian"`
|
||
Result string `json:"result"`
|
||
Gold int64 `json:"gold"`
|
||
Stock int64 `json:"stock"`
|
||
Points int64 `json:"points"`
|
||
}
|
||
|
||
type MessageParsingRule struct {
|
||
ID int32
|
||
Priority int32
|
||
Description string
|
||
Rule string
|
||
MsgTypeID int32
|
||
re *regexp.Regexp
|
||
}
|
||
|
||
type BotMsg struct {
|
||
To tb.Recipient
|
||
Text string
|
||
}
|
||
|
||
type Job struct {
|
||
ID64 int64
|
||
JobTypeID int32
|
||
Status int32
|
||
UserID64 int64
|
||
Payload []byte
|
||
}
|
||
|
||
type JobPayloadPillage struct {
|
||
ObjID64 int64 `json:"obj_id"`
|
||
}
|
||
|
||
type JobPayloadTribute struct {
|
||
}
|
||
|
||
type JobPayloadStatus struct {
|
||
}
|
||
|
||
type JobPayloadWithdrawal struct {
|
||
}
|
||
|
||
type JobPayloadGStock struct {
|
||
}
|
||
|
||
type JobPayloadRescanMsg struct {
|
||
Query string `json:"query"`
|
||
MsgID64 int64 `json:"msg_id"`
|
||
ChatID64 int64 `json:"chat_id"`
|
||
}
|
||
|
||
type JobPayloadSetDone struct {
|
||
JobID64 int64 `json:"job_id"`
|
||
MsgID64 int64 `json:"msg_id"`
|
||
ChatID64 int64 `json:"chat_id"`
|
||
Text string `json:"test"`
|
||
}
|
||
|
||
const (
|
||
userID64ChtWrsBot = 408101137
|
||
|
||
commandForwardMsg = 1
|
||
commandReplyMsg = 2
|
||
commandSendMsg = 3
|
||
commandDeleteMsg = 4
|
||
commandRefreshMsg = 5
|
||
|
||
objTypeUser = 1
|
||
objTypeGuild = 2
|
||
objTypeMessage = 3
|
||
objTypeWar = 4
|
||
objTypeWarReport = 5
|
||
objTypeJob = 6
|
||
objTypeItem = 7
|
||
|
||
castleDeer = 1
|
||
castleDragon = 2
|
||
castleHighnest = 3
|
||
castleMoon = 4
|
||
castlePotato = 5
|
||
castleShark = 6
|
||
castleWolf = 7
|
||
|
||
objSubTypeMessageUnknown = 301
|
||
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)
|
||
objSubTypeMessageReportAck = 306 // result from /report (done)
|
||
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)
|
||
objSubTypeMessageTop = 334 // any /topXX (not done)
|
||
objSubTypeMessageMenu = 335 // main menu (not done)
|
||
objSubTypeMessageBuyReq = 336 // /wtb_xx (done)
|
||
objSubTypeMessageSellReq = 337 // /wts_xx (done)
|
||
objSubTypeMessageOrderbookReq = 338 // /t_xx (done)
|
||
objSubTypeMessageOrderbookAck = 339 // orderbook summary (not done)
|
||
objSubTypeMessageWithdrawReq = 340 // /g_withdraw (not done)
|
||
objSubTypeMessageWithdrawCode = 341 // code to receive (not done)
|
||
objSubTypeMessageWithdrawRcv = 342 // Received msg (not done)
|
||
objSubTypeMessageDepositReq = 343 // /g_deposit (not done)
|
||
objSubTypeMessageDepositAck = 344 // Deposited successfully (not done)
|
||
objSubTypeJobPillage = 601
|
||
objSubTypeJobTribute = 602
|
||
objSubTypeJobStatus = 603
|
||
objSubTypeJobWithdrawal = 604
|
||
objSubTypeJobGStock = 605
|
||
objSubTypeJobRescanMsg = 606
|
||
objSubTypeJobSetJobDone = 607
|
||
objSubTypeItemResource = 701
|
||
objSubTypeItemAlch = 702
|
||
objSubTypeItemMisc = 703
|
||
objSubTypeItemRecipe = 704
|
||
objSubTypeItemPart = 705
|
||
objSubTypeItemOther = 706
|
||
|
||
objJobStatusNew = 0
|
||
objJobStatusPillageGo = 1
|
||
objJonStatusPending = 10
|
||
objJobStatusDone = 20
|
||
|
||
objJobPriority = 1
|
||
objJobPriorityRescanMsg = 2
|
||
objJobPriorityRescanAllMsg = 3
|
||
|
||
MQGetMsgWorkers = 12
|
||
MQCWMsgQueueSize = 100
|
||
SQLCWMsgWorkers = 6
|
||
SQLIdentifyMsgWorkers = 6
|
||
SQLMsgIdentifyQueueSize = 100
|
||
SQLMsgRescanJobSize = 25
|
||
SQLJobWorkers = 12
|
||
TGCmdWorkers = 3
|
||
TGCmdQueueSize = 100
|
||
MQTGCmdWorkers = 3
|
||
MQTGCmdQueueSize = 100
|
||
SQLJobSliceSize = 25
|
||
)
|
||
|
||
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}
|
||
|
||
chatWarsDaysSpecial = map[int]map[int]int{
|
||
2: {1060: 29},
|
||
4: {1060: 29}}
|
||
|
||
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}
|
||
)
|