mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
- Reworked embed builder
- Use IEmbedBuilderService to create embed builders - Wrapped embed builder and using IEmbedBuilder
This commit is contained in:
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user