108 lines
3.6 KiB
C#
108 lines
3.6 KiB
C#
namespace FluxPose.DiscordBot.Experimenting;
|
|
|
|
public class SlashCommands(Actions<ApplicationCommandContext> experimentingActions, Users.Actions<ApplicationCommandContext> usersActions, Roles.Actions<ApplicationCommandContext> rolesActions, GatewayClient client) : ApplicationCommandModule<ApplicationCommandContext>
|
|
{
|
|
[SlashCommand("randomuser", "Get a random user from the server")]
|
|
public async Task<string> GetRandomUserCommand()
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
var randomUser = await experimentingActions.GetRandomUserFromGuild();
|
|
|
|
if (randomUser == null)
|
|
{
|
|
return $"Found no users :(";
|
|
}
|
|
|
|
return $"Here's a random user: {randomUser.Username}";
|
|
}
|
|
|
|
[SlashCommand("getroles", "Get all roles on the server")]
|
|
public async Task<string> GetRolesCommand()
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
|
|
var roles = await rolesActions.GetRolesFromGuild();
|
|
|
|
roles = [.. roles.Where(role => !role.Name.StartsWith('@'))];
|
|
|
|
if (roles.Count == 0)
|
|
{
|
|
return $"Found no roles :(";
|
|
}
|
|
|
|
return $"Roles in the server:\n{String.Join("\n", roles.Select(role => $"- {role.Id}: {role.Name}"))}";
|
|
}
|
|
|
|
[SlashCommand("giveroletouser", "Give a role")]
|
|
public async Task<string> GiveRoleToAllUsersCommand(string userId, string roleId)
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
|
|
var parsed = ulong.TryParse(userId, out ulong userIdParsed);
|
|
if (!parsed)
|
|
{
|
|
return "Invalid roleId";
|
|
}
|
|
|
|
parsed = ulong.TryParse(roleId, out ulong roleIdParsed);
|
|
if (!parsed)
|
|
{
|
|
return "Invalid roleId";
|
|
}
|
|
|
|
await rolesActions.GiveRoleToUser(userIdParsed, roleIdParsed);
|
|
|
|
return "Done.";
|
|
}
|
|
|
|
[SlashCommand("removerolefromallusers", "Remove role from all users on the server")]
|
|
public async Task<string> RemoveRoleFromAllUsersCommand(string roleId)
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
|
|
var parsed = ulong.TryParse(roleId, out ulong roleIdParsed);
|
|
if (!parsed)
|
|
{
|
|
return "Invalid roleId";
|
|
}
|
|
|
|
await experimentingActions.RemoveRoleFromAllUsers(roleIdParsed);
|
|
|
|
return "Done.";
|
|
}
|
|
|
|
[SlashCommand("defer", "Defer")]
|
|
public async Task DeferCommand()
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
await Context.Interaction.ModifyResponseAsync(message => message.WithContent("Sup"));
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
await Context.Interaction.ModifyResponseAsync(message => message.WithContent("Sup bitches"));
|
|
}
|
|
|
|
[SlashCommand("button", "Gives a button")]
|
|
public async Task ButtonCommand()
|
|
{
|
|
await Context.Interaction.SendResponseAsync(InteractionCallback.DeferredMessage());
|
|
|
|
var emojis = await experimentingActions.GetAllGuildEmoji();
|
|
|
|
EmojiProperties? emoji = null;
|
|
if (emojis.Count > 0)
|
|
{
|
|
emoji = EmojiProperties.Custom(emojis[new Random().Next(emojis.Count)].Id);
|
|
}
|
|
|
|
var button = new ButtonProperties("testButton", "Click Me!", emoji!, ButtonStyle.Primary);
|
|
|
|
var component = new ActionRowProperties([button]);
|
|
|
|
await Context.Interaction.ModifyResponseAsync(message => message.WithContent("Here's a button").WithComponents([component]));
|
|
}
|
|
}
|