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

@@ -20,9 +20,7 @@ public class ChatterBotService : IExecOnMessage
private readonly DiscordSocketClient _client;
private readonly IPermissionChecker _perms;
private readonly CommandHandler _cmd;
private readonly IBotStrings _strings;
private readonly IBotCredentials _creds;
private readonly IEmbedBuilderService _eb;
private readonly IHttpClientFactory _httpFactory;
private readonly IPatronageService _ps;
private readonly GamesConfigService _gcs;
@@ -33,10 +31,8 @@ public class ChatterBotService : IExecOnMessage
IPermissionChecker perms,
IBot bot,
CommandHandler cmd,
IBotStrings strings,
IHttpClientFactory factory,
IBotCredentials creds,
IEmbedBuilderService eb,
IPatronageService ps,
GamesConfigService gcs,
IMessageSenderService sender)
@@ -44,14 +40,12 @@ public class ChatterBotService : IExecOnMessage
_client = client;
_perms = perms;
_cmd = cmd;
_strings = strings;
_creds = creds;
_eb = eb;
_sender = sender;
_httpFactory = factory;
_ps = ps;
_perms = perms;
_gcs = gcs;
_sender = sender;
_flKey = new FeatureLimitKey()
{
@@ -166,8 +160,7 @@ public class ChatterBotService : IExecOnMessage
{
if (ql.Quota == 0)
{
await channel
.Response(_strings, _eb)
await _sender.Response(channel)
.Error(null,
text:
"In order to use the cleverbot feature, the owner of this server should be [Patron Tier X](https://patreon.com/join/nadekobot) on patreon.",
@@ -178,7 +171,7 @@ public class ChatterBotService : IExecOnMessage
return true;
}
await channel.Response(_strings, _eb)
await _sender.Response(channel)
.Error(
null!,
$"You've reached your quota limit of **{ql.Quota}** responses {ql.QuotaPeriod.ToFullName()} for the cleverbot feature.",

View File

@@ -23,7 +23,7 @@ public partial class Games
/-\
""";
public static EmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
public static EmbedBuilder GetEmbed(HangmanGame.State state)
{
if (state.Phase == HangmanGame.Phase.Running)
{
@@ -60,7 +60,7 @@ public partial class Games
return;
}
var eb = GetEmbed(_eb, hangman);
var eb = GetEmbed(hangman);
eb.WithDescription(GetText(strs.hangman_game_started));
await Response().Embed(eb).SendAsync();
}

View File

@@ -9,7 +9,7 @@ public sealed class HangmanService : IHangmanService, IExecNoCommand
{
private readonly ConcurrentDictionary<ulong, HangmanGame> _hangmanGames = new();
private readonly IHangmanSource _source;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
private readonly GamesConfigService _gcs;
private readonly ICurrencyService _cs;
private readonly IMemoryCache _cdCache;
@@ -17,13 +17,13 @@ public sealed class HangmanService : IHangmanService, IExecNoCommand
public HangmanService(
IHangmanSource source,
IEmbedBuilderService eb,
IMessageSenderService sender,
GamesConfigService gcs,
ICurrencyService cs,
IMemoryCache cdCache)
{
_source = source;
_eb = eb;
_sender = sender;
_gcs = gcs;
_cs = cs;
_cdCache = cdCache;
@@ -116,7 +116,7 @@ public sealed class HangmanService : IHangmanService, IExecNoCommand
string content,
HangmanGame.State state)
{
var embed = Games.HangmanCommands.GetEmbed(_eb, state);
var embed = Games.HangmanCommands.GetEmbed(state);
if (state.GuessResult == HangmanGame.GuessResult.Guess)
embed.WithDescription($"{user} guessed the letter {content}!").WithOkColor();
else if (state.GuessResult == HangmanGame.GuessResult.Incorrect && state.Failed)
@@ -131,6 +131,6 @@ public sealed class HangmanService : IHangmanService, IExecNoCommand
if (!string.IsNullOrWhiteSpace(state.ImageUrl) && Uri.IsWellFormedUriString(state.ImageUrl, UriKind.Absolute))
embed.WithImageUrl(state.ImageUrl);
return channel.EmbedAsync(embed);
return _sender.Response(channel).Embed(embed).SendAsync();
}
}

View File

@@ -78,10 +78,11 @@ public class TypingGame
var time = _options.StartTime;
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...");
var msg = await _sender.Response(Channel).Confirm($"Starting new typing contest in **{time}**...").SendAsync();
do
{
// todo fix all modifies
await Task.Delay(2000);
time -= 2;
try { await msg.ModifyAsync(m => m.Content = $"Starting new typing contest in **{time}**.."); }
@@ -144,13 +145,15 @@ public class TypingGame
var wpm = CurrentSentence.Length / WORD_VALUE / elapsed.TotalSeconds * 60;
_finishedUserIds.Add(msg.Author.Id);
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle($"{msg.Author} finished the race!")
.AddField("Place", $"#{_finishedUserIds.Count}", true)
.AddField("WPM", $"{wpm:F1} *[{elapsed.TotalSeconds:F2}sec]*", true)
.AddField("Errors", distance.ToString(), true);
await _sender.Response(Channel)
.Embed(eb => new EmbedBuilder()
.WithOkColor()
.WithTitle($"{msg.Author} finished the race!")
.AddField("Place", $"#{_finishedUserIds.Count}", true)
.AddField("WPM", $"{wpm:F1} *[{elapsed.TotalSeconds:F2}sec]*", true)
.AddField("Errors", distance.ToString(), true))
.Embed(embed)
.SendAsync();
if (_finishedUserIds.Count % 4 == 0)

View File

@@ -26,7 +26,7 @@ public class TicTacToe
private readonly IBotStrings _strings;
private readonly DiscordSocketClient _client;
private readonly Options _options;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
public TicTacToe(
IBotStrings strings,
@@ -34,13 +34,13 @@ public class TicTacToe
ITextChannel channel,
IGuildUser firstUser,
Options options,
IEmbedBuilderService eb)
IMessageSenderService sender)
{
_channel = channel;
_strings = strings;
_client = client;
_options = options;
_eb = eb;
_sender = sender;
_users = new[] { firstUser, null };
_state = new int?[,] { { null, null, null }, { null, null, null }, { null, null, null } };
@@ -115,13 +115,13 @@ public class TicTacToe
{
if (phase is Phase.Started or Phase.Ended)
{
await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_already_running)).SendAsync();
await _sender.Response(_channel).Error(user.Mention + GetText(strs.ttt_already_running)).SendAsync();
return;
}
if (_users[0] == user)
{
await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_against_yourself)).SendAsync();
await _sender.Response(_channel).Error(user.Mention + GetText(strs.ttt_against_yourself)).SendAsync();
return;
}
@@ -144,7 +144,7 @@ public class TicTacToe
var del = previousMessage?.DeleteAsync();
try
{
await _channel.EmbedAsync(GetEmbed(GetText(strs.ttt_time_expired)));
await _sender.Response(_channel).Embed(GetEmbed(GetText(strs.ttt_time_expired))).SendAsync();
if (del is not null)
await del;
}
@@ -166,7 +166,7 @@ public class TicTacToe
_client.MessageReceived += Client_MessageReceived;
previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started)));
previousMessage = await _sender.Response(_channel).Embed(GetEmbed(GetText(strs.game_started))).SendAsync();
}
private bool IsDraw()
@@ -259,7 +259,7 @@ public class TicTacToe
{
var del1 = msg.DeleteAsync();
var del2 = previousMessage?.DeleteAsync();
try { previousMessage = await _channel.EmbedAsync(GetEmbed(reason)); }
try { previousMessage = await _sender.Response(_channel).Embed(GetEmbed(reason)).SendAsync(); }
catch { }
try { await del1; }

View File

@@ -35,7 +35,7 @@ public partial class Games
return;
}
game = new(Strings, _client, channel, (IGuildUser)ctx.User, options, _eb);
game = new(Strings, _client, channel, (IGuildUser)ctx.User, options, _sender);
_service.TicTacToeGames.Add(channel.Id, game);
await Response().Confirm(strs.ttt_created).SendAsync();

View File

@@ -51,7 +51,7 @@ public partial class Games
if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var tg))
{
await Response().Error(GetText(strs.trivia_already_running)).SendAsync();
await Response().Error(strs.trivia_already_running).SendAsync();
await tg.TriggerQuestionAsync();
}
}