format change

This commit is contained in:
nquidox 2026-03-05 16:20:28 +03:00
parent fd7868128a
commit 5f72059bb6
2 changed files with 23 additions and 8 deletions

View file

@ -65,7 +65,7 @@ func (d *DiscordBot) Start(fromTelegram <-chan dto.TelegramDTO) chan dto.Discord
files = append(files, file)
}
m := discord.MessageCreate{Content: fmt.Sprintf("[%s]\n%s", msg.AuthorName, msg.Content)}
m := discord.MessageCreate{Content: fmt.Sprintf("**[%s]**\n%s", msg.AuthorName, msg.Content)}
if len(files) > 0 {
m.Files = append(m.Files, files...)

View file

@ -57,19 +57,21 @@ func (b *TgBot) Start(fromDiscord chan dto.DiscordDTO) chan dto.TelegramDTO {
go func() {
for msg := range fromDiscord {
log.WithField("content", msg).Debug("TG | Message from Discord")
m := fmt.Sprintf("[%s]\n%s", msg.AuthorName, msg.Content)
m := fmt.Sprintf("*\\[ %s \\]*\n%s", msg.AuthorName, msg.Content)
b.bot.SendMessage(b.ctx, &bot.SendMessageParams{
ChatID: b.chatID,
Text: m,
ChatID: b.chatID,
Text: m,
ParseMode: "",
})
if msg.Images != nil {
var mediaGroup []models.InputMedia
for _, img := range *msg.Images {
photo := &models.InputMediaPhoto{
Media: fmt.Sprintf("attach://%s", img.Filename),
Caption: "test caption",
Media: fmt.Sprintf("attach://%s", img.Filename),
//Caption: "test caption",
MediaAttachment: bytes.NewReader(img.Data),
}
mediaGroup = append(mediaGroup, photo)
@ -146,7 +148,7 @@ func (b *TgBot) proccessSimple(update *models.Update, msgChan chan<- dto.Telegra
}
msg := dto.TelegramDTO{
AuthorName: update.Message.From.Username,
AuthorName: b.getName(update),
Content: content,
Images: &images,
}
@ -185,7 +187,7 @@ func (b *TgBot) processMediaGroup(update *models.Update, mediaGroupID string, ms
delete(b.mediaGroupCache, mediaGroupID)
msg := dto.TelegramDTO{
AuthorName: update.Message.From.Username,
AuthorName: b.getName(update),
Content: content,
Images: &images,
}
@ -193,3 +195,16 @@ func (b *TgBot) processMediaGroup(update *models.Update, mediaGroupID string, ms
msgChan <- msg
}()
}
func (b *TgBot) getName(update *models.Update) string {
switch {
case update.Message.From.Username != "":
return update.Message.From.Username
case update.Message.From.FirstName != "":
return update.Message.From.FirstName
case update.Message.From.LastName != "":
return update.Message.From.LastName
default:
return "No name"
}
}