security with spamming
This commit is contained in:
parent
8398560f9c
commit
a020a111a8
45
bot.go
45
bot.go
@ -711,6 +711,17 @@ func botListParsingRule(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botGStock(m *ChatWarsMessage) {
|
func botGStock(m *ChatWarsMessage) {
|
||||||
|
if hasUnfinishedJob(cacheObjSubType[`job_gstock`]) {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "GStock is already running",
|
||||||
|
FromMsgID64: m.ID64,
|
||||||
|
FromChatID64: m.ChatID64,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
clt, err := getLockedIdleClient()
|
clt, err := getLockedIdleClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
@ -756,8 +767,18 @@ func botGStock(m *ChatWarsMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botShops(m *ChatWarsMessage) {
|
func botShops(m *ChatWarsMessage) {
|
||||||
// fan out to all active and non idle clients
|
if hasUnfinishedJob(cacheObjSubType[`job_shops`]) {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Shops is already running",
|
||||||
|
FromMsgID64: m.ID64,
|
||||||
|
FromChatID64: m.ChatID64,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// fan out to all active and non idle clients
|
||||||
clts, err := getAllIdleClientID64()
|
clts, err := getAllIdleClientID64()
|
||||||
if err != nil || len(clts) == 0 {
|
if err != nil || len(clts) == 0 {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
@ -809,6 +830,17 @@ func botShops(m *ChatWarsMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botCraftItem(m *ChatWarsMessage, r *regexp.Regexp) {
|
func botCraftItem(m *ChatWarsMessage, r *regexp.Regexp) {
|
||||||
|
if hasUnfinishedJob(cacheObjSubType[`job_craft_item`]) {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Craft Item is already running",
|
||||||
|
FromMsgID64: m.ID64,
|
||||||
|
FromChatID64: m.ChatID64,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
clt, err := getLockedIdleClient()
|
clt, err := getLockedIdleClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
@ -903,6 +935,17 @@ func botUserConfig(m *ChatWarsMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) {
|
func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) {
|
||||||
|
if hasUnfinishedJob(cacheObjSubType[`job_craft_all`]) {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Craft All is already running",
|
||||||
|
FromMsgID64: m.ID64,
|
||||||
|
FromChatID64: m.ChatID64,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
clt, err := getLockedIdleClient()
|
clt, err := getLockedIdleClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
|
21
job.go
21
job.go
@ -282,6 +282,27 @@ func rescheduleJob(jobID64 int64, trigger int64, schedule time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasUnfinishedJob(jobTypeID64 int64) bool {
|
||||||
|
var count int64
|
||||||
|
stmt, err := db.Prepare(`SELECT count(*) FROM obj o, obj_job j WHERE o.id = j.obj_id AND o.obj_sub_type_id = ? AND j.is_done = 0;`)
|
||||||
|
logOnError(err, "hasUnfinishedJob : prepare select obj")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
err = stmt.QueryRow(jobTypeID64).Scan(&count)
|
||||||
|
logOnError(err, "hasUnfinishedJob : exec select obj")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func loadCurrentJobs() ([]Job, error) {
|
func loadCurrentJobs() ([]Job, error) {
|
||||||
var (
|
var (
|
||||||
objId int64
|
objId int64
|
||||||
|
Loading…
Reference in New Issue
Block a user