Init bot go.mod project and added queue system for bot actions handling
This commit is contained in:
3
bot/go.mod
Normal file
3
bot/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module lirqetes.ru/thelanc3/laura
|
||||||
|
|
||||||
|
go 1.25.4
|
||||||
37
bot/main.go
Normal file
37
bot/main.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"lirqetes.ru/thelanc3/laura/queue"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx := context.Background()
|
||||||
|
actions := make(chan queue.BotAction, 200)
|
||||||
|
go actionsWorker(ctx, actions, 34*time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
func actionsWorker(
|
||||||
|
ctx context.Context,
|
||||||
|
actions <-chan queue.BotAction,
|
||||||
|
interval time.Duration,
|
||||||
|
) {
|
||||||
|
ticker := time.NewTicker(interval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case action := <-actions:
|
||||||
|
{
|
||||||
|
<-ticker.C
|
||||||
|
action(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
bot/queue/bot_action.go
Normal file
5
bot/queue/bot_action.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package queue
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type BotAction func(ctx context.Context)
|
||||||
Reference in New Issue
Block a user