From 02039a14bdc6a3ba6c28075d814eedf246de3678 Mon Sep 17 00:00:00 2001 From: TheLanc3 Date: Sat, 24 Jan 2026 00:20:36 +0300 Subject: [PATCH] Init bot go.mod project and added queue system for bot actions handling --- bot/go.mod | 3 +++ bot/main.go | 37 +++++++++++++++++++++++++++++++++++++ bot/queue/bot_action.go | 5 +++++ 3 files changed, 45 insertions(+) create mode 100644 bot/go.mod create mode 100644 bot/main.go create mode 100644 bot/queue/bot_action.go 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)