diff --git a/bot/go.mod b/bot/go.mod new file mode 100644 index 0000000..3859aa7 --- /dev/null +++ b/bot/go.mod @@ -0,0 +1,3 @@ +module lirqetes.ru/thelanc3/laura + +go 1.25.4 diff --git a/bot/main.go b/bot/main.go new file mode 100644 index 0000000..d61da8c --- /dev/null +++ b/bot/main.go @@ -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) + } + } + } +} diff --git a/bot/queue/bot_action.go b/bot/queue/bot_action.go new file mode 100644 index 0000000..7a7d56a --- /dev/null +++ b/bot/queue/bot_action.go @@ -0,0 +1,5 @@ +package queue + +import "context" + +type BotAction func(ctx context.Context)