mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
- Reworked embed builder
- Use IEmbedBuilderService to create embed builders - Wrapped embed builder and using IEmbedBuilder
This commit is contained in:
@@ -50,14 +50,16 @@ namespace NadekoBot.Modules.Games.Common
|
||||
private readonly IBotStrings _strings;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly Options _options;
|
||||
private readonly IEmbedBuilderService _eb;
|
||||
|
||||
public TicTacToe(IBotStrings strings, DiscordSocketClient client, ITextChannel channel,
|
||||
IGuildUser firstUser, Options options)
|
||||
IGuildUser firstUser, Options options, IEmbedBuilderService eb)
|
||||
{
|
||||
_channel = channel;
|
||||
_strings = strings;
|
||||
_client = client;
|
||||
_options = options;
|
||||
_eb = eb;
|
||||
|
||||
_users = new[] { firstUser, null };
|
||||
_state = new int?[,] {
|
||||
@@ -91,9 +93,9 @@ namespace NadekoBot.Modules.Games.Common
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public EmbedBuilder GetEmbed(string title = null)
|
||||
public IEmbedBuilder GetEmbed(string title = null)
|
||||
{
|
||||
var embed = new EmbedBuilder()
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithDescription(Environment.NewLine + GetState())
|
||||
.WithAuthor(GetText("vs", _users[0], _users[1]));
|
||||
@@ -135,12 +137,12 @@ namespace NadekoBot.Modules.Games.Common
|
||||
{
|
||||
if (_phase == Phase.Started || _phase == Phase.Ended)
|
||||
{
|
||||
await _channel.SendErrorAsync(user.Mention + GetText("ttt_already_running")).ConfigureAwait(false);
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText("ttt_already_running")).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else if (_users[0] == user)
|
||||
{
|
||||
await _channel.SendErrorAsync(user.Mention + GetText("ttt_against_yourself")).ConfigureAwait(false);
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText("ttt_against_yourself")).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -42,10 +42,11 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
private readonly TriviaQuestionPool _questionPool;
|
||||
private int _timeoutCount = 0;
|
||||
private readonly string _quitCommand;
|
||||
private readonly IEmbedBuilderService _eb;
|
||||
|
||||
public TriviaGame(IBotStrings strings, DiscordSocketClient client, GamesConfig config,
|
||||
IDataCache cache, ICurrencyService cs, IGuild guild, ITextChannel channel,
|
||||
TriviaOptions options, string quitCommand)
|
||||
TriviaOptions options, string quitCommand, IEmbedBuilderService eb)
|
||||
{
|
||||
_cache = cache;
|
||||
_questionPool = new TriviaQuestionPool(_cache);
|
||||
@@ -55,6 +56,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
_cs = cs;
|
||||
_options = options;
|
||||
_quitCommand = quitCommand;
|
||||
_eb = eb;
|
||||
|
||||
Guild = guild;
|
||||
Channel = channel;
|
||||
@@ -76,16 +78,16 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
CurrentQuestion = _questionPool.GetRandomQuestion(OldQuestions, _options.IsPokemon);
|
||||
if (string.IsNullOrWhiteSpace(CurrentQuestion?.Answer) || string.IsNullOrWhiteSpace(CurrentQuestion.Question))
|
||||
{
|
||||
await Channel.SendErrorAsync(GetText("trivia_game"), GetText("failed_loading_question")).ConfigureAwait(false);
|
||||
await Channel.SendErrorAsync(_eb, GetText("trivia_game"), GetText("failed_loading_question")).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
OldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again
|
||||
|
||||
EmbedBuilder questionEmbed;
|
||||
IEmbedBuilder questionEmbed;
|
||||
IUserMessage questionMessage;
|
||||
try
|
||||
{
|
||||
questionEmbed = new EmbedBuilder().WithOkColor()
|
||||
questionEmbed = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.AddField(GetText("category"), CurrentQuestion.Category)
|
||||
.AddField(GetText("question"), CurrentQuestion.Question);
|
||||
@@ -149,7 +151,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
{
|
||||
try
|
||||
{
|
||||
var embed = new EmbedBuilder().WithErrorColor()
|
||||
var embed = _eb.Create().WithErrorColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithDescription(GetText("trivia_times_up", Format.Bold(CurrentQuestion.Answer)));
|
||||
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
|
||||
@@ -173,7 +175,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
{
|
||||
ShouldStopGame = true;
|
||||
|
||||
await Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||
await Channel.EmbedAsync(_eb.Create().WithOkColor()
|
||||
.WithAuthor("Trivia Game Ended")
|
||||
.WithTitle("Final Results")
|
||||
.WithDescription(GetLeaderboard())).ConfigureAwait(false);
|
||||
@@ -187,8 +189,9 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
{
|
||||
try
|
||||
{
|
||||
await Channel.SendConfirmAsync(GetText("trivia_game"), GetText("trivia_stopping"))
|
||||
.ConfigureAwait(false);
|
||||
await Channel.SendConfirmAsync(_eb,
|
||||
GetText("trivia_game"),
|
||||
GetText("trivia_stopping"));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -235,7 +238,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
ShouldStopGame = true;
|
||||
try
|
||||
{
|
||||
var embedS = new EmbedBuilder().WithOkColor()
|
||||
var embedS = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithDescription(GetText("trivia_win",
|
||||
guildUser.Mention,
|
||||
@@ -253,7 +256,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
await _cs.AddAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var embed = new EmbedBuilder().WithOkColor()
|
||||
var embed = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithDescription(GetText("trivia_guess", guildUser.Mention, Format.Bold(CurrentQuestion.Answer)));
|
||||
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
|
||||
|
@@ -9,6 +9,7 @@ using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Games.Services;
|
||||
using CommandLine;
|
||||
using NadekoBot.Services;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common
|
||||
@@ -37,15 +38,17 @@ namespace NadekoBot.Modules.Games.Common
|
||||
private readonly GamesService _games;
|
||||
private readonly string _prefix;
|
||||
private readonly Options _options;
|
||||
private readonly IEmbedBuilderService _eb;
|
||||
|
||||
public TypingGame(GamesService games, DiscordSocketClient client, ITextChannel channel,
|
||||
string prefix, Options options)
|
||||
string prefix, Options options, IEmbedBuilderService eb)
|
||||
{
|
||||
_games = games;
|
||||
_client = client;
|
||||
_prefix = prefix;
|
||||
_options = options;
|
||||
|
||||
_eb = eb;
|
||||
|
||||
this.Channel = channel;
|
||||
IsActive = false;
|
||||
sw = new Stopwatch();
|
||||
@@ -62,7 +65,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
sw.Reset();
|
||||
try
|
||||
{
|
||||
await Channel.SendConfirmAsync("Typing contest stopped.").ConfigureAwait(false);
|
||||
await Channel.SendConfirmAsync(_eb, "Typing contest stopped.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -80,7 +83,8 @@ namespace NadekoBot.Modules.Games.Common
|
||||
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
|
||||
try
|
||||
{
|
||||
await Channel.SendConfirmAsync($@":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
|
||||
await Channel.SendConfirmAsync(_eb,
|
||||
$@":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.");
|
||||
|
||||
|
||||
var time = _options.StartTime;
|
||||
@@ -156,7 +160,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
var elapsed = sw.Elapsed;
|
||||
var wpm = CurrentSentence.Length / WORD_VALUE / elapsed.TotalSeconds * 60;
|
||||
finishedUserIds.Add(msg.Author.Id);
|
||||
await this.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||
await this.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)
|
||||
@@ -164,7 +168,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
|
||||
if (finishedUserIds.Count % 4 == 0)
|
||||
{
|
||||
await this.Channel.SendConfirmAsync(
|
||||
await this.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)}**")
|
||||
.ConfigureAwait(false);
|
||||
|
Reference in New Issue
Block a user