part 3 of the response rework

This commit is contained in:
Kwoth
2024-04-29 21:03:40 +00:00
parent d28c7b500d
commit daa2177559
65 changed files with 508 additions and 625 deletions

View File

@@ -6,7 +6,6 @@ using System.Text.Json;
namespace NadekoBot.Modules.Searches;
// todo fix stock
public sealed class DefaultStockDataService : IStockDataService, INService
{
private readonly IHttpClientFactory _httpClientFactory;

View File

@@ -14,7 +14,7 @@ public class FeedsService : INService
private readonly DbService _db;
private readonly ConcurrentDictionary<string, List<FeedSub>> _subs;
private readonly DiscordSocketClient _client;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
private readonly ConcurrentDictionary<string, DateTime> _lastPosts = new();
private readonly Dictionary<string, uint> _errorCounters = new();
@@ -23,7 +23,7 @@ public class FeedsService : INService
IBot bot,
DbService db,
DiscordSocketClient client,
IEmbedBuilderService eb)
IMessageSenderService sender)
{
_db = db;
@@ -42,7 +42,7 @@ public class FeedsService : INService
}
_client = client;
_eb = eb;
_sender = sender;
_ = Task.Run(TrackFeeds);
}

View File

@@ -69,7 +69,7 @@ public partial class Searches
}
memeUrl += ".png";
await ctx.Channel.SendMessageAsync(memeUrl);
await Response().Text(memeUrl).SendAsync();
}
private static string Replace(string input)

View File

@@ -165,7 +165,7 @@ public partial class Searches
}
await AddYoutubeUrlToCacheAsync(query, result.Url);
await ctx.Channel.SendMessageAsync(result.Url);
await Response().Text(result.Url).SendAsync();
}
// [Cmd]

View File

@@ -141,7 +141,7 @@ public partial class Searches : NadekoModule<SearchesService>
.AddField(GetText(strs.location), string.Join('\n', data.Address.Split(", ")), true)
.AddField(GetText(strs.timezone), data.TimeZoneName, true);
await ctx.Channel.SendMessageAsync(embed: eb.Build());
await Response().Embed(eb).SendAsync();
}
[Cmd]
@@ -441,7 +441,7 @@ public partial class Searches : NadekoModule<SearchesService>
if (data.Query.Pages[0].Missing || string.IsNullOrWhiteSpace(data.Query.Pages[0].FullUrl))
await Response().Error(strs.wiki_page_not_found).SendAsync();
else
await ctx.Channel.SendMessageAsync(data.Query.Pages[0].FullUrl);
await Response().Text(data.Query.Pages[0].FullUrl).SendAsync();
}
[Cmd]
@@ -514,7 +514,7 @@ public partial class Searches : NadekoModule<SearchesService>
var url = Uri.EscapeDataString($"https://{target}.fandom.com/wiki/{title}");
var response = $@"`{GetText(strs.title)}` {title.SanitizeMentions()}
`{GetText(strs.url)}:` {url}";
await ctx.Channel.SendMessageAsync(response);
await Response().Text(response).SendAsync();
}
catch
{
@@ -575,7 +575,7 @@ public partial class Searches : NadekoModule<SearchesService>
// .AddField(GetText(strs.price), gameData.IsFree ? GetText(strs.FREE) : game, true)
// .AddField(GetText(strs.links), gameData.GetGenresString(), true)
// .WithFooter(GetText(strs.recommendations(gameData.TotalRecommendations)));
await ctx.Channel.SendMessageAsync($"https://store.steampowered.com/app/{appId}");
await Response().Text($"https://store.steampowered.com/app/{appId}").SendAsync();
}
private async Task<bool> ValidateQuery([MaybeNullWhen(false)] string query)

View File

@@ -25,7 +25,7 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
private readonly ConcurrentHashSet<ulong> _deleteOnOfflineServers;
private readonly IPubSub _pubSub;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
private readonly SearchesConfigService _config;
private readonly IReplacementService _repSvc;
@@ -49,7 +49,7 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
IHttpClientFactory httpFactory,
IBot bot,
IPubSub pubSub,
IEmbedBuilderService eb,
IMessageSenderService sender,
SearchesConfigService config,
IReplacementService repSvc)
{
@@ -57,7 +57,7 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
_client = client;
_strings = strings;
_pubSub = pubSub;
_eb = eb;
_sender = sender;
_config = config;
_repSvc = repSvc;
@@ -285,7 +285,10 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
? ""
: await _repSvc.ReplaceAsync(fs.Message, repCtx);
var msg = await textChannel.EmbedAsync(GetEmbed(fs.GuildId, stream, false), message);
var msg = await _sender.Response(textChannel)
.Embed(GetEmbed(fs.GuildId, stream, false))
.Text(message)
.SendAsync();
// only cache the ids of channel/message pairs
if (_deleteOnOfflineServers.Contains(fs.GuildId))

View File

@@ -12,7 +12,7 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
{
private readonly IGoogleApiService _google;
private readonly DbService _db;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
private readonly IBot _bot;
private readonly ConcurrentDictionary<ulong, bool> _atcs = new();
@@ -21,12 +21,12 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
public TranslateService(
IGoogleApiService google,
DbService db,
IEmbedBuilderService eb,
IMessageSenderService sender,
IBot bot)
{
_google = google;
_db = db;
_eb = eb;
_sender = sender;
_bot = bot;
}
@@ -77,7 +77,7 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
.AddField(langs.From, um.Content)
.AddField(langs.To, output);
await tch.EmbedAsync(embed);
await _sender.Response(tch).Embed(embed).SendAsync();
try
{