-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8ade12
commit c462fa8
Showing
11 changed files
with
180 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env | ||
vendor | ||
vendor | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
|
||
# The lines below are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/need to use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
||
version: 2 | ||
|
||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
archives: | ||
- files: | ||
- none* | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/joho/godotenv" | ||
"os" | ||
"sync" | ||
"tg_translate_bots/internal/tgbot" | ||
"tg_translate_bots/internal/translator" | ||
"tg_translate_bots/internal/translator/client" | ||
) | ||
|
||
func main() { | ||
_ = godotenv.Load(".env") | ||
|
||
var botsPtr *[]*tgbot.TgBot | ||
botsDiscoverFunc := func() map[string]string { | ||
botsMap := make(map[string]string) | ||
for _, bot := range *botsPtr { | ||
botsMap[bot.Name] = bot.Link | ||
} | ||
return botsMap | ||
} | ||
|
||
var bots = []*tgbot.TgBot{ | ||
tgbot.New( | ||
"En-Ru", | ||
"tg://resolve?domain=@EnToRuTranslatorBot", | ||
os.Getenv("EN_TO_RU_TG_BOT_TOKEN"), | ||
"Hello. I translate all messages from English to Russian.", | ||
"An error occurred while translating the message.", | ||
translator.New( | ||
"EN", | ||
"RU", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
tgbot.New( | ||
"En-Ua", | ||
"tg://resolve?domain=@EnToUaTranslatorBot", | ||
os.Getenv("EN_TO_UA_TG_BOT_TOKEN"), | ||
"Hello. I translate all messages from English to Ukrainian.", | ||
"An error occurred while translating the message.", | ||
translator.New( | ||
"EN", | ||
"UK", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
tgbot.New( | ||
"Ru-En", | ||
"tg://resolve?domain=@RuToEnTranslatorBot", | ||
os.Getenv("RU_TO_EN_TG_BOT_TOKEN"), | ||
"Привет. Я перевожу все сообщения с русского на английский язык.", | ||
"Произошла ошибка при переводе сообщения.", | ||
translator.New( | ||
"RU", | ||
"EN", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
tgbot.New( | ||
"Ru-Ua", | ||
"tg://resolve?domain=@RuToUaTranslatorBot", | ||
os.Getenv("RU_TO_UA_TG_BOT_TOKEN"), | ||
"Привет. Я перевожу все сообщения с русского на украинский язык.", | ||
"Произошла ошибка при переводе сообщения.", | ||
translator.New( | ||
"RU", | ||
"UK", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
tgbot.New( | ||
"Ua-En", | ||
"tg://resolve?domain=@UaToEnTranslatorBot", | ||
os.Getenv("UA_TO_EN_TG_BOT_TOKEN"), | ||
"Привіт. Я перекладаю всі повідомлення з української на англійську мову.", | ||
"Сталася помилка під час перекладу повідомлення.", | ||
translator.New( | ||
"UK", | ||
"EN", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
tgbot.New( | ||
"Ua-Ru", | ||
"tg://resolve?domain=@UaToRuTranslatorBot", | ||
os.Getenv("UA_TO_RU_TG_BOT_TOKEN"), | ||
"Привіт. Я перекладаю всі повідомлення з української на російську мову.", | ||
"Сталася помилка під час перекладу повідомлення.", | ||
translator.New( | ||
"UK", | ||
"RU", | ||
&client.DeeplClient{}, | ||
), | ||
botsDiscoverFunc, | ||
), | ||
} | ||
|
||
botsPtr = &bots | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(len(bots)) | ||
|
||
for _, bot := range bots { | ||
go func(bot *tgbot.TgBot) { | ||
defer wg.Done() | ||
bot.PollTgApiAndRespond() | ||
}(bot) | ||
} | ||
|
||
wg.Wait() | ||
} |