58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using SkyBot.Helpers;
|
|
using SkyBot.Models;
|
|
|
|
namespace SkyBot.Commands
|
|
{
|
|
public class React : ICommand
|
|
{
|
|
public string Name => "react";
|
|
public string[] Aliases => [];
|
|
public string Description => "Adds a reaction to a replied message.";
|
|
public string Category => "Dev";
|
|
public string Usage => "dev <emoji> [amount]";
|
|
public string[] SubCommands => [];
|
|
|
|
public async Task Execute(CommandContext ctx)
|
|
{
|
|
if (!ctx.ChannelCache.TryGetValue(ctx.Channel.Id, out var channel)) return;
|
|
|
|
if (!PermissionHelper.IsOwner(ctx.Member))
|
|
{
|
|
await MessageHelper.ReplyAsync(ctx, "You do not have permission to execute this command.");
|
|
return;
|
|
}
|
|
|
|
if (ctx.Args.Length < 1)
|
|
{
|
|
await MessageHelper.ReplyAsync(ctx, $"Usage: `{Config.Prefix}react <emoji> [amount]");
|
|
return;
|
|
}
|
|
|
|
string emoji = ctx.Args[0];
|
|
|
|
int amount = 1;
|
|
if (ctx.Args.Length >= 2 && !int.TryParse(ctx.Args[1], out amount))
|
|
{
|
|
await MessageHelper.ReplyAsync(ctx, $"`{ctx.Args[1]}` is not a valid number. Defaulting to `1`");
|
|
amount = 1;
|
|
}
|
|
|
|
if (ctx.Message.ReplyToId is not long replyToId)
|
|
{
|
|
await MessageHelper.ReplyAsync(ctx, "Please reply to the message you want to add the reaction to.");
|
|
return;
|
|
}
|
|
if (!ctx.Client.Cache.Messages.TryGet(replyToId, out var replyMsg))
|
|
{
|
|
await MessageHelper.ReplyAsync(ctx, "Could not find the replied message in cache.");
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < amount; i++)
|
|
{
|
|
await replyMsg!.AddReactionAsync(emoji);
|
|
}
|
|
await ctx.Message.AddReactionAsync("👍");
|
|
}
|
|
}
|
|
} |