HOLY SHIT IT WORKS!
This commit is contained in:
@@ -7,13 +7,12 @@ namespace Reactor.Commands
|
||||
public static class AddCommand
|
||||
{
|
||||
public static async Task Execute(
|
||||
ValourClient client,
|
||||
Dictionary<long, Channel> channelCache,
|
||||
long channelId,
|
||||
long messageId,
|
||||
string emoji,
|
||||
long roleId,
|
||||
ValourClient client,
|
||||
Planet planet)
|
||||
long roleId)
|
||||
{
|
||||
//Check if the current channel is in the cache (should never happen but you never know!)
|
||||
if (!channelCache.TryGetValue(channelId, out var channel))
|
||||
@@ -40,12 +39,14 @@ namespace Reactor.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the emoji to the message
|
||||
//Add the emoji to the message
|
||||
await message.AddReactionAsync(emoji);
|
||||
|
||||
//Add reaction-role mapping to DB and Cache
|
||||
await ReactionRoleService.AddReactionAsync(messageId, emoji, roleId);
|
||||
|
||||
ReactionRoleService.SubscribeToMessageReactions(client, channelCache, message);
|
||||
|
||||
await channel.SendMessageAsync($"Added reaction {emoji} -> role {roleId} for message {messageId}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,12 +61,6 @@ namespace Reactor.Commands
|
||||
Reactions = new Dictionary<string, long>()
|
||||
};
|
||||
|
||||
//Subscribe events
|
||||
// sentMessage.ReactionAdded += async () =>
|
||||
// {
|
||||
// await ReactionRoleService.HandleReactionAddedAsync(channelCache, sentMessage);
|
||||
// };
|
||||
|
||||
Console.WriteLine($"Created reaction message {sentMessage.Id} in channel {channelId}");
|
||||
}
|
||||
}
|
||||
|
||||
47
Commands/DeleteCommand.cs
Normal file
47
Commands/DeleteCommand.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Reactor.Services;
|
||||
using Valour.Sdk.Client;
|
||||
using Valour.Sdk.Models;
|
||||
|
||||
namespace Reactor.Commands
|
||||
{
|
||||
public static class DeleteCommand
|
||||
{
|
||||
public static async Task Execute(
|
||||
ValourClient client,
|
||||
Dictionary<long, Channel> channelCache,
|
||||
long channelId,
|
||||
long messageId)
|
||||
{
|
||||
//Check if channel in cache
|
||||
if (!channelCache.TryGetValue(channelId, out var channel))
|
||||
{
|
||||
Console.WriteLine($"Channel {channelId} not found in cache.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if message is actually a reaction message
|
||||
if (!ReactionRoleService.Messages.TryGetValue(messageId, out var reactionMsg))
|
||||
{
|
||||
await channel.SendMessageAsync($"Message ID {messageId} is not tracked as a reaction message.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Delete the actual message
|
||||
var recentMessages = await channel.GetLastMessagesAsync(50);
|
||||
var message = recentMessages.FirstOrDefault(m => m.Id == messageId);
|
||||
if (message != null)
|
||||
{
|
||||
await message.DeleteAsync();
|
||||
} else
|
||||
{
|
||||
Console.WriteLine($"Message {messageId} not found in recent messages, skipping deletion of message.");
|
||||
}
|
||||
|
||||
//Remove from cache and database
|
||||
await ReactionRoleService.RemoveMessageAsync(messageId);
|
||||
ReactionRoleService.ResetSubscription(messageId);
|
||||
|
||||
await channel.SendMessageAsync($"Deleted reaction message {messageId} and all its role mappings.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ public static class HelpCommand
|
||||
- `{prefix}help` - Shows this list.
|
||||
- `{prefix}source` - Shows my source code!
|
||||
- `{prefix}create` - Creates the Reaction Message.
|
||||
- `{prefix}delete` - Deletes a Reaction Message.
|
||||
- `{prefix}add` - Adds a Reaction Role to a Valid Message.
|
||||
- `{prefix}remove` - Removes a Reaction Role from a Valid Message.
|
||||
";
|
||||
|
||||
if (channelCache.TryGetValue(channelId, out var channel))
|
||||
|
||||
50
Commands/RemoveCommand.cs
Normal file
50
Commands/RemoveCommand.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Reactor.Services;
|
||||
using Valour.Sdk.Client;
|
||||
using Valour.Sdk.Models;
|
||||
|
||||
namespace Reactor.Commands
|
||||
{
|
||||
public static class RemoveCommand
|
||||
{
|
||||
public static async Task Execute(
|
||||
ValourClient client,
|
||||
Dictionary<long, Channel> channelCache,
|
||||
long channelId,
|
||||
long messageId,
|
||||
string emoji)
|
||||
{
|
||||
//Check if channel in cache
|
||||
if (!channelCache.TryGetValue(channelId, out var channel))
|
||||
{
|
||||
Console.WriteLine($"Channel {channelId} not found in cache.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if message is actually a reaction message
|
||||
if (!ReactionRoleService.Messages.TryGetValue(messageId, out var reactionMsg))
|
||||
{
|
||||
await channel.SendMessageAsync($"Message ID {messageId} is not tracked as a reaction message.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the emoji is actually a valid reaction on the message
|
||||
if (!reactionMsg.Reactions.ContainsKey(emoji))
|
||||
{
|
||||
await channel.SendMessageAsync($"Emoji {emoji} is not mapped to any role on message {messageId}.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Fetch the message and remove the reaction
|
||||
var recentMessages = await channel.GetLastMessagesAsync(50);
|
||||
var message = recentMessages.FirstOrDefault(m => m.Id == messageId);
|
||||
if (message != null)
|
||||
{
|
||||
await message.RemoveReactionAsync(emoji);
|
||||
}
|
||||
|
||||
await ReactionRoleService.RemoveReactionAsync(messageId, emoji);
|
||||
|
||||
await channel.SendMessageAsync($"Removed reaction {emoji} from message {messageId}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user