init
commit
90bc515284
|
@ -0,0 +1,7 @@
|
|||
git add *
|
||||
|
||||
read -p "Commit message: " commit_message
|
||||
|
||||
git commit -m "$commit_message"
|
||||
|
||||
git push -u origin main
|
|
@ -0,0 +1,29 @@
|
|||
module jannex/telegram-bot-manager
|
||||
|
||||
go 1.21.0
|
||||
|
||||
require (
|
||||
git.ex.umbach.dev/Alex/roese-utils v1.0.16
|
||||
github.com/gofiber/fiber/v2 v2.50.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/klauspost/compress v1.16.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/rs/zerolog v1.31.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.50.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
gorm.io/driver/mysql v1.5.2 // indirect
|
||||
gorm.io/gorm v1.25.5 // indirect
|
||||
)
|
|
@ -0,0 +1,49 @@
|
|||
git.ex.umbach.dev/Alex/roese-utils v1.0.16 h1:B9yVx5nL7FfUPJmqHDs58mq8MB2wSox1fK34EP3dqhc=
|
||||
git.ex.umbach.dev/Alex/roese-utils v1.0.16/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gofiber/fiber/v2 v2.50.0 h1:ia0JaB+uw3GpNSCR5nvC5dsaxXjRU5OEu36aytx+zGw=
|
||||
github.com/gofiber/fiber/v2 v2.50.0/go.mod h1:21eytvay9Is7S6z+OgPi7c7n4++tnClWmhpimVHMimw=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M=
|
||||
github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
|
||||
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
|
||||
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
|
||||
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
|
@ -0,0 +1,112 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jannex/telegram-bot-manager/modules/config"
|
||||
"jannex/telegram-bot-manager/modules/database"
|
||||
"jannex/telegram-bot-manager/modules/utils"
|
||||
"jannex/telegram-bot-manager/routers/router"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.ex.umbach.dev/Alex/roese-utils/rsconfig"
|
||||
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
|
||||
tblogger "jannex/telegram-bot-manager/modules/logger"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rsconfig.CreateEnvConfigFileIfNotExists(`DEBUG=false
|
||||
COLORIZED_OUTPUT=true
|
||||
HOST=127.0.0.1
|
||||
PORT=8080
|
||||
|
||||
LOG_MANAGER_SERVER_URL=http://localhost:50110
|
||||
|
||||
# MariaDB
|
||||
MARIADB_HOSTNAME=127.0.0.1
|
||||
MARIADB_PORT=3306
|
||||
MARIADB_USERNAME=db_user
|
||||
MARIADB_PASSWORD=db_password
|
||||
MARIADB_DATABASE_NAME=db_database_name`)
|
||||
|
||||
config.LoadConfig()
|
||||
rslogger.InitLogger(true, config.Cfg.ColorizedOutput, config.Cfg.LogManagerServerUrl)
|
||||
|
||||
if os.Getenv("DOCKER") != "" {
|
||||
fmt.Println("Waiting for mariadb docker")
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
|
||||
database.InitDatabase()
|
||||
utils.ValidatorInit()
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
app.Use(cors.New())
|
||||
|
||||
if config.Cfg.Debug {
|
||||
app.Use(logger.New(logger.Config{
|
||||
Format: "${pid} ${locals:requestid} ${status} - ${latency} ${method} ${path}\n",
|
||||
}))
|
||||
}
|
||||
|
||||
router.SetupRoutes(app)
|
||||
|
||||
tblogger.AddSystemLog(rslogger.LogTypeInfo, "Server started")
|
||||
|
||||
app.Listen(config.Cfg.Host + ":" + config.Cfg.Port)
|
||||
}
|
||||
|
||||
/*
|
||||
func main() {
|
||||
// Setze deinen Telegram Bot Token hier ein
|
||||
bot, err := tgbotapi.NewBotAPI("6450280279:AAGxXdPv_YwRtl_pXIqYojqOecBrEjn3fJo")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
bot.Debug = true
|
||||
|
||||
log.Printf("Angemeldet als %s", bot.Self.UserName)
|
||||
|
||||
// Erstelle eine Nachricht, die du senden möchtest
|
||||
msg := tgbotapi.NewMessage(935432572, "Das freut mich mein Hase. Ich liebe dich.")
|
||||
|
||||
// Sende die Nachricht
|
||||
_, err = bot.Send(msg)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
// Erstelle eine Update-Konfiguration, um auf eingehende Nachrichten zu reagieren
|
||||
updateConfig := tgbotapi.NewUpdate(0)
|
||||
updateConfig.Timeout = 60
|
||||
|
||||
updates, err := bot.GetUpdatesChan(updateConfig)
|
||||
|
||||
for update := range updates {
|
||||
if update.Message == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
chatID := update.Message.Chat.ID
|
||||
text := update.Message.Text
|
||||
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, text)
|
||||
|
||||
// Hier kannst du auf die empfangene Nachricht reagieren
|
||||
// Zum Beispiel, eine Antwort senden
|
||||
reply := tgbotapi.NewMessage(chatID, "Du hast folgende Nachricht gesendet: "+text)
|
||||
_, err := bot.Send(reply)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,52 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var Cfg Config
|
||||
|
||||
type Config struct {
|
||||
Debug bool
|
||||
ColorizedOutput bool
|
||||
Host string
|
||||
Port string
|
||||
LogManagerServerUrl string
|
||||
MariaDB MariaDB
|
||||
}
|
||||
|
||||
type MariaDB struct {
|
||||
Hostname string
|
||||
Port string
|
||||
Username string
|
||||
Password string
|
||||
DatabaseName string
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
// used to determine server was startet in docker or not
|
||||
if os.Getenv("DOCKER") == "" {
|
||||
fmt.Println("Load env from file")
|
||||
godotenv.Load(".env")
|
||||
} else {
|
||||
fmt.Println("Load env from system")
|
||||
}
|
||||
|
||||
Cfg = Config{
|
||||
Debug: os.Getenv("DEBUG") == "true",
|
||||
ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true",
|
||||
Host: os.Getenv("HOST"),
|
||||
Port: os.Getenv("PORT"),
|
||||
LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"),
|
||||
MariaDB: MariaDB{
|
||||
Hostname: os.Getenv("MARIADB_HOSTNAME"),
|
||||
Port: os.Getenv("MARIADB_PORT"),
|
||||
Username: os.Getenv("MARIADB_USERNAME"),
|
||||
Password: os.Getenv("MARIADB_PASSWORD"),
|
||||
DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"),
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jannex/telegram-bot-manager/modules/config"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
func InitDatabase() {
|
||||
cfg := config.Cfg
|
||||
|
||||
var logMode logger.LogLevel
|
||||
|
||||
if cfg.Debug {
|
||||
logMode = logger.Error
|
||||
} else {
|
||||
logMode = logger.Silent
|
||||
}
|
||||
|
||||
db, err := gorm.Open(mysql.Open(
|
||||
fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", cfg.MariaDB.Username, cfg.MariaDB.Password, cfg.MariaDB.Hostname, cfg.MariaDB.Port, cfg.MariaDB.DatabaseName)),
|
||||
&gorm.Config{
|
||||
Logger: logger.Default.LogMode(logMode),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DB = db
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func AddSystemLog(logType string, format string, v ...any) {
|
||||
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
|
||||
Type: "telegram-bot",
|
||||
Logs: []string{logType + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package utils
|
|
@ -0,0 +1,5 @@
|
|||
package utils
|
||||
|
||||
func ValidatorInit() {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package router
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func SetupRoutes(app *fiber.App) {
|
||||
//v1 := app.Group("/v1")
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
screen -dmS telegram-bot-manager | exit 0
|
||||
screen -S telegram-bot-manager -p 0 -X stuff 'go run main.go\n'
|
|
@ -0,0 +1,4 @@
|
|||
# installing swagger - version v0.30.5 - installed at 26.08.2023
|
||||
# go install github.com/go-swagger/go-swagger/cmd/swagger@latest
|
||||
|
||||
~/go/bin/swagger generate spec -o ./public/swagger/swagger.json --scan-models
|
Loading…
Reference in New Issue