initial
This commit is contained in:
commit
7c610d0477
11 changed files with 399 additions and 0 deletions
69
config/config.go
Normal file
69
config/config.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/disgoorg/snowflake/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppConf AppConfig
|
||||
TgConf TelegramConfig
|
||||
DsConf DiscordConfig
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
LogLvl string
|
||||
}
|
||||
|
||||
type TelegramConfig struct {
|
||||
Token string
|
||||
ChatID int64
|
||||
}
|
||||
|
||||
type DiscordConfig struct {
|
||||
Token string
|
||||
GuildID snowflake.ID
|
||||
ChannelID snowflake.ID
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
AppConfig{
|
||||
LogLvl: "info",
|
||||
},
|
||||
TelegramConfig{
|
||||
Token: getEnv("TELEGRAM_TOKEN", ""),
|
||||
ChatID: convertChatID(getEnv("TELEGRAM_CHANNEL_ID", "")),
|
||||
},
|
||||
DiscordConfig{
|
||||
Token: getEnv("DISCORD_TOKEN", ""),
|
||||
GuildID: convertID(getEnv("GUILD_ID", "")),
|
||||
ChannelID: convertID(getEnv("CHANNEL_ID", "")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func convertID(channelIDStr string) snowflake.ID {
|
||||
channelIDUint, err := strconv.ParseUint(channelIDStr, 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal("Cannot convert channel ID to snowflake ID")
|
||||
}
|
||||
return snowflake.ID(channelIDUint)
|
||||
}
|
||||
|
||||
func convertChatID(str string) int64 {
|
||||
id, err := strconv.ParseInt(str, 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal("Cannot convert string to int64")
|
||||
}
|
||||
return id
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue