66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
log "github.com/sirupsen/logrus"
|
||
|
|
"os"
|
||
|
|
"os/signal"
|
||
|
|
"syscall"
|
||
|
|
"tg-disc-bot/config"
|
||
|
|
"tg-disc-bot/discordBot"
|
||
|
|
"tg-disc-bot/dto"
|
||
|
|
"tg-disc-bot/tgBot"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
c := config.NewConfig()
|
||
|
|
config.LogSetup(c.AppConf.LogLvl)
|
||
|
|
|
||
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
shutdown := make(chan os.Signal, 1)
|
||
|
|
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
|
||
|
|
|
||
|
|
tgb, err := tgBot.NewTgBot(ctx, c.TgConf)
|
||
|
|
if err != nil {
|
||
|
|
log.Fatal(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
dsb, err := discordBot.NewDiscordBot(ctx, c.DsConf)
|
||
|
|
if err != nil {
|
||
|
|
log.Fatal(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
fromDiscord := make(chan dto.DiscordDTO, 100)
|
||
|
|
fromTelegram := make(chan dto.TelegramDTO, 100)
|
||
|
|
|
||
|
|
tgMsgs := tgb.Start(fromDiscord)
|
||
|
|
dsMsgs := dsb.Start(fromTelegram)
|
||
|
|
|
||
|
|
log.Info("App is now running. Press CTRL-C to exit.")
|
||
|
|
|
||
|
|
for {
|
||
|
|
select {
|
||
|
|
case sig := <-shutdown:
|
||
|
|
{
|
||
|
|
log.WithField("type", sig).Info("terminating, close app")
|
||
|
|
os.Exit(0)
|
||
|
|
}
|
||
|
|
case <-ctx.Done():
|
||
|
|
{
|
||
|
|
log.Info("terminating, close app")
|
||
|
|
os.Exit(0)
|
||
|
|
}
|
||
|
|
case tgMsg := <-tgMsgs:
|
||
|
|
{
|
||
|
|
fromTelegram <- tgMsg
|
||
|
|
}
|
||
|
|
case dsMsg := <-dsMsgs:
|
||
|
|
{
|
||
|
|
fromDiscord <- dsMsg
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|