private async Task <Translation?> SendMessageToPartner(SocketMessage message, string username, ITextChannel targetChannel, string from, string to, Translation.TranslationType type) { var guildLang = _serverConfig.GetLanguageForGuild(targetChannel.Guild.Id); var safeGuildLang = GetSafeLangString(guildLang); var isStandardLang = targetChannel.IsStandardLangChannel(safeGuildLang); _logger.LogDebug($"Message received from {from} channel '{message.Channel.Name}', sending to {targetChannel.Name}"); Translation?translation = null; if (!string.IsNullOrEmpty(message.Content)) { translation = await _translation.GetTranslation(from, to, message.Content); translation.Type = type; } var translatedText = translation?.Translated.Text; if (message.Attachments.Count > 0) { translatedText += $"{(string.IsNullOrEmpty(translatedText) ? string.Empty : Environment.NewLine)}{message.Attachments.First().Url}"; } foreach (var chunk in $"{Format.Bold(username)}: {translatedText}".ChunkUpTo(2000)) { await targetChannel.SendMessageAsync(chunk); } return(translation); }
private async Task <Translation?> SendMessageToPartner(SocketMessage message, string username, ITextChannel targetChannel, string from, string to, Translation.TranslationType type) { var guildLang = _serverConfig.GetLanguageForGuild(targetChannel.Guild.Id); var safeGuildLang = GetSafeLangString(guildLang); var isStandardLang = targetChannel.IsStandardLangChannel(safeGuildLang); _logger.LogDebug($"Message received from {from} channel '{message.Channel.Name}', sending to {targetChannel.Name}"); if (string.IsNullOrEmpty(message.Content)) { return(null); } var translation = await _translation.GetTranslation(from, to, message.Content); translation.Type = type; await targetChannel.SendMessageAsync($"{Format.Bold(username)}: {translation}"); return(translation); }
private async Task <string> SendMessageToPartner(SocketMessage message, string username, ITextChannel targetChannel, string from, string to) { var guildLang = _serverConfig.GetLanguageForGuild(targetChannel.Guild.Id); var safeGuildLang = GetSafeLangString(guildLang); var isStandardLang = targetChannel.IsStandardLangChannel(safeGuildLang); _logger.LogDebug($"Message received from {from} channel '{message.Channel.Name}', sending to {targetChannel.Name}"); string relayText = string.Empty; if (!string.IsNullOrWhiteSpace(message.Content)) { relayText = await _translation.GetTranslation(from, to, message.Content); } if (message.Attachments.Count != 0) { relayText += $" {string.Join(" ", message.Attachments.Select(a => a.Url))}"; } await targetChannel.SendMessageAsync($"{Format.Bold(username)}: {relayText}"); return(relayText); }