- Added a simple bank system. Users can deposit, withdraw and check the balance of their currency in the bank.

- Users can't check other user's bank balances.
- Added a button on a .$ command which, when clicked, sends you a message with your bank balance that only you can see.
- Updated pagination, it now uses buttons instead of reactions
- using .h <command group> (atm only .bank is a proper group) will list commands with their descriptions in that group
This commit is contained in:
Kwoth
2022-04-29 06:47:00 +02:00
parent 3b6b3bcf07
commit f132aa2624
25 changed files with 10588 additions and 78 deletions

View File

@@ -121,7 +121,7 @@ public static class Extensions
args = strings.GetCommandStrings(cmd.Summary, culture).Args;
}
return args.Map(arg => GetFullUsage(cmd.Name, arg, prefix));
return args.Map(arg => GetFullUsage(cmd.Aliases.First(), arg, prefix));
}
private static string GetFullUsage(string commandName, string args, string prefix)

View File

@@ -2,53 +2,116 @@ namespace NadekoBot.Extensions;
public static class MessageChannelExtensions
{
public static Task<IUserMessage> EmbedAsync(
this IMessageChannel ch,
IEmbedBuilder embed,
string msg = "",
// main overload that all other send methods reduce to
public static Task<IUserMessage> SendAsync(
this IMessageChannel channel,
string? plainText,
Embed? embed = null,
IReadOnlyCollection<Embed>? embeds = null,
bool sanitizeAll = false,
MessageComponent? components = null)
=> ch.SendMessageAsync(msg,
embed: embed.Build(),
{
plainText = sanitizeAll
? plainText?.SanitizeAllMentions() ?? ""
: plainText?.SanitizeMentions() ?? "";
return channel.SendMessageAsync(plainText,
embed: embed,
embeds: embeds is null
? null
: embeds as Embed[] ?? embeds.ToArray(),
components: components,
options: new()
{
RetryMode = RetryMode.AlwaysRetry
});
}
public static async Task<IUserMessage> SendAsync(
this IMessageChannel channel,
string? plainText,
NadekoInteraction? inter,
Embed? embed = null,
IReadOnlyCollection<Embed>? embeds = null,
bool sanitizeAll = false)
{
var msg = await channel.SendAsync(plainText,
embed,
embeds,
sanitizeAll,
inter?.CreateComponent());
if (inter is not null)
await inter.RunAsync(msg);
return msg;
}
public static Task<IUserMessage> SendAsync(
this IMessageChannel channel,
string? plainText,
Embed? embed = null,
Embed[]? embeds = null,
SmartText text,
bool sanitizeAll = false)
{
plainText = sanitizeAll ? plainText?.SanitizeAllMentions() ?? "" : plainText?.SanitizeMentions() ?? "";
return channel.SendMessageAsync(plainText, embed: embed, embeds: embeds);
}
public static Task<IUserMessage> SendAsync(this IMessageChannel channel, SmartText text, bool sanitizeAll = false)
=> text switch
{
SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed().Build(), sanitizeAll: sanitizeAll),
SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll: sanitizeAll),
SmartEmbedText set => channel.SendAsync(set.PlainText,
set.GetEmbed().Build(),
sanitizeAll: sanitizeAll),
SmartPlainText st => channel.SendAsync(st.Text,
default(Embed),
sanitizeAll: sanitizeAll),
SmartEmbedTextArray arr => channel.SendAsync(arr.Content,
embeds: arr.GetEmbedBuilders().Map(e => e.Build())),
_ => throw new ArgumentOutOfRangeException(nameof(text))
};
// this is a huge problem, because now i don't have
// access to embed builder service
// as this is an extension of the message channel
public static Task<IUserMessage> SendErrorAsync(
public static Task<IUserMessage> EmbedAsync(
this IMessageChannel ch,
IEmbedBuilder? embed,
string plainText = "",
IReadOnlyCollection<IEmbedBuilder>? embeds = null,
NadekoInteraction? inter = null)
=> ch.SendAsync(plainText,
inter,
embed: embed?.Build(),
embeds: embeds?.Map(x => x.Build()));
public static Task<IUserMessage> SendAsync(
this IMessageChannel ch,
IEmbedBuilderService eb,
string text,
MessageType type,
NadekoInteraction? inter = null)
{
var builder = eb.Create().WithDescription(text);
builder = (type switch
{
MessageType.Error => builder.WithErrorColor(),
MessageType.Ok => builder.WithOkColor(),
MessageType.Pending => builder.WithPendingColor(),
_ => throw new ArgumentOutOfRangeException(nameof(type))
});
return ch.EmbedAsync(builder, inter: inter);
}
// regular send overloads
public static Task<IUserMessage> SendErrorAsync(this IMessageChannel ch, IEmbedBuilderService eb, string text)
=> ch.SendAsync(eb, text, MessageType.Error);
public static Task<IUserMessage> SendConfirmAsync(this IMessageChannel ch, IEmbedBuilderService eb, string text)
=> ch.SendAsync(eb, text, MessageType.Ok);
public static Task<IUserMessage> SendAsync(
this IMessageChannel ch,
IEmbedBuilderService eb,
MessageType type,
string title,
string error,
string text,
string? url = null,
string? footer = null)
{
var embed = eb.Create().WithErrorColor().WithDescription(error).WithTitle(title);
var embed = eb.Create().WithDescription(text).WithTitle(title);
if (url is not null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
embed.WithUrl(url);
@@ -56,15 +119,19 @@ public static class MessageChannelExtensions
if (!string.IsNullOrWhiteSpace(footer))
embed.WithFooter(footer);
return ch.SendMessageAsync("", embed: embed.Build());
embed = type switch
{
MessageType.Error => embed.WithErrorColor(),
MessageType.Ok => embed.WithOkColor(),
MessageType.Pending => embed.WithPendingColor(),
_ => throw new ArgumentOutOfRangeException(nameof(type))
};
return ch.EmbedAsync(embed);
}
public static Task<IUserMessage> SendErrorAsync(this IMessageChannel ch, IEmbedBuilderService eb, string error)
=> ch.SendMessageAsync("", embed: eb.Create().WithErrorColor().WithDescription(error).Build());
public static Task<IUserMessage> SendPendingAsync(this IMessageChannel ch, IEmbedBuilderService eb, string message)
=> ch.SendMessageAsync("", embed: eb.Create().WithPendingColor().WithDescription(message).Build());
// embed title and optional footer overloads
public static Task<IUserMessage> SendConfirmAsync(
this IMessageChannel ch,
IEmbedBuilderService eb,
@@ -72,21 +139,19 @@ public static class MessageChannelExtensions
string text,
string? url = null,
string? footer = null)
{
var embed = eb.Create().WithOkColor().WithDescription(text).WithTitle(title);
if (url is not null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
embed.WithUrl(url);
if (!string.IsNullOrWhiteSpace(footer))
embed.WithFooter(footer);
return ch.SendMessageAsync("", embed: embed.Build());
}
public static Task<IUserMessage> SendConfirmAsync(this IMessageChannel ch, IEmbedBuilderService eb, string text)
=> ch.SendMessageAsync("", embed: eb.Create().WithOkColor().WithDescription(text).Build());
=> ch.SendAsync(eb, MessageType.Ok, title, text, url, footer);
public static Task<IUserMessage> SendErrorAsync(
this IMessageChannel ch,
IEmbedBuilderService eb,
string title,
string text,
string? url = null,
string? footer = null)
=> ch.SendAsync(eb, MessageType.Error, title, text, url, footer);
// weird stuff
public static Task<IUserMessage> SendTableAsync<T>(
this IMessageChannel ch,
string seed,
@@ -142,7 +207,7 @@ public static class MessageChannelExtensions
var component = new ComponentBuilder()
.WithButton(new ButtonBuilder()
.WithStyle(ButtonStyle.Secondary)
.WithStyle(ButtonStyle.Primary)
.WithCustomId(BUTTON_LEFT)
.WithDisabled(lastPage == 0)
.WithEmote(_arrowLeft))
@@ -164,6 +229,9 @@ public static class MessageChannelExtensions
if (smc.Message.Id != msg.Id)
return;
if (smc.Data.CustomId != BUTTON_LEFT && smc.Data.CustomId != BUTTON_RIGHT)
return;
await si.DeferAsync();
if (smc.User.Id != ctx.User.Id)
@@ -210,12 +278,36 @@ public static class MessageChannelExtensions
await msg.ModifyAsync(mp => mp.Components = new ComponentBuilder().Build());
}
private static readonly Emoji _okEmoji = new Emoji("✅");
private static readonly Emoji _warnEmoji = new Emoji("⚠️");
private static readonly Emoji _errorEmoji = new Emoji("❌");
public static Task ReactAsync(this ICommandContext ctx, MessageType type)
{
var emoji = type switch
{
MessageType.Error => _errorEmoji,
MessageType.Pending => _warnEmoji,
MessageType.Ok => _okEmoji,
_ => throw new ArgumentOutOfRangeException(nameof(type)),
};
return ctx.Message.AddReactionAsync(emoji);
}
public static Task OkAsync(this ICommandContext ctx)
=> ctx.Message.AddReactionAsync(new Emoji("✅"));
=> ctx.ReactAsync(MessageType.Ok);
public static Task ErrorAsync(this ICommandContext ctx)
=> ctx.Message.AddReactionAsync(new Emoji("❌"));
=> ctx.ReactAsync(MessageType.Error);
public static Task WarningAsync(this ICommandContext ctx)
=> ctx.Message.AddReactionAsync(new Emoji("⚠️"));
=> ctx.ReactAsync(MessageType.Pending);
}
public enum MessageType
{
Ok,
Pending,
Error
}