I am a failure :c

This commit is contained in:
2026-03-01 03:39:44 +00:00
parent df122f1470
commit fda66681b6
6 changed files with 263 additions and 0 deletions

52
Commands/AddCommand.cs Normal file
View File

@@ -0,0 +1,52 @@
using Reactor.Services;
using Valour.Sdk.Client;
using Valour.Sdk.Models;
namespace Reactor.Commands
{
public static class AddCommand
{
public static async Task Execute(
Dictionary<long, Channel> channelCache,
long channelId,
long messageId,
string emoji,
long roleId,
ValourClient client,
Planet planet)
{
//Check if the current channel is in the cache (should never happen but you never know!)
if (!channelCache.TryGetValue(channelId, out var channel))
{
Console.WriteLine($"Channel {channelId} not found in cache.");
return;
}
//Check if the message id is a valid reaction message
if (!ReactionRoleService.Messages.TryGetValue(messageId, out var reactionMsg))
{
await channel.SendMessageAsync($"Message ID {messageId} is not tracked as a reaction message.");
return;
}
//Fetch recent messages
var recentMessages = await channel.GetLastMessagesAsync(50);
//Try and find the message inside those recent messages
var message = recentMessages.FirstOrDefault(m => m.Id == messageId);
if (message == null)
{
await channel.SendMessageAsync("Could not find the message in the last 50 messages.");
return;
}
// Add the emoji to the message
await message.AddReactionAsync(emoji);
//Add reaction-role mapping to DB and Cache
await ReactionRoleService.AddReactionAsync(messageId, emoji, roleId);
await channel.SendMessageAsync($"Added reaction {emoji} -> role {roleId} for message {messageId}");
}
}
}

73
Commands/CreateCommand.cs Normal file
View File

@@ -0,0 +1,73 @@
using Microsoft.Data.Sqlite;
using Reactor.Services;
using Valour.Sdk.Client;
using Valour.Sdk.Models;
namespace Reactor.Commands
{
public static class CreateCommand
{
//Sends a new Reaction Role Message and Stores it
public static async Task Execute(
ValourClient client,
Dictionary<long, Channel> channelCache,
long channelId,
string content,
long planetId,
int deleteDelaySeconds = 5)
{
if (!channelCache.TryGetValue(channelId, out var channel))
{
Console.WriteLine($"Channel {channelId} not found in cache.");
return;
}
//Send the Message
var result = await channel.SendMessageAsync(content);
if (!result.Success || result.Data == null)
{
Console.WriteLine("Failed to send message.");
return;
}
var sentMessage = result.Data;
await channel.SendMessageAsync($"This Reaction Message has the ID of: {sentMessage.Id}");
//Insert into DB
using var connection = new SqliteConnection("Data Source=reactor.db");
await connection.OpenAsync();
var cmd = connection.CreateCommand();
cmd.CommandText = @"
INSERT INTO ReactionMessages (PlanetId, ChannelId, MessageId, DeleteDelaySeconds)
VALUES (@planetId, @channelId, @messageId, @delay);
SELECT last_insert_rowid();
";
cmd.Parameters.AddWithValue("@planetId", planetId);
cmd.Parameters.AddWithValue("@channelId", channelId);
cmd.Parameters.AddWithValue("@messageId", sentMessage.Id);
cmd.Parameters.AddWithValue("@delay", deleteDelaySeconds);
var insertedId = (long)await cmd.ExecuteScalarAsync();
//Add to memory
ReactionRoleService.Messages[sentMessage.Id] = new Models.ReactionMessage
{
Id = insertedId,
PlanetId = planetId,
ChannelId = channelId,
MessageId = sentMessage.Id,
DeleteDelaySeconds = deleteDelaySeconds,
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}");
}
}
}

View File

@@ -9,6 +9,7 @@ public static class HelpCommand
string helpMessage = $@"**Reactor Commands**:
- `{prefix}help` - Shows this list.
- `{prefix}source` - Shows my source code!
- `{prefix}create` - Creates the Reaction Message.
";
if (channelCache.TryGetValue(channelId, out var channel))