- Reworked embed builder

- Use IEmbedBuilderService to create embed builders
- Wrapped embed builder and using IEmbedBuilder
This commit is contained in:
Kwoth
2021-07-09 22:23:19 +02:00
parent 5b4daa9dd3
commit 5e4754fa40
103 changed files with 730 additions and 540 deletions

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithDescription(novelData.Description.Replace("<br>", Environment.NewLine, StringComparison.InvariantCulture))
.WithTitle(novelData.Title)
@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Searches
.Select(x => x.TextContent.Split(':').Select(y => y.Trim()).ToArray())
.ToArray();
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle(GetText("mal_profile", name))
.AddField("💚 " + GetText("watching"), stats[0], true)
@@ -150,7 +150,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithDescription(animeData.Synopsis.Replace("<br>", Environment.NewLine, StringComparison.InvariantCulture))
.WithTitle(animeData.TitleEnglish)
@@ -178,7 +178,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithDescription(mangaData.Synopsis.Replace("<br>", Environment.NewLine, StringComparison.InvariantCulture))
.WithTitle(mangaData.TitleEnglish)

View File

@@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Searches
if (nearest != null)
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("crypto_not_found"))
.WithDescription(GetText("did_you_mean", Format.Bold($"{nearest.Name} ({nearest.Symbol})")));
@@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Searches
? ld.ToString("F2")
: crypto.Quote.Usd.Percent_Change_24h;
await ctx.Channel.EmbedAsync(new EmbedBuilder()
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle($"{crypto.Name} ({crypto.Symbol})")
.WithUrl($"https://coinmarketcap.com/currencies/{crypto.Slug}/")

View File

@@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Searches
if (!feeds.Any())
{
await ctx.Channel.EmbedAsync(new EmbedBuilder()
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithDescription(GetText("feed_no_feed")))
.ConfigureAwait(false);
@@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Searches
await ctx.SendPaginatedConfirmAsync(0, (cur) =>
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor();
var i = 0;
var fs = string.Join("\n", feeds.Skip(cur * 10)

View File

@@ -17,20 +17,20 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Aliases]
public async Task Yomama()
{
await ctx.Channel.SendConfirmAsync(await _service.GetYomamaJoke().ConfigureAwait(false)).ConfigureAwait(false);
await SendConfirmAsync(await _service.GetYomamaJoke().ConfigureAwait(false)).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
public async Task Randjoke()
{
var (setup, punchline) = await _service.GetRandomJoke().ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync(setup, punchline).ConfigureAwait(false);
await SendConfirmAsync(setup, punchline).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
public async Task ChuckNorris()
{
await ctx.Channel.SendConfirmAsync(await _service.GetChuckNorrisJoke().ConfigureAwait(false)).ConfigureAwait(false);
await SendConfirmAsync(await _service.GetChuckNorrisJoke().ConfigureAwait(false)).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var joke = _service.WowJokes[new NadekoRandom().Next(0, _service.WowJokes.Count)];
await ctx.Channel.SendConfirmAsync(joke.Question, joke.Answer).ConfigureAwait(false);
await SendConfirmAsync(joke.Question, joke.Answer).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Searches
}
var item = _service.MagicItems[new NadekoRandom().Next(0, _service.MagicItems.Count)];
await ctx.Channel.SendConfirmAsync("✨" + item.Name, item.Description).ConfigureAwait(false);
await SendConfirmAsync("✨" + item.Name, item.Description).ConfigureAwait(false);
}
}
}

View File

@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Searches
{
templates += $"**{template.Name}:**\n key: `{template.Id}`\n";
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithDescription(templates);

View File

@@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Searches
var obj = objs[0];
var userId = obj.UserId;
await ctx.Channel.EmbedAsync(new EmbedBuilder()
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle($"osu! {smode} profile for {user}")
.WithThumbnailUrl($"https://a.ppy.sh/{userId}")
@@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Searches
var userData = JsonConvert.DeserializeObject<GatariUserResponse>(usrResString).Users[0];
var userStats = statsResponse.Stats;
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle($"osu!Gatari {modeStr} profile for {user}")
.WithThumbnailUrl($"https://a.gatari.pw/{userStats.Id}")
@@ -134,17 +134,16 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Aliases]
public async Task Osu5(string user, [Leftover] string mode = null)
{
var channel = (ITextChannel) ctx.Channel;
{;
if (string.IsNullOrWhiteSpace(_creds.OsuApiKey))
{
await channel.SendErrorAsync("An osu! API key is required.").ConfigureAwait(false);
await SendErrorAsync("An osu! API key is required.").ConfigureAwait(false);
return;
}
if (string.IsNullOrWhiteSpace(user))
{
await channel.SendErrorAsync("Please provide a username.").ConfigureAwait(false);
await SendErrorAsync("Please provide a username.").ConfigureAwait(false);
return;
}
@@ -192,17 +191,17 @@ namespace NadekoBot.Modules.Searches
return (title, desc);
});
var eb = new EmbedBuilder()
var eb = _eb.Create()
.WithOkColor()
.WithTitle($"Top 5 plays for {user}");
var mapData = await Task.WhenAll(mapTasks);
foreach (var (title, desc) in mapData.Where(x => x != default))
{
eb.AddField(title, desc, inline: false);
eb.AddField(title, desc, false);
}
await channel.EmbedAsync(eb).ConfigureAwait(false);
await ctx.Channel.EmbedAsync(eb).ConfigureAwait(false);
}
}

View File

@@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(usr))
{
await ctx.Channel.SendErrorAsync("Please provide an account name.").ConfigureAwait(false);
await SendErrorAsync("Please provide an account name.").ConfigureAwait(false);
return;
}
@@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Searches
}
catch
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithDescription(GetText("account_not_found"))
.WithErrorColor();
@@ -74,7 +74,7 @@ namespace NadekoBot.Modules.Searches
await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithAuthor($"Characters on {usr}'s account",
"https://web.poecdn.com/image/favicon/ogimage.png",
$"{_profileURL}{usr}")
@@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Searches
}
catch
{
var eembed = new EmbedBuilder()
var eembed = _eb.Create()
.WithDescription(GetText("leagues_not_found"))
.WithErrorColor();
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithAuthor($"Path of Exile Leagues",
"https://web.poecdn.com/image/favicon/ogimage.png",
"https://www.pathofexile.com")
@@ -154,12 +154,12 @@ namespace NadekoBot.Modules.Searches
{
if (string.IsNullOrWhiteSpace(leagueName))
{
await ctx.Channel.SendErrorAsync("Please provide league name.").ConfigureAwait(false);
await SendErrorAsync("Please provide league name.").ConfigureAwait(false);
return;
}
if (string.IsNullOrWhiteSpace(currencyName))
{
await ctx.Channel.SendErrorAsync("Please provide currency name.").ConfigureAwait(false);
await SendErrorAsync("Please provide currency name.").ConfigureAwait(false);
return;
}
@@ -201,7 +201,7 @@ namespace NadekoBot.Modules.Searches
conversionEquivalent = float.Parse(currencyOutput["chaosEquivalent"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithAuthor($"{leagueName} Currency Exchange",
"https://web.poecdn.com/image/favicon/ogimage.png",
"http://poe.ninja")
@@ -214,7 +214,7 @@ namespace NadekoBot.Modules.Searches
}
catch
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithDescription(GetText("ninja_not_found"))
.WithErrorColor();

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Aliases]
public async Task Placelist()
{
await ctx.Channel.SendConfirmAsync(GetText("list_of_place_tags", Prefix),
await SendConfirmAsync(GetText("list_of_place_tags", Prefix),
_typesStr)
.ConfigureAwait(false);
}

View File

@@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Searches
if (kvp.Key.ToUpperInvariant() == pokemon.ToUpperInvariant())
{
var p = kvp.Value;
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(kvp.Key.ToTitleCase())
.WithDescription(p.BaseStats.ToString())
.WithThumbnailUrl($"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/{p.Id.ToString("000")}.png")
@@ -62,7 +62,7 @@ namespace NadekoBot.Modules.Searches
{
if (kvp.Key.ToUpperInvariant() == ability)
{
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(kvp.Value.Name)
.WithDescription(string.IsNullOrWhiteSpace(kvp.Value.Desc)
? kvp.Value.ShortDesc

View File

@@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Searches
if (!await ValidateQuery(ctx.Channel, query).ConfigureAwait(false))
return;
var embed = new EmbedBuilder();
var embed = _eb.Create();
var data = await _service.GetWeatherDataAsync(query).ConfigureAwait(false);
if (data is null)
@@ -140,12 +140,12 @@ namespace NadekoBot.Modules.Searches
return;
}
var eb = new EmbedBuilder()
var eb = _eb.Create()
.WithOkColor()
.WithTitle(GetText("time_new"))
.WithDescription(Format.Code(data.Time.ToString()))
.AddField(GetText("location"), string.Join('\n', data.Address.Split(", ")), inline: true)
.AddField(GetText("timezone"), data.TimeZoneName, inline: true);
.AddField(GetText("location"), string.Join('\n', data.Address.Split(", ")), true)
.AddField(GetText("timezone"), data.TimeZoneName, true);
await ctx.Channel.SendMessageAsync(embed: eb.Build()).ConfigureAwait(false);
}
@@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Searches
await ReplyErrorLocalizedAsync("imdb_fail").ConfigureAwait(false);
return;
}
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(movie.Title)
.WithUrl($"http://www.imdb.com/title/{movie.ImdbId}/")
.WithDescription(movie.Plot.TrimTo(1000))
@@ -205,7 +205,7 @@ namespace NadekoBot.Modules.Searches
private Task InternalRandomImage(SearchesService.ImageTag tag)
{
var url = _service.GetRandomImageUrl(tag);
return ctx.Channel.EmbedAsync(new EmbedBuilder()
return ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithImageUrl(url));
}
@@ -220,7 +220,7 @@ namespace NadekoBot.Modules.Searches
try
{
var res = await _google.GetImageAsync(oterms).ConfigureAwait(false);
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithAuthor(GetText("image_search_for") + " " + oterms.TrimTo(50),
"http://i.imgur.com/G46fm8J.png",
@@ -250,7 +250,7 @@ namespace NadekoBot.Modules.Searches
var source = img.Source.Replace("b.", ".", StringComparison.InvariantCulture);
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithAuthor(GetText("image_search_for") + " " + oterms.TrimTo(50),
"http://s.imgur.com/images/logo-1200-630.jpg?",
@@ -269,8 +269,8 @@ namespace NadekoBot.Modules.Searches
if (!await ValidateQuery(ctx.Channel, ffs).ConfigureAwait(false))
return;
await ctx.Channel.SendConfirmAsync("<" + await _google.ShortenUrl($"http://lmgtfy.com/?q={ Uri.EscapeUriString(ffs) }").ConfigureAwait(false) + ">")
.ConfigureAwait(false);
var shortenedUrl = await _google.ShortenUrl($"http://lmgtfy.com/?q={Uri.EscapeUriString(ffs)}");
await SendConfirmAsync($"<{shortenedUrl}>");
}
public class ShortenData
@@ -322,8 +322,8 @@ namespace NadekoBot.Modules.Searches
}
}
await ctx.Channel.EmbedAsync(new EmbedBuilder()
.WithColor(Bot.OkColor)
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.AddField(GetText("original_url"), $"<{query}>")
.AddField(GetText("short_url"), $"<{shortLink}>"));
}
@@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Searches
var descStr = string.Join("\n\n", desc);
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithAuthor(ctx.User.ToString(),
iconUrl: "http://i.imgur.com/G46fm8J.png")
.WithTitle(ctx.User.ToString())
@@ -383,7 +383,7 @@ namespace NadekoBot.Modules.Searches
var descStr = string.Join("\n\n", desc);
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithAuthor(ctx.User.ToString(),
iconUrl: "https://upload.wikimedia.org/wikipedia/en/9/90/The_DuckDuckGo_Duck.png")
.WithDescription($"{GetText("search_for")} **{query}**\n\n" + descStr)
@@ -407,7 +407,7 @@ namespace NadekoBot.Modules.Searches
return;
}
var embed = new EmbedBuilder().WithOkColor()
var embed = _eb.Create().WithOkColor()
.WithTitle(card.Name)
.WithDescription(card.Description)
.WithImageUrl(card.ImageUrl)
@@ -439,7 +439,7 @@ namespace NadekoBot.Modules.Searches
await ReplyErrorLocalizedAsync("card_not_found").ConfigureAwait(false);
return;
}
var embed = new EmbedBuilder().WithOkColor()
var embed = _eb.Create().WithOkColor()
.WithImageUrl(card.Img);
if (!string.IsNullOrWhiteSpace(card.Flavor))
@@ -467,7 +467,7 @@ namespace NadekoBot.Modules.Searches
await ctx.SendPaginatedConfirmAsync(0, (p) =>
{
var item = items[p];
return new EmbedBuilder().WithOkColor()
return _eb.Create().WithOkColor()
.WithUrl(item.Permalink)
.WithAuthor(item.Word)
.WithDescription(item.Definition);
@@ -529,10 +529,10 @@ namespace NadekoBot.Modules.Searches
await ctx.SendPaginatedConfirmAsync(0, page =>
{
var data = col.Skip(page).First();
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithDescription(ctx.User.Mention)
.AddField(GetText("word"), data.Word, inline: true)
.AddField(GetText("class"), data.WordType, inline: true)
.AddField(GetText("word"), data.Word, true)
.AddField(GetText("class"), data.WordType, true)
.AddField(GetText("definition"), data.Definition)
.WithOkColor();
@@ -559,7 +559,7 @@ namespace NadekoBot.Modules.Searches
return;
var fact = JObject.Parse(response)["fact"].ToString();
await ctx.Channel.SendConfirmAsync("🐈" + GetText("catfact"), fact).ConfigureAwait(false);
await SendConfirmAsync("🐈" + GetText("catfact"), fact).ConfigureAwait(false);
}
}
@@ -575,7 +575,7 @@ namespace NadekoBot.Modules.Searches
if (av is null)
return;
await ctx.Channel.SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={av}").ConfigureAwait(false);
await SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={av}").ConfigureAwait(false);
}
//done in 3.0
@@ -586,12 +586,12 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(imageLink))
return;
await ctx.Channel.SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
await SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={imageLink}").ConfigureAwait(false);
}
[NadekoCommand, Aliases]
public Task Safebooru([Leftover] string tag = null)
=> InternalDapiCommand(ctx.Message, tag, DapiSearchType.Safebooru);
=> InternalDapiCommand(tag, DapiSearchType.Safebooru);
[NadekoCommand, Aliases]
public async Task Wiki([Leftover] string query = null)
@@ -655,7 +655,7 @@ namespace NadekoBot.Modules.Searches
return;
}
await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.AddField("Username", usr.ToString(), false)
.AddField("Avatar Url", avatarUrl, false)
.WithThumbnailUrl(avatarUrl.ToString()), ctx.User.Mention).ConfigureAwait(false);
@@ -721,11 +721,11 @@ namespace NadekoBot.Modules.Searches
{
}
if (obj.Error != null || obj.Verses is null || obj.Verses.Length == 0)
await ctx.Channel.SendErrorAsync(obj.Error ?? "No verse found.").ConfigureAwait(false);
await SendErrorAsync(obj.Error ?? "No verse found.").ConfigureAwait(false);
else
{
var v = obj.Verses[0];
await ctx.Channel.EmbedAsync(new EmbedBuilder()
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle($"{v.BookName} {v.Chapter}:{v.Verse}")
.WithDescription(v.Text)).ConfigureAwait(false);
@@ -747,7 +747,7 @@ namespace NadekoBot.Modules.Searches
return;
}
//var embed = new EmbedBuilder()
//var embed = _eb.Create()
// .WithOkColor()
// .WithDescription(gameData.ShortDescription)
// .WithTitle(gameData.Name)
@@ -760,19 +760,17 @@ namespace NadekoBot.Modules.Searches
await ctx.Channel.SendMessageAsync($"https://store.steampowered.com/app/{appId}").ConfigureAwait(false);
}
public async Task InternalDapiCommand(IUserMessage umsg, string tag, DapiSearchType type)
public async Task InternalDapiCommand(string tag, DapiSearchType type)
{
var channel = umsg.Channel;
tag = tag?.Trim() ?? "";
var imgObj = await _service.DapiSearch(tag, type, ctx.Guild?.Id).ConfigureAwait(false);
if (imgObj is null)
await channel.SendErrorAsync(umsg.Author.Mention + " " + GetText("no_results")).ConfigureAwait(false);
await SendErrorAsync(ctx.User.Mention + " " + GetText("no_results")).ConfigureAwait(false);
else
await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription($"{umsg.Author.Mention} [{tag ?? "url"}]({imgObj.FileUrl})")
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithDescription($"{ctx.User.Mention} [{tag ?? "url"}]({imgObj.FileUrl})")
.WithImageUrl(imgObj.FileUrl)
.WithFooter(type.ToString())).ConfigureAwait(false);
}

View File

@@ -20,11 +20,12 @@ namespace NadekoBot.Modules.Searches.Services
private readonly DbService _db;
private readonly ConcurrentDictionary<string, HashSet<FeedSub>> _subs;
private readonly DiscordSocketClient _client;
private readonly IEmbedBuilderService _eb;
private readonly ConcurrentDictionary<string, DateTime> _lastPosts =
new ConcurrentDictionary<string, DateTime>();
public FeedsService(Bot bot, DbService db, DiscordSocketClient client)
public FeedsService(Bot bot, DbService db, DiscordSocketClient client, IEmbedBuilderService eb)
{
_db = db;
@@ -44,6 +45,7 @@ namespace NadekoBot.Modules.Searches.Services
}
_client = client;
_eb = eb;
var _ = Task.Run(TrackFeeds);
}
@@ -87,7 +89,7 @@ namespace NadekoBot.Modules.Searches.Services
continue;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithFooter(rssUrl);
_lastPosts[kvp.Key] = itemUpdateDate;

View File

@@ -41,6 +41,7 @@ namespace NadekoBot.Modules.Searches.Services
private readonly IDataCache _cache;
private readonly FontProvider _fonts;
private readonly IBotCredentials _creds;
private readonly IEmbedBuilderService _eb;
private readonly NadekoRandom _rng;
public ConcurrentDictionary<ulong, bool> TranslatedChannels { get; } = new ConcurrentDictionary<ulong, bool>();
@@ -61,7 +62,7 @@ namespace NadekoBot.Modules.Searches.Services
public SearchesService(DiscordSocketClient client, IGoogleApiService google,
DbService db, Bot bot, IDataCache cache, IHttpClientFactory factory,
FontProvider fonts, IBotCredentials creds)
FontProvider fonts, IBotCredentials creds, IEmbedBuilderService eb)
{
_httpFactory = factory;
_client = client;
@@ -71,6 +72,7 @@ namespace NadekoBot.Modules.Searches.Services
_cache = cache;
_fonts = fonts;
_creds = creds;
_eb = eb;
_rng = new NadekoRandom();
_blacklistedTags = new ConcurrentDictionary<ulong, HashSet<string>>(
@@ -100,7 +102,8 @@ namespace NadekoBot.Modules.Searches.Services
.ConfigureAwait(false);
if (autoDelete)
try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { }
await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` "
await umsg.Channel.SendConfirmAsync(_eb, $"{umsg.Author.Mention} `:` "
+ text.Replace("<@ ", "<@", StringComparison.InvariantCulture)
.Replace("<@! ", "<@!", StringComparison.InvariantCulture)).ConfigureAwait(false);
}

View File

@@ -40,6 +40,7 @@ namespace NadekoBot.Modules.Searches.Services
private readonly IBotCredentials _creds;
private readonly IPubSub _pubSub;
private readonly IEmbedBuilderService _eb;
private readonly Timer _notifCleanupTimer;
private readonly TypedKey<List<StreamData>> _streamsOnlineKey;
@@ -56,13 +57,15 @@ namespace NadekoBot.Modules.Searches.Services
IBotCredentials creds,
IHttpClientFactory httpFactory,
Bot bot,
IPubSub pubSub)
IPubSub pubSub,
IEmbedBuilderService eb)
{
_db = db;
_client = client;
_strings = strings;
_creds = creds;
_pubSub = pubSub;
_eb = eb;
_streamTracker = new NotifChecker(httpFactory, redis, creds.RedisKey(), client.ShardId == 0);
_streamsOnlineKey = new("streams.online");
@@ -438,16 +441,20 @@ namespace NadekoBot.Modules.Searches.Services
return data;
}
public EmbedBuilder GetEmbed(ulong guildId, StreamData status)
public IEmbedBuilder GetEmbed(ulong guildId, StreamData status)
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(status.Name)
.WithUrl(status.StreamUrl)
.WithDescription(status.StreamUrl)
.AddField(GetText(guildId, "status"), status.IsLive ? "🟢 Online" : "🔴 Offline", true)
.AddField(GetText(guildId, "viewers"), status.IsLive ? status.Viewers.ToString() : "-", true)
.WithColor(status.IsLive ? Bot.OkColor : Bot.ErrorColor);
.AddField(GetText(guildId, "viewers"), status.IsLive ? status.Viewers.ToString() : "-", true);
if (status.IsLive)
embed = embed.WithOkColor();
else
embed = embed.WithErrorColor();
if (!string.IsNullOrWhiteSpace(status.Title))
embed.WithAuthor(status.Title);

View File

@@ -117,12 +117,12 @@ namespace NadekoBot.Modules.Searches
if (elements.Count == 0)
{
return new EmbedBuilder()
return _eb.Create()
.WithDescription(GetText("streams_none"))
.WithErrorColor();
}
var eb = new EmbedBuilder()
var eb = _eb.Create()
.WithTitle(GetText("streams_follow_title"))
.WithOkColor();
for (var index = 0; index < elements.Count; index++)

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches
{
await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false);
var translation = await _searches.Translate(langs, text).ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync(GetText("translation") + " " + langs, translation).ConfigureAwait(false);
await SendConfirmAsync(GetText("translation") + " " + langs, translation).ConfigureAwait(false);
}
catch
{
@@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Searches
// foreach (var item in _google.Languages.Except(new[] { "en" }).Where(x => x.Length < 4))
// {
// var txt2 = await _searches.Translate(lastItem + ">" + item, txt);
// await ctx.Channel.EmbedAsync(new EmbedBuilder()
// await ctx.Channel.EmbedAsync(_eb.Create()
// .WithOkColor()
// .WithTitle(lastItem + ">" + item)
// .AddField("Input", txt)
@@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Searches
// lastItem = item;
// }
// txt = await _searches.Translate(lastItem + ">en", txt);
// await ctx.Channel.SendConfirmAsync("Final output:\n\n" + txt);
// await SendConfirmAsync("Final output:\n\n" + txt);
//}
public enum AutoDeleteAutoTranslate

View File

@@ -34,11 +34,11 @@ namespace NadekoBot.Modules.Searches
{
var res = await http.GetStringAsync($"{_xkcdUrl}/info.0.json").ConfigureAwait(false);
var comic = JsonConvert.DeserializeObject<XkcdComic>(res);
var embed = new EmbedBuilder().WithColor(Bot.OkColor)
.WithImageUrl(comic.ImageLink)
.WithAuthor(comic.Title,"https://xkcd.com/s/919f27.ico", $"{_xkcdUrl}/{comic.Num}")
.AddField(GetText("comic_number"), comic.Num.ToString(), true)
.AddField(GetText("date"), $"{comic.Month}/{comic.Year}", true);
var embed = _eb.Create().WithOkColor()
.WithImageUrl(comic.ImageLink)
.WithAuthor(comic.Title, "https://xkcd.com/s/919f27.ico", $"{_xkcdUrl}/{comic.Num}")
.AddField(GetText("comic_number"), comic.Num.ToString(), true)
.AddField(GetText("date"), $"{comic.Month}/{comic.Year}", true);
var sent = await ctx.Channel.EmbedAsync(embed)
.ConfigureAwait(false);
@@ -69,8 +69,8 @@ namespace NadekoBot.Modules.Searches
var res = await http.GetStringAsync($"{_xkcdUrl}/{num}/info.0.json").ConfigureAwait(false);
var comic = JsonConvert.DeserializeObject<XkcdComic>(res);
var embed = new EmbedBuilder()
.WithColor(Bot.OkColor)
var embed = _eb.Create()
.WithOkColor()
.WithImageUrl(comic.ImageLink)
.WithAuthor(comic.Title, "https://xkcd.com/s/919f27.ico", $"{_xkcdUrl}/{num}")
.AddField(GetText("comic_number"), comic.Num.ToString(), true)