- Reworked embed builder

- Use IEmbedBuilderService to create embed builders
- Wrapped embed builder and using IEmbedBuilder
This commit is contained in:
Kwoth
2021-07-09 22:23:19 +02:00
parent 5b4daa9dd3
commit 5e4754fa40
103 changed files with 730 additions and 540 deletions

View File

@@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Gambling
var ar = new AnimalRace(options, _cs, _gamesConf.Data.RaceAnimals.Shuffle());
if (!_service.AnimalRaces.TryAdd(ctx.Guild.Id, ar))
return ctx.Channel.SendErrorAsync(GetText("animal_race"), GetText("animal_race_already_started"));
return SendErrorAsync(GetText("animal_race"), GetText("animal_race_already_started"));
ar.Initialize();
@@ -76,13 +76,13 @@ namespace NadekoBot.Modules.Gambling
var winner = race.FinishedUsers[0];
if (race.FinishedUsers[0].Bet > 0)
{
return ctx.Channel.SendConfirmAsync(GetText("animal_race"),
return SendConfirmAsync(GetText("animal_race"),
GetText("animal_race_won_money", Format.Bold(winner.Username),
winner.Animal.Icon, (race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign));
}
else
{
return ctx.Channel.SendConfirmAsync(GetText("animal_race"),
return SendConfirmAsync(GetText("animal_race"),
GetText("animal_race_won", Format.Bold(winner.Username), winner.Animal.Icon));
}
}
@@ -93,16 +93,16 @@ namespace NadekoBot.Modules.Gambling
ar.OnStarted += Ar_OnStarted;
_client.MessageReceived += _client_MessageReceived;
return ctx.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting", options.StartTime),
return SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting", options.StartTime),
footer: GetText("animal_race_join_instr", Prefix));
}
private Task Ar_OnStarted(AnimalRace race)
{
if (race.Users.Count == race.MaxUsers)
return ctx.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_full"));
return SendConfirmAsync(GetText("animal_race"), GetText("animal_race_full"));
else
return ctx.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting_with_x", race.Users.Count));
return SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting_with_x", race.Users.Count));
}
private async Task Ar_OnStateUpdate(AnimalRace race)
@@ -119,10 +119,10 @@ namespace NadekoBot.Modules.Gambling
var msg = raceMessage;
if (msg is null)
raceMessage = await ctx.Channel.SendConfirmAsync(text)
raceMessage = await SendConfirmAsync(text)
.ConfigureAwait(false);
else
await msg.ModifyAsync(x => x.Embed = new EmbedBuilder()
await msg.ModifyAsync(x => x.Embed = _eb.Create()
.WithTitle(GetText("animal_race"))
.WithDescription(text)
.WithOkColor()
@@ -153,9 +153,9 @@ namespace NadekoBot.Modules.Gambling
var user = await ar.JoinRace(ctx.User.Id, ctx.User.ToString(), amount)
.ConfigureAwait(false);
if (amount > 0)
await ctx.Channel.SendConfirmAsync(GetText("animal_race_join_bet", ctx.User.Mention, user.Animal.Icon, amount + CurrencySign)).ConfigureAwait(false);
await SendConfirmAsync(GetText("animal_race_join_bet", ctx.User.Mention, user.Animal.Icon, amount + CurrencySign)).ConfigureAwait(false);
else
await ctx.Channel.SendConfirmAsync(GetText("animal_race_join", ctx.User.Mention, user.Animal.Icon)).ConfigureAwait(false);
await SendConfirmAsync(GetText("animal_race_join", ctx.User.Mention, user.Animal.Icon)).ConfigureAwait(false);
}
catch (ArgumentOutOfRangeException)
{
@@ -171,12 +171,12 @@ namespace NadekoBot.Modules.Gambling
}
catch (AnimalRaceFullException)
{
await ctx.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_full"))
await SendConfirmAsync(GetText("animal_race"), GetText("animal_race_full"))
.ConfigureAwait(false);
}
catch (NotEnoughFundsException)
{
await ctx.Channel.SendErrorAsync(GetText("not_enough", CurrencySign)).ConfigureAwait(false);
await SendErrorAsync(GetText("not_enough", CurrencySign)).ConfigureAwait(false);
}
}
}

View File

@@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Gambling
var cStr = string.Concat(c.Select(x => x.Substring(0, x.Length - 1) + " "));
cStr += "\n" + string.Concat(c.Select(x => x.Last() + " "));
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle("BlackJack")
.AddField($"{dealerIcon} Dealer's Hand | Value: {bj.Dealer.GetHandValue()}", cStr);

View File

@@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
public bool Stopped { get; private set; }
public bool PotEmptied { get; private set; } = false;
private readonly Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> _embedFunc;
private readonly Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> _embedFunc;
private readonly bool _isPotLimited;
private readonly ITextChannel _channel;
private readonly ConcurrentHashSet<ulong> _awardedUsers = new ConcurrentHashSet<ulong>();
@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
.ToArray();
public GameStatusEvent(DiscordSocketClient client, ICurrencyService cs,SocketGuild g, ITextChannel ch,
EventOptions opt, Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
EventOptions opt, Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embedFunc)
{
_client = client;
_guild = g;
@@ -126,7 +126,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
}
private EmbedBuilder GetEmbed(long pot)
private IEmbedBuilder GetEmbed(long pot)
{
return _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
}

View File

@@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
public bool Stopped { get; private set; }
public bool PotEmptied { get; private set; } = false;
private readonly Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> _embedFunc;
private readonly Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> _embedFunc;
private readonly bool _isPotLimited;
private readonly ITextChannel _channel;
private readonly ConcurrentHashSet<ulong> _awardedUsers = new ConcurrentHashSet<ulong>();
@@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
public ReactionEvent(DiscordSocketClient client, ICurrencyService cs,
SocketGuild g, ITextChannel ch, EventOptions opt, GamblingConfig config,
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embedFunc)
{
_client = client;
_guild = g;
@@ -130,7 +130,7 @@ namespace NadekoBot.Modules.Gambling.Common.Events
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
}
private EmbedBuilder GetEmbed(long pot)
private IEmbedBuilder GetEmbed(long pot)
{
return _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
}

View File

@@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Gambling
else
title = GetText("connect4_draw");
return msg.ModifyAsync(x => x.Embed = new EmbedBuilder()
return msg.ModifyAsync(x => x.Embed = _eb.Create()
.WithTitle(title)
.WithDescription(GetGameStateText(game))
.WithOkColor()
@@ -162,7 +162,7 @@ namespace NadekoBot.Modules.Gambling
private async Task Game_OnGameStateUpdated(Connect4Game game)
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle($"{game.CurrentPlayer.Username} vs {game.OtherPlayer.Username}")
.WithDescription(GetGameStateText(game))
.WithOkColor();

View File

@@ -45,18 +45,18 @@ namespace NadekoBot.Modules.Gambling
}
}
private EmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
{
switch (type)
{
case CurrencyEvent.Type.Reaction:
return new EmbedBuilder()
return _eb.Create()
.WithOkColor()
.WithTitle(GetText("event_title", type.ToString()))
.WithDescription(GetReactionDescription(opts.Amount, currentPot))
.WithFooter(GetText("event_duration_footer", opts.Hours));
case CurrencyEvent.Type.GameStatus:
return new EmbedBuilder()
return _eb.Create()
.WithOkColor()
.WithTitle(GetText("event_title", type.ToString()))
.WithDescription(GetGameStatusDescription(opts.Amount, currentPot))

View File

@@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Gambling
return;
async Task OnEnded(IUser arg, long won)
{
await ctx.Channel.SendConfirmAsync(GetText("rafflecur_ended", CurrencyName, Format.Bold(arg.ToString()), won + CurrencySign)).ConfigureAwait(false);
await SendConfirmAsync(GetText("rafflecur_ended", CurrencyName, Format.Bold(arg.ToString()), won + CurrencySign)).ConfigureAwait(false);
}
var res = await _service.JoinOrCreateGame(ctx.Channel.Id,
ctx.User, amount, mixed, OnEnded)
@@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Gambling
if (res.Item1 != null)
{
await ctx.Channel.SendConfirmAsync(GetText("rafflecur", res.Item1.GameType.ToString()),
await SendConfirmAsync(GetText("rafflecur", res.Item1.GameType.ToString()),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({x.Amount})")),
footer: GetText("rafflecur_joined", ctx.User.ToString())).ConfigureAwait(false);
}

View File

@@ -150,9 +150,11 @@ namespace NadekoBot.Modules.Gambling
{
rolls.Add(_fateRolls[rng.Next(0, _fateRolls.Length)]);
}
var embed = new EmbedBuilder().WithOkColor().WithDescription(ctx.User.Mention + " " + GetText("dice_rolled_num", Format.Bold(n1.ToString())))
.AddField(efb => efb.WithName(Format.Bold("Result"))
.WithValue(string.Join(" ", rolls.Select(c => Format.Code($"[{c}]")))));
var embed = _eb.Create()
.WithOkColor()
.WithDescription(ctx.User.Mention + " " + GetText("dice_rolled_num", Format.Bold(n1.ToString())))
.AddField(Format.Bold("Result"), string.Join(" ", rolls.Select(c => Format.Code($"[{c}]"))));
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
else if ((match = dndRegex.Match(arg)).Length != 0)
@@ -174,11 +176,13 @@ namespace NadekoBot.Modules.Gambling
}
var sum = arr.Sum();
var embed = new EmbedBuilder().WithOkColor().WithDescription(ctx.User.Mention + " " + GetText("dice_rolled_num", n1) + $"`1 - {n2}`")
.AddField(efb => efb.WithName(Format.Bold("Rolls"))
.WithValue(string.Join(" ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => Format.Code(x.ToString())))))
.AddField(efb => efb.WithName(Format.Bold("Sum"))
.WithValue(sum + " + " + add + " - " + sub + " = " + (sum + add - sub)));
var embed = _eb.Create().WithOkColor()
.WithDescription(ctx.User.Mention + " " + GetText("dice_rolled_num", n1) + $"`1 - {n2}`")
.AddField(Format.Bold("Rolls"), string.Join(" ",
(ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x =>
Format.Code(x.ToString()))))
.AddField(Format.Bold("Sum"),
sum + " + " + add + " - " + sub + " = " + (sum + add - sub));
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
}

View File

@@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Gambling
str = ctx.User.ToString() + " " + GetText("better_luck");
}
await ctx.Channel.EmbedAsync(new EmbedBuilder()
await ctx.Channel.EmbedAsync(_eb.Create()
.WithDescription(str)
.WithOkColor()
.WithImageUrl(imageToSend.ToString())).ConfigureAwait(false);

View File

@@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Gambling
onePercent = ec.OnePercent / (ec.Cash-ec.Bot); // This stops the top 1% from owning more than 100% of the money
// [21:03] Bob Page: Kinda remids me of US economy
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("economy_state"))
.AddField(GetText("currency_owned"), ((BigInteger)(ec.Cash - ec.Bot)) + CurrencySign)
.AddField(GetText("currency_one_percent"), (onePercent * 100).ToString("F2") + "%")
@@ -140,7 +140,7 @@ namespace NadekoBot.Modules.Gambling
return;
}
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await ctx.Channel.SendConfirmAsync("🎟 " + GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
await SendConfirmAsync("🎟 " + GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Gambling
return;
}
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await ctx.Channel.SendConfirmAsync("🎟 " + GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
await SendConfirmAsync("🎟 " + GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -195,7 +195,7 @@ namespace NadekoBot.Modules.Gambling
trs = uow.CurrencyTransactions.GetPageFor(userId, page);
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("transactions",
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString() ?? $"{userId}"))
.WithOkColor();
@@ -373,10 +373,12 @@ namespace NadekoBot.Modules.Gambling
if (amount <= 0)
return;
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle(GetText("roll_duel"));
var description = string.Empty;
var game = new RollDuelGame(_cs, _client.CurrentUser.Id, ctx.User.Id, u.Id, amount);
//means challenge is just created
if (_service.Duels.TryGetValue((ctx.User.Id, u.Id), out var other))
@@ -406,10 +408,11 @@ namespace NadekoBot.Modules.Gambling
async Task Game_OnGameTick(RollDuelGame arg)
{
var rolls = arg.Rolls.Last();
embed.Description += $@"{Format.Bold(ctx.User.ToString())} rolled **{rolls.Item1}**
description += $@"{Format.Bold(ctx.User.ToString())} rolled **{rolls.Item1}**
{Format.Bold(u.ToString())} rolled **{rolls.Item2}**
--
";
embed = embed.WithDescription(description);
if (rdMsg is null)
{
@@ -434,7 +437,10 @@ namespace NadekoBot.Modules.Gambling
var winner = rdGame.Winner == rdGame.P1
? ctx.User
: u;
embed.Description += $"\n**{winner}** Won {n(((long)(rdGame.Amount * 2 * 0.98))) + CurrencySign}";
description += $"\n**{winner}** Won {n(((long)(rdGame.Amount * 2 * 0.98))) + CurrencySign}";
embed = embed.WithDescription(description);
await rdMsg.ModifyAsync(x => x.Embed = embed.Build())
.ConfigureAwait(false);
}
@@ -485,7 +491,7 @@ namespace NadekoBot.Modules.Gambling
str += GetText("better_luck");
}
await ctx.Channel.SendConfirmAsync(str).ConfigureAwait(false);
await SendConfirmAsync(str).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -541,7 +547,7 @@ namespace NadekoBot.Modules.Gambling
await Context.SendPaginatedConfirmAsync(page, curPage =>
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle(CurrencySign + " " + GetText("leaderboard"));
@@ -615,7 +621,7 @@ namespace NadekoBot.Modules.Gambling
return "✂️";
}
}
var embed = new EmbedBuilder();
var embed = _eb.Create();
var nadekoPick = (RpsPick)new NadekoRandom().Next(0, 3);

View File

@@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Gambling.Services
}
public async Task<bool> TryCreateEventAsync(ulong guildId, ulong channelId, CurrencyEvent.Type type,
EventOptions opts, Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embed)
EventOptions opts, Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embed)
{
SocketGuild g = _client.GetGuild(guildId);
SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel;

View File

@@ -59,9 +59,9 @@ namespace NadekoBot.Modules.Gambling
var theseEntries = entries.Skip(curPage * 9).Take(9).ToArray();
if (!theseEntries.Any())
return new EmbedBuilder().WithErrorColor()
return _eb.Create().WithErrorColor()
.WithDescription(GetText("shop_none"));
var embed = new EmbedBuilder().WithOkColor()
var embed = _eb.Create().WithOkColor()
.WithTitle(GetText("shop", CurrencySign));
for (int i = 0; i < theseEntries.Length; i++)
@@ -172,7 +172,7 @@ namespace NadekoBot.Modules.Gambling
try
{
await (await ctx.User.GetOrCreateDMChannelAsync().ConfigureAwait(false))
.EmbedAsync(new EmbedBuilder().WithOkColor()
.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText("shop_purchase", ctx.Guild.Name))
.AddField(GetText("item"), item.Text, false)
.AddField(GetText("price"), entry.Price.ToString(), true)
@@ -428,9 +428,9 @@ namespace NadekoBot.Modules.Gambling
}
}
public EmbedBuilder EntryToEmbed(ShopEntry entry)
public IEmbedBuilder EntryToEmbed(ShopEntry entry)
{
var embed = new EmbedBuilder().WithOkColor();
var embed = _eb.Create().WithOkColor();
if (entry.Type == ShopEntryType.Role)
return embed.AddField(GetText("name"), GetText("shop_role", Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")), true)

View File

@@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Gambling
if (bet <= 0)
bet = 1;
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle("Slot Stats")
.AddField("Total Bet", bet.ToString(), true)
@@ -133,7 +133,7 @@ namespace NadekoBot.Modules.Gambling
sb.AppendLine($"x{key} occured {dict[key]} times. {dict[key] * 1.0f / tests * 100}%");
payout += key * dict[key];
}
await ctx.Channel.SendConfirmAsync("Slot Test Results", sb.ToString(),
await SendConfirmAsync("Slot Test Results", sb.ToString(),
footer: $"Total Bet: {tests * bet} | Payout: {payout * bet} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
}

View File

@@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Gambling
public async Task WaifuReset()
{
var price = _service.GetResetPrice(ctx.User);
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("waifu_reset_confirm"))
.WithDescription(GetText("waifu_reset_price", Format.Bold(price + CurrencySign)));
@@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Gambling
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign);
else
msg = " " + msg;
await ctx.Channel.SendConfirmAsync(ctx.User.Mention + msg);
await SendConfirmAsync(ctx.User.Mention + msg);
}
[NadekoCommand, Aliases]
@@ -221,7 +221,7 @@ namespace NadekoBot.Modules.Gambling
return;
}
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("waifus_top_waifus"))
.WithOkColor();
@@ -282,7 +282,7 @@ namespace NadekoBot.Modules.Gambling
if (string.IsNullOrWhiteSpace(fansStr))
fansStr = "-";
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithOkColor()
.WithTitle(GetText("waifu") + " " + (wi.FullName ?? name ?? targetId.ToString()) + " - \"the " +
_service.GetClaimTitle(wi.ClaimCount) + "\"")
@@ -312,7 +312,7 @@ namespace NadekoBot.Modules.Gambling
var waifuItems = _service.GetWaifuItems();
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
{
var embed = new EmbedBuilder()
var embed = _eb.Create()
.WithTitle(GetText("waifu_gift_shop"))
.WithOkColor();

View File

@@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Gambling
var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount).ConfigureAwait(false);
var wofMultipliers = _config.WheelOfFortune.Multipliers;
await ctx.Channel.SendConfirmAsync(
await SendConfirmAsync(
Format.Bold($@"{ctx.User.ToString()} won: {result.Amount + CurrencySign}
『{wofMultipliers[1]}』 『{wofMultipliers[0]}』 『{wofMultipliers[7]}』