Files
trbot/main.go
2025-02-11 22:19:51 +08:00

69 lines
1.4 KiB
Go

// main.go
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)
var botMe *models.User
var logChat_ID int64 = -1002499888124
var modules map[string]Module
var plugin_names []string
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
allowedUpdates := bot.AllowedUpdates{
"message",
"inline_query",
"chosen_inline_result",
}
opts := []bot.Option{
bot.WithDefaultHandler(defaultHandler),
bot.WithAllowedUpdates(allowedUpdates),
}
thebot, err := bot.New("", opts...)
if err != nil { panic(err) }
botMe, _ = thebot.GetMe(ctx)
log.Printf("name[%s] [@%s] id[%d]", botMe.FirstName, botMe.Username, botMe.ID)
AdditionalDatas = readAdditionalDatas(AdditionalDatas_paths)
// 动态加载插件
modules, plugin_names, err = LoadPlugins("./plugins")
if err != nil {
log.Fatal("Failed to load plugins:", err)
}
if len(modules) == 0 {
log.Println("No plugins found.")
} else {
log.Printf("Loaded %d plugins: %v", len(modules), plugin_names)
}
// for i := range plugin_names {
// fmt.Print(plugin_names[i])
// response := modules[plugin_names[i]].TextHandler("wtf")
// fmt.Println(" Response:", response)
// }
log.Println("Working at Long Polling Mode")
thebot.Start(ctx)
<-ctx.Done()
}