initial
This commit is contained in:
commit
7c610d0477
11 changed files with 399 additions and 0 deletions
65
main.go
Normal file
65
main.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue