Part2 of the response system rework

This commit is contained in:
Kwoth
2024-04-29 01:13:45 +00:00
parent 4bab94b329
commit d28c7b500d
128 changed files with 2723 additions and 2289 deletions

View File

@@ -43,7 +43,7 @@ public partial class Games
}
}
else
await ReplyErrorLocalizedAsync(strs.acro_running);
await Response().Error(strs.acro_running).SendAsync();
Task ClientMessageReceived(SocketMessage msg)
{
@@ -67,18 +67,18 @@ public partial class Games
private Task Game_OnStarted(AcrophobiaGame game)
{
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.acrophobia))
.WithDescription(
GetText(strs.acro_started(Format.Bold(string.Join(".", game.StartingLetters)))))
.WithFooter(GetText(strs.acro_started_footer(game.Opts.SubmissionTime)));
return EmbedAsync(embed);
return Response().Embed(embed).SendAsync();
}
private Task Game_OnUserVoted(string user)
=> SendConfirmAsync(GetText(strs.acrophobia), GetText(strs.acro_vote_cast(Format.Bold(user))));
=> Response().Confirm(GetText(strs.acrophobia), GetText(strs.acro_vote_cast(Format.Bold(user)))).SendAsync();
private async Task Game_OnVotingStarted(
AcrophobiaGame game,
@@ -86,24 +86,24 @@ public partial class Games
{
if (submissions.Length == 0)
{
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub));
await Response().Error(GetText(strs.acrophobia), GetText(strs.acro_ended_no_sub)).SendAsync();
return;
}
if (submissions.Length == 1)
{
await EmbedAsync(_eb.Create()
await Response().Embed(new EmbedBuilder()
.WithOkColor()
.WithDescription(GetText(
strs.acro_winner_only(
Format.Bold(submissions.First().Key.UserName))))
.WithFooter(submissions.First().Key.Input));
.WithFooter(submissions.First().Key.Input)).SendAsync();
return;
}
var i = 0;
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.acrophobia) + " - " + GetText(strs.submissions_closed))
.WithDescription(GetText(strs.acro_nym_was(
@@ -114,27 +114,27 @@ public partial class Games
--")))
.WithFooter(GetText(strs.acro_vote));
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
private async Task Game_OnEnded(AcrophobiaGame game, ImmutableArray<KeyValuePair<AcrophobiaUser, int>> votes)
{
if (!votes.Any() || votes.All(x => x.Value == 0))
{
await SendErrorAsync(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast));
await Response().Error(GetText(strs.acrophobia), GetText(strs.acro_no_votes_cast)).SendAsync();
return;
}
var table = votes.OrderByDescending(v => v.Value);
var winner = table.First();
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.acrophobia))
.WithDescription(GetText(strs.acro_winner(Format.Bold(winner.Key.UserName),
Format.Bold(winner.Value.ToString()))))
.WithFooter(winner.Key.Input);
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
}
}

View File

@@ -26,6 +26,7 @@ public class ChatterBotService : IExecOnMessage
private readonly IHttpClientFactory _httpFactory;
private readonly IPatronageService _ps;
private readonly GamesConfigService _gcs;
private readonly IMessageSenderService _sender;
public ChatterBotService(
DiscordSocketClient client,
@@ -37,7 +38,8 @@ public class ChatterBotService : IExecOnMessage
IBotCredentials creds,
IEmbedBuilderService eb,
IPatronageService ps,
GamesConfigService gcs)
GamesConfigService gcs,
IMessageSenderService sender)
{
_client = client;
_perms = perms;
@@ -49,6 +51,7 @@ public class ChatterBotService : IExecOnMessage
_ps = ps;
_perms = perms;
_gcs = gcs;
_sender = sender;
_flKey = new FeatureLimitKey()
{
@@ -133,7 +136,7 @@ public class ChatterBotService : IExecOnMessage
usrMsg.Author,
"games",
CleverBotResponseStr.CLEVERBOT_RESPONSE);
if (!res.IsAllowed)
return false;
@@ -163,20 +166,24 @@ public class ChatterBotService : IExecOnMessage
{
if (ql.Quota == 0)
{
await channel.SendErrorAsync(_eb,
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.",
footer:
"You may disable the cleverbot feature, and this message via '.cleverbot' command");
await channel
.Response(_strings, _eb)
.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.",
footer:
"You may disable the cleverbot feature, and this message via '.cleverbot' command")
.SendAsync();
return true;
}
await channel.SendErrorAsync(_eb,
null!,
$"You've reached your quota limit of **{ql.Quota}** responses {ql.QuotaPeriod.ToFullName()} for the cleverbot feature.",
footer: "You may wait for the quota reset or .");
await channel.Response(_strings, _eb)
.Error(
null!,
$"You've reached your quota limit of **{ql.Quota}** responses {ql.QuotaPeriod.ToFullName()} for the cleverbot feature.",
footer: "You may wait for the quota reset or .")
.SendAsync();
return true;
}
@@ -184,19 +191,17 @@ public class ChatterBotService : IExecOnMessage
_ = channel.TriggerTypingAsync();
var response = await cbs.Think(message, usrMsg.Author.ToString());
await channel.SendConfirmAsync(_eb,
title: null,
response.SanitizeMentions(true)
// , footer: counter > 0 ? counter.ToString() : null
);
await _sender.Response(channel)
.Confirm(response)
.SendAsync();
Log.Information("""
CleverBot Executed
Server: {GuildName} [{GuildId}]
Channel: {ChannelName} [{ChannelId}]
UserId: {Author} [{AuthorId}]
Message: {Content}
""",
CleverBot Executed
Server: {GuildName} [{GuildId}]
Channel: {ChannelName} [{ChannelId}]
UserId: {Author} [{AuthorId}]
Message: {Content}
""",
guild.Name,
guild.Id,
usrMsg.Channel?.Name,

View File

@@ -30,7 +30,7 @@ public partial class Games
await uow.SaveChangesAsync();
}
await ReplyConfirmLocalizedAsync(strs.cleverbot_disabled);
await Response().Confirm(strs.cleverbot_disabled).SendAsync();
return;
}
@@ -42,7 +42,7 @@ public partial class Games
await uow.SaveChangesAsync();
}
await ReplyConfirmLocalizedAsync(strs.cleverbot_enabled);
await Response().Confirm(strs.cleverbot_enabled).SendAsync();
}
}
}

View File

@@ -28,7 +28,7 @@ public partial class Games : NadekoModule<GamesService>
if (listArr.Length < 2)
return;
var rng = new NadekoRandom();
await SendConfirmAsync("🤔", listArr[rng.Next(0, listArr.Length)]);
await Response().Confirm("🤔", listArr[rng.Next(0, listArr.Length)]).SendAsync();
}
[Cmd]
@@ -38,10 +38,10 @@ public partial class Games : NadekoModule<GamesService>
return;
var res = _service.GetEightballResponse(ctx.User.Id, question);
await EmbedAsync(_eb.Create()
await Response().Embed(new EmbedBuilder()
.WithOkColor()
.WithDescription(ctx.User.ToString())
.AddField("❓ " + GetText(strs.question), question)
.AddField("🎱 " + GetText(strs._8ball), res));
.AddField("🎱 " + GetText(strs._8ball), res)).SendAsync();
}
}

View File

@@ -10,7 +10,7 @@ public partial class Games
[Cmd]
[RequireContext(ContextType.Guild)]
public async Task Hangmanlist()
=> await SendConfirmAsync(GetText(strs.hangman_types(prefix)), _service.GetHangmanTypes().Join('\n'));
=> await Response().Confirm(GetText(strs.hangman_types(prefix)), _service.GetHangmanTypes().Join('\n')).SendAsync();
private static string Draw(HangmanGame.State state)
=> $"""
@@ -23,11 +23,11 @@ public partial class Games
/-\
""";
public static IEmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
public static EmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
{
if (state.Phase == HangmanGame.Phase.Running)
{
return eb.Create()
return new EmbedBuilder()
.WithOkColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
@@ -36,14 +36,14 @@ public partial class Games
if (state.Phase == HangmanGame.Phase.Ended && state.Failed)
{
return eb.Create()
return new EmbedBuilder()
.WithErrorColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.MissedLetters.Join(' '));
}
return eb.Create()
return new EmbedBuilder()
.WithOkColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
@@ -56,13 +56,13 @@ public partial class Games
{
if (!_service.StartHangman(ctx.Channel.Id, type, out var hangman))
{
await ReplyErrorLocalizedAsync(strs.hangman_running);
await Response().Error(strs.hangman_running).SendAsync();
return;
}
var eb = GetEmbed(_eb, hangman);
eb.WithDescription(GetText(strs.hangman_game_started));
await EmbedAsync(eb);
await Response().Embed(eb).SendAsync();
}
[Cmd]
@@ -70,7 +70,7 @@ public partial class Games
public async Task HangmanStop()
{
if (await _service.StopHangman(ctx.Channel.Id))
await ReplyConfirmLocalizedAsync(strs.hangman_stopped);
await Response().Confirm(strs.hangman_stopped).SendAsync();
}
}
}

View File

@@ -25,17 +25,16 @@ public partial class Games
if ((nunchi = _service.NunchiGames.GetOrAdd(ctx.Guild.Id, newNunchi)) != newNunchi)
{
// join it
// if you failed joining, that means game is running or just ended
if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString()))
// if you failed joining, that means game is running or just ended
// await ReplyErrorLocalized("nunchi_already_started");
return;
await ReplyErrorLocalizedAsync(strs.nunchi_joined(nunchi.ParticipantCount));
await Response().Error(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync();
return;
}
try { await ConfirmLocalizedAsync(strs.nunchi_created); }
try { await Response().Confirm(strs.nunchi_created).SendAsync(); }
catch { }
nunchi.OnGameEnded += NunchiOnGameEnded;
@@ -50,7 +49,7 @@ public partial class Games
{
if (_service.NunchiGames.TryRemove(ctx.Guild.Id, out var game))
game.Dispose();
await ConfirmLocalizedAsync(strs.nunchi_failed_to_start);
await Response().Confirm(strs.nunchi_failed_to_start).SendAsync();
}
Task ClientMessageReceived(SocketMessage arg)
@@ -82,30 +81,34 @@ public partial class Games
}
if (arg2 is null)
return ConfirmLocalizedAsync(strs.nunchi_ended_no_winner);
return ConfirmLocalizedAsync(strs.nunchi_ended(Format.Bold(arg2)));
return Response().Confirm(strs.nunchi_ended_no_winner).SendAsync();
return Response().Confirm(strs.nunchi_ended(Format.Bold(arg2))).SendAsync();
}
}
private Task Nunchi_OnRoundStarted(NunchiGame arg, int cur)
=> ConfirmLocalizedAsync(strs.nunchi_round_started(Format.Bold(arg.ParticipantCount.ToString()),
Format.Bold(cur.ToString())));
=> Response()
.Confirm(strs.nunchi_round_started(Format.Bold(arg.ParticipantCount.ToString()),
Format.Bold(cur.ToString())))
.SendAsync();
private Task Nunchi_OnUserGuessed(NunchiGame arg)
=> ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString())));
=> Response().Confirm(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString()))).SendAsync();
private Task Nunchi_OnRoundEnded(NunchiGame arg1, (ulong Id, string Name)? arg2)
{
if (arg2.HasValue)
return ConfirmLocalizedAsync(strs.nunchi_round_ended(Format.Bold(arg2.Value.Name)));
return ConfirmLocalizedAsync(strs.nunchi_round_ended_boot(
Format.Bold("\n"
+ string.Join("\n, ",
arg1.Participants.Select(x
=> x.Name))))); // this won't work if there are too many users
return Response().Confirm(strs.nunchi_round_ended(Format.Bold(arg2.Value.Name))).SendAsync();
return Response()
.Confirm(strs.nunchi_round_ended_boot(
Format.Bold("\n"
+ string.Join("\n, ",
arg1.Participants.Select(x
=> x.Name)))))
.SendAsync(); // this won't work if there are too many users
}
private Task Nunchi_OnGameStarted(NunchiGame arg)
=> ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString())));
=> Response().Confirm(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString()))).SendAsync();
}
}

View File

@@ -27,10 +27,10 @@ public partial class Games
var channel = (ITextChannel)ctx.Channel;
var game = _service.RunningContests.GetOrAdd(ctx.Guild.Id,
_ => new(_games, _client, channel, prefix, options, _eb));
_ => new(_games, _client, channel, prefix, options, _sender));
if (game.IsActive)
await SendErrorAsync($"Contest already running in {game.Channel.Mention} channel.");
await Response().Error($"Contest already running in {game.Channel.Mention} channel.").SendAsync();
else
await game.Start();
}
@@ -45,7 +45,7 @@ public partial class Games
return;
}
await SendErrorAsync("No contest to stop on this channel.");
await Response().Error("No contest to stop on this channel.").SendAsync();
}
@@ -59,7 +59,7 @@ public partial class Games
_games.AddTypingArticle(ctx.User, text);
await SendConfirmAsync("Added new article for typing game.");
await Response().Confirm("Added new article for typing game.").SendAsync();
}
[Cmd]
@@ -73,13 +73,15 @@ public partial class Games
if (!articles.Any())
{
await SendErrorAsync($"{ctx.User.Mention} `No articles found on that page.`");
await Response().Error($"{ctx.User.Mention} `No articles found on that page.`").SendAsync();
return;
}
var i = (page - 1) * 15;
await SendConfirmAsync("List of articles for Type Race",
string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}")));
await Response()
.Confirm("List of articles for Type Race",
string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}")))
.SendAsync();
}
[Cmd]
@@ -92,12 +94,12 @@ public partial class Games
if (removed is null)
return;
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithTitle($"Removed typing article #{index + 1}")
.WithDescription(removed.Text.TrimTo(50))
.WithOkColor();
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
}
}

View File

@@ -17,7 +17,7 @@ public class TypingGame
private readonly GamesService _games;
private readonly string _prefix;
private readonly Options _options;
private readonly IEmbedBuilderService _eb;
private readonly IMessageSenderService _sender;
public TypingGame(
GamesService games,
@@ -25,13 +25,13 @@ public class TypingGame
ITextChannel channel,
string prefix,
Options options,
IEmbedBuilderService eb)
IMessageSenderService sender)
{
_games = games;
_client = client;
_prefix = prefix;
_options = options;
_eb = eb;
_sender = sender;
Channel = channel;
IsActive = false;
@@ -50,7 +50,9 @@ public class TypingGame
_sw.Reset();
try
{
await Channel.SendConfirmAsync(_eb, "Typing contest stopped.");
await _sender.Response(Channel)
.Confirm("Typing contest stopped.")
.SendAsync();
}
catch
{
@@ -68,8 +70,10 @@ public class TypingGame
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
try
{
await Channel.SendConfirmAsync(_eb,
$":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.");
await _sender.Response(Channel)
.Confirm(
$":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.")
.SendAsync();
var time = _options.StartTime;
@@ -139,18 +143,26 @@ public class TypingGame
var elapsed = _sw.Elapsed;
var wpm = CurrentSentence.Length / WORD_VALUE / elapsed.TotalSeconds * 60;
_finishedUserIds.Add(msg.Author.Id);
await Channel.EmbedAsync(_eb.Create()
.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))
.SendAsync();
if (_finishedUserIds.Count % 4 == 0)
{
await Channel.SendConfirmAsync(_eb,
":exclamation: A lot of people finished, here is the text for those still typing:"
+ $"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**");
await _sender.Response(Channel)
.Confirm(
$"""
:exclamation: A lot of people finished, here is the text for those still typing:
**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**
""")
.SendAsync();
}
}
}

View File

@@ -71,9 +71,9 @@ public class TicTacToe
return sb.ToString();
}
public IEmbedBuilder GetEmbed(string title = null)
public EmbedBuilder GetEmbed(string title = null)
{
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithDescription(Environment.NewLine + GetState())
.WithAuthor(GetText(strs.vs(_users[0], _users[1])));
@@ -115,13 +115,13 @@ public class TicTacToe
{
if (phase is Phase.Started or Phase.Ended)
{
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running));
await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_already_running)).SendAsync();
return;
}
if (_users[0] == user)
{
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_against_yourself));
await _channel.Response(_strings, _eb).Error(user.Mention + GetText(strs.ttt_against_yourself)).SendAsync();
return;
}

View File

@@ -37,7 +37,7 @@ public partial class Games
game = new(Strings, _client, channel, (IGuildUser)ctx.User, options, _eb);
_service.TicTacToeGames.Add(channel.Id, game);
await ReplyConfirmLocalizedAsync(strs.ttt_created);
await Response().Confirm(strs.ttt_created).SendAsync();
game.OnEnded += _ =>
{

View File

@@ -36,7 +36,9 @@ public partial class Games
var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args);
var config = _gamesConfig.Data;
if (opts.WinRequirement != 0 && config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement)
if (opts.WinRequirement != 0
&& config.Trivia.MinimumWinReq > 0
&& config.Trivia.MinimumWinReq > opts.WinRequirement)
return;
var trivia = new TriviaGame(opts, _cache);
@@ -49,11 +51,11 @@ public partial class Games
if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var tg))
{
await SendErrorAsync(GetText(strs.trivia_already_running));
await Response().Error(GetText(strs.trivia_already_running)).SendAsync();
await tg.TriggerQuestionAsync();
}
}
[Cmd]
[RequireContext(ContextType.Guild)]
public async Task Tl()
@@ -64,7 +66,7 @@ public partial class Games
return;
}
await ReplyErrorLocalizedAsync(strs.trivia_none);
await Response().Error(strs.trivia_none).SendAsync();
}
[Cmd]
@@ -79,9 +81,9 @@ public partial class Games
{
try
{
await ctx.Channel.SendConfirmAsync(_eb,
GetText(strs.trivia_game),
GetText(strs.trivia_stopping));
await Response()
.Confirm(GetText(strs.trivia_game), GetText(strs.trivia_stopping))
.SendAsync();
}
catch (Exception ex)
{
@@ -92,7 +94,7 @@ public partial class Games
return;
}
await ReplyErrorLocalizedAsync(strs.trivia_none);
await Response().Error(strs.trivia_none).SendAsync();
}
private string GetLeaderboardString(TriviaGame tg)
@@ -103,13 +105,12 @@ public partial class Games
sb.AppendLine(GetText(strs.trivia_points(Format.Bold($"<@{id}>"), pts)));
return sb.ToString();
}
private IEmbedBuilder? questionEmbed = null;
private EmbedBuilder? questionEmbed = null;
private IUserMessage? questionMessage = null;
private bool showHowToQuit = false;
private void RegisterEvents(TriviaGame trivia)
{
trivia.OnQuestion += OnTriviaQuestion;
@@ -119,7 +120,7 @@ public partial class Games
trivia.OnStats += OnTriviaStats;
trivia.OnTimeout += OnTriviaTimeout;
}
private void UnregisterEvents(TriviaGame trivia)
{
trivia.OnQuestion -= OnTriviaQuestion;
@@ -141,7 +142,8 @@ public partial class Games
}
if (questionEmbed is not null)
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(question.GetHint()).Build());
await questionMessage.ModifyAsync(m
=> m.Embed = questionEmbed.WithFooter(question.GetHint()).Build());
}
catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound or HttpStatusCode.Forbidden)
{
@@ -158,11 +160,11 @@ public partial class Games
{
try
{
questionEmbed = _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.AddField(GetText(strs.category), question.Category)
.AddField(GetText(strs.question), question.Question);
questionEmbed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.AddField(GetText(strs.category), question.Category)
.AddField(GetText(strs.question), question.Question);
showHowToQuit = !showHowToQuit;
if (showHowToQuit)
@@ -171,9 +173,10 @@ public partial class Games
if (Uri.IsWellFormedUriString(question.ImageUrl, UriKind.Absolute))
questionEmbed.WithImageUrl(question.ImageUrl);
questionMessage = await EmbedAsync(questionEmbed);
questionMessage = await Response().Embed(questionEmbed).SendAsync();
}
catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound or HttpStatusCode.Forbidden
catch (HttpException ex) when (ex.HttpCode is HttpStatusCode.NotFound
or HttpStatusCode.Forbidden
or HttpStatusCode.BadRequest)
{
Log.Warning("Unable to send trivia questions. Stopping immediately");
@@ -186,15 +189,15 @@ public partial class Games
{
try
{
var embed = _eb.Create()
.WithErrorColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_times_up(Format.Bold(question.Answer))));
var embed = new EmbedBuilder()
.WithErrorColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_times_up(Format.Bold(question.Answer))));
if (Uri.IsWellFormedUriString(question.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(question.AnswerImageUrl);
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
catch
{
@@ -206,7 +209,7 @@ public partial class Games
{
try
{
await SendConfirmAsync(GetText(strs.leaderboard), GetLeaderboardString(game));
await Response().Confirm(GetText(strs.leaderboard), GetLeaderboardString(game)).SendAsync();
}
catch
{
@@ -218,11 +221,11 @@ public partial class Games
{
try
{
await EmbedAsync(_eb.Create(ctx)
.WithOkColor()
.WithAuthor(GetText(strs.trivia_ended))
.WithTitle(GetText(strs.leaderboard))
.WithDescription(GetLeaderboardString(game)));
await Response().Embed(new EmbedBuilder()
.WithOkColor()
.WithAuthor(GetText(strs.trivia_ended))
.WithTitle(GetText(strs.leaderboard))
.WithDescription(GetLeaderboardString(game))).SendAsync();
}
catch
{
@@ -236,15 +239,19 @@ public partial class Games
UnregisterEvents(game);
}
private async Task OnTriviaGuess(TriviaGame _, TriviaUser user, TriviaQuestion question, bool isWin)
private async Task OnTriviaGuess(
TriviaGame _,
TriviaUser user,
TriviaQuestion question,
bool isWin)
{
try
{
var embed = _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_win(user.Name,
Format.Bold(question.Answer))));
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.trivia_game))
.WithDescription(GetText(strs.trivia_win(user.Name,
Format.Bold(question.Answer))));
if (Uri.IsWellFormedUriString(question.AnswerImageUrl, UriKind.Absolute))
embed.WithImageUrl(question.AnswerImageUrl);
@@ -252,7 +259,7 @@ public partial class Games
if (isWin)
{
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
var reward = _gamesConfig.Data.Trivia.CurrencyReward;
if (reward > 0)
@@ -264,7 +271,7 @@ public partial class Games
embed.WithDescription(GetText(strs.trivia_guess(user.Name,
Format.Bold(question.Answer))));
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
catch
{