diff --git a/bottomly.net/Bottomly.AppHost/.aspire/settings.json b/bottomly.net/Bottomly.AppHost/.aspire/settings.json
new file mode 100644
index 0000000..283e445
--- /dev/null
+++ b/bottomly.net/Bottomly.AppHost/.aspire/settings.json
@@ -0,0 +1,3 @@
+{
+ "appHostPath": "../Bottomly.AppHost.csproj"
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.AppHost/Properties/launchSettings.json b/bottomly.net/Bottomly.AppHost/Properties/launchSettings.json
new file mode 100644
index 0000000..abda127
--- /dev/null
+++ b/bottomly.net/Bottomly.AppHost/Properties/launchSettings.json
@@ -0,0 +1,31 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "https://localhost:17281;http://localhost:15221",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "DOTNET_ENVIRONMENT": "Development",
+ "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21226",
+ "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23133",
+ "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22202"
+ }
+ },
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "http://localhost:15221",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "DOTNET_ENVIRONMENT": "Development",
+ "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19053",
+ "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18014",
+ "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20264"
+ }
+ }
+ }
+}
diff --git a/bottomly.net/Bottomly.AppHost/apphost.run.json b/bottomly.net/Bottomly.AppHost/apphost.run.json
new file mode 100644
index 0000000..f293972
--- /dev/null
+++ b/bottomly.net/Bottomly.AppHost/apphost.run.json
@@ -0,0 +1,31 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "https://localhost:17219;http://localhost:15148",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "DOTNET_ENVIRONMENT": "Development",
+ "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21009",
+ "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23079",
+ "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22198"
+ }
+ },
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "http://localhost:15148",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "DOTNET_ENVIRONMENT": "Development",
+ "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19120",
+ "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18106",
+ "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20045"
+ }
+ }
+ }
+}
diff --git a/bottomly.net/Bottomly.AppHost/appsettings.Development.json b/bottomly.net/Bottomly.AppHost/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/bottomly.net/Bottomly.AppHost/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/bottomly.net/Bottomly.AppHost/appsettings.json b/bottomly.net/Bottomly.AppHost/appsettings.json
new file mode 100644
index 0000000..31c092a
--- /dev/null
+++ b/bottomly.net/Bottomly.AppHost/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning",
+ "Aspire.Hosting.Dcp": "Warning"
+ }
+ }
+}
diff --git a/bottomly.net/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj b/bottomly.net/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj
new file mode 100644
index 0000000..938db20
--- /dev/null
+++ b/bottomly.net/Bottomly.ServiceDefaults/Bottomly.ServiceDefaults.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net10.0
+ enable
+ enable
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bottomly.net/Bottomly.ServiceDefaults/Extensions.cs b/bottomly.net/Bottomly.ServiceDefaults/Extensions.cs
new file mode 100644
index 0000000..b3f7b27
--- /dev/null
+++ b/bottomly.net/Bottomly.ServiceDefaults/Extensions.cs
@@ -0,0 +1,129 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Diagnostics.HealthChecks;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Diagnostics.HealthChecks;
+using Microsoft.Extensions.Logging;
+using OpenTelemetry;
+using OpenTelemetry.Metrics;
+using OpenTelemetry.Trace;
+
+namespace Microsoft.Extensions.Hosting;
+
+// Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
+// This project should be referenced by each service project in your solution.
+// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
+public static class Extensions
+{
+ private const string HealthEndpointPath = "/health";
+ private const string AlivenessEndpointPath = "/alive";
+
+ public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder
+ {
+ builder.ConfigureOpenTelemetry();
+
+ builder.AddDefaultHealthChecks();
+
+ builder.Services.AddServiceDiscovery();
+
+ builder.Services.ConfigureHttpClientDefaults(http =>
+ {
+ // Turn on resilience by default
+ http.AddStandardResilienceHandler();
+
+ // Turn on service discovery by default
+ http.AddServiceDiscovery();
+ });
+
+ // Uncomment the following to restrict the allowed schemes for service discovery.
+ // builder.Services.Configure(options =>
+ // {
+ // options.AllowedSchemes = ["https"];
+ // });
+
+ return builder;
+ }
+
+ public static TBuilder ConfigureOpenTelemetry(this TBuilder builder)
+ where TBuilder : IHostApplicationBuilder
+ {
+ builder.Logging.AddOpenTelemetry(logging =>
+ {
+ logging.IncludeFormattedMessage = true;
+ logging.IncludeScopes = true;
+ });
+
+ builder.Services.AddOpenTelemetry()
+ .WithMetrics(metrics =>
+ {
+ metrics.AddAspNetCoreInstrumentation()
+ .AddHttpClientInstrumentation()
+ .AddRuntimeInstrumentation();
+ })
+ .WithTracing(tracing =>
+ {
+ tracing.AddSource(builder.Environment.ApplicationName)
+ .AddAspNetCoreInstrumentation(tracing =>
+ // Exclude health check requests from tracing
+ tracing.Filter = context =>
+ !context.Request.Path.StartsWithSegments(HealthEndpointPath)
+ && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
+ )
+ // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
+ //.AddGrpcClientInstrumentation()
+ .AddHttpClientInstrumentation();
+ });
+
+ builder.AddOpenTelemetryExporters();
+
+ return builder;
+ }
+
+ private static TBuilder AddOpenTelemetryExporters(this TBuilder builder)
+ where TBuilder : IHostApplicationBuilder
+ {
+ var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
+
+ if (useOtlpExporter)
+ {
+ builder.Services.AddOpenTelemetry().UseOtlpExporter();
+ }
+
+ // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
+ //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
+ //{
+ // builder.Services.AddOpenTelemetry()
+ // .UseAzureMonitor();
+ //}
+
+ return builder;
+ }
+
+ public static TBuilder AddDefaultHealthChecks(this TBuilder builder)
+ where TBuilder : IHostApplicationBuilder
+ {
+ builder.Services.AddHealthChecks()
+ // Add a default liveness check to ensure app is responsive
+ .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
+
+ return builder;
+ }
+
+ public static WebApplication MapDefaultEndpoints(this WebApplication app)
+ {
+ // Adding health checks endpoints to applications in non-development environments has security implications.
+ // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
+ if (app.Environment.IsDevelopment())
+ {
+ // All health checks must pass for app to be considered ready to accept traffic after starting
+ app.MapHealthChecks(HealthEndpointPath);
+
+ // Only health checks tagged with the "live" tag must pass for app to be considered alive
+ app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
+ {
+ Predicate = r => r.Tags.Contains("live")
+ });
+ }
+
+ return app;
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.Tests/Bottomly.Tests.csproj b/bottomly.net/Bottomly.Tests/Bottomly.Tests.csproj
new file mode 100644
index 0000000..3d5b464
--- /dev/null
+++ b/bottomly.net/Bottomly.Tests/Bottomly.Tests.csproj
@@ -0,0 +1,29 @@
+
+
+
+ net10.0
+ enable
+ enable
+ false
+ daba8c84-3cbb-425d-9103-50c95448cdb3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.Tests/Commands/AddKarmaCommandTests.cs b/bottomly.net/Bottomly.Tests/Commands/AddKarmaCommandTests.cs
new file mode 100644
index 0000000..87850ec
--- /dev/null
+++ b/bottomly.net/Bottomly.Tests/Commands/AddKarmaCommandTests.cs
@@ -0,0 +1,42 @@
+using Bottomly.Commands;
+using Bottomly.Models;
+using Bottomly.Repositories;
+using Moq;
+using Shouldly;
+
+namespace Bottomly.Tests.Commands;
+
+public class AddKarmaCommandTests
+{
+ private readonly AddKarmaCommand _command;
+ private readonly Mock _mockRepo = new();
+
+ public AddKarmaCommandTests() => _command = new AddKarmaCommand(_mockRepo.Object);
+
+ [Fact]
+ public async Task ExecuteAsync_AwardsKarma_PersistsToRepository()
+ {
+ _mockRepo.Setup(r => r.AddAsync(It.IsAny())).Returns(Task.CompletedTask);
+
+ await _command.ExecuteAsync("alice", "bob", "great job", KarmaType.PozzyPoz);
+
+ _mockRepo.Verify(r => r.AddAsync(It.Is(k =>
+ k.AwardedToUsername == "alice" &&
+ k.AwardedByUsername == "bob" &&
+ k.Reason == "great job" &&
+ k.KarmaType == KarmaType.PozzyPoz)), Times.Once());
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_SelfPositiveKarma_ThrowsInvalidOperation() =>
+ await Should.ThrowAsync(() =>
+ _command.ExecuteAsync("alice", "alice", "", KarmaType.PozzyPoz));
+
+ [Fact]
+ public async Task ExecuteAsync_SelfNegativeKarma_DoesNotThrow()
+ {
+ _mockRepo.Setup(r => r.AddAsync(It.IsAny())).Returns(Task.CompletedTask);
+
+ await Should.NotThrowAsync(() => _command.ExecuteAsync("alice", "alice", "", KarmaType.NeggyNeg));
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.Tests/Commands/GoogleImageSearchCommandTests.cs b/bottomly.net/Bottomly.Tests/Commands/GoogleImageSearchCommandTests.cs
new file mode 100644
index 0000000..6b23fe4
--- /dev/null
+++ b/bottomly.net/Bottomly.Tests/Commands/GoogleImageSearchCommandTests.cs
@@ -0,0 +1,20 @@
+using Bottomly.Commands;
+using Bottomly.Configuration;
+using Microsoft.Extensions.Options;
+using Shouldly;
+
+namespace Bottomly.Tests.Commands;
+
+public class GoogleImageSearchCommandTests
+{
+ [Fact]
+ public async Task ExecuteAsync_EmptyInput_ReturnsNull()
+ {
+ var options = Options.Create(new BottomlyOptions { GoogleApiKey = "key", GoogleCseId = "cse" });
+ var command = new GoogleImageSearchCommand(options);
+
+ var result = await command.ExecuteAsync("");
+
+ result.ShouldBeNull();
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.Tests/Commands/GoogleSearchCommandTests.cs b/bottomly.net/Bottomly.Tests/Commands/GoogleSearchCommandTests.cs
new file mode 100644
index 0000000..e5b8761
--- /dev/null
+++ b/bottomly.net/Bottomly.Tests/Commands/GoogleSearchCommandTests.cs
@@ -0,0 +1,20 @@
+using Bottomly.Commands;
+using Bottomly.Configuration;
+using Microsoft.Extensions.Options;
+using Shouldly;
+
+namespace Bottomly.Tests.Commands;
+
+public class GoogleSearchCommandTests
+{
+ [Fact]
+ public async Task ExecuteAsync_EmptyInput_ReturnsNull()
+ {
+ var options = Options.Create(new BottomlyOptions { GoogleApiKey = "key", GoogleCseId = "cse" });
+ var command = new GoogleSearchCommand(options);
+
+ var result = await command.ExecuteAsync("");
+
+ result.ShouldBeNull();
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly.Tests/Slack/SlackParserTests.cs b/bottomly.net/Bottomly.Tests/Slack/SlackParserTests.cs
new file mode 100644
index 0000000..cf99c7b
--- /dev/null
+++ b/bottomly.net/Bottomly.Tests/Slack/SlackParserTests.cs
@@ -0,0 +1,47 @@
+using Bottomly.Models;
+using Bottomly.Repositories;
+using Bottomly.Slack;
+using Moq;
+using Shouldly;
+
+namespace Bottomly.Tests.Slack;
+
+public class SlackParserTests
+{
+ private readonly Mock _mockMemberRepo = new();
+ private readonly SlackParser _parser;
+
+ public SlackParserTests() => _parser = new SlackParser(_mockMemberRepo.Object);
+
+ [Fact]
+ public async Task ReplaceSlackIdTokensWithUsernamesAsync_NoSlackIds_ReturnsUnchanged()
+ {
+ var message = "hello world";
+
+ var result = await _parser.ReplaceSlackIdTokensWithUsernamesAsync(message);
+
+ result.ShouldBe("hello world");
+ }
+
+ [Fact]
+ public async Task ReplaceSlackIdTokensWithUsernamesAsync_WithSlackId_ReplacesWithUsername()
+ {
+ _mockMemberRepo.Setup(r => r.GetBySlackIdAsync("U12345"))
+ .ReturnsAsync(new Member { Username = "alice", SlackId = "U12345" });
+
+ var result = await _parser.ReplaceSlackIdTokensWithUsernamesAsync("hello <@U12345>");
+
+ result.ShouldBe("hello alice");
+ }
+
+ [Fact]
+ public async Task ReplaceSlackIdTokensWithUsernamesAsync_SlackIdInLongMessage_ReplacesCorrectly()
+ {
+ _mockMemberRepo.Setup(r => r.GetBySlackIdAsync("U99999"))
+ .ReturnsAsync(new Member { Username = "bob", SlackId = "U99999" });
+
+ var result = await _parser.ReplaceSlackIdTokensWithUsernamesAsync("good work <@U99999> you did it");
+
+ result.ShouldBe("good work bob you did it");
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Commands/ReleaseCommand.cs b/bottomly.net/Bottomly/Commands/ReleaseCommand.cs
new file mode 100644
index 0000000..124b3fd
--- /dev/null
+++ b/bottomly.net/Bottomly/Commands/ReleaseCommand.cs
@@ -0,0 +1,42 @@
+using Bottomly.Configuration;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Octokit;
+
+namespace Bottomly.Commands;
+
+public class ReleaseCommand(IOptions options, ILogger logger)
+ : ICommand
+{
+ private readonly string _token = options.Value.GitHubToken;
+
+ public string GetPurpose() => "Describes the latest release of bottomly";
+
+ public virtual async Task ExecuteAsync()
+ {
+ try
+ {
+ var client = new GitHubClient(new ProductHeaderValue("bottomly"))
+ {
+ Credentials = new Credentials(_token)
+ };
+
+ var user = await client.User.Current();
+ var release = await client.Repository.Release.GetLatest(user.Login, "bottomly");
+
+ var desc = $"Latest Release: *{release.Name}* v{release.TagName}";
+ desc += $"\n_Published at {release.PublishedAt}_";
+ if (!string.IsNullOrEmpty(release.Body))
+ {
+ desc += $"\n{release.Body}";
+ }
+
+ return desc;
+ }
+ catch (Exception ex)
+ {
+ logger.LogError(ex, "Error retrieving release info from Github");
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Configuration/BottomlyOptions.cs b/bottomly.net/Bottomly/Configuration/BottomlyOptions.cs
new file mode 100644
index 0000000..0afe660
--- /dev/null
+++ b/bottomly.net/Bottomly/Configuration/BottomlyOptions.cs
@@ -0,0 +1,15 @@
+namespace Bottomly.Configuration;
+
+public class BottomlyOptions
+{
+ public string SlackBotToken { get; set; } = string.Empty;
+ public string SlackAppToken { get; set; } = string.Empty;
+ public string GoogleApiKey { get; set; } = string.Empty;
+ public string GoogleCseId { get; set; } = string.Empty;
+ public string Prefix { get; set; } = "!";
+ public string GiphyApiKey { get; set; } = string.Empty;
+ public string Environment { get; set; } = "live";
+ public string GitHubToken { get; set; } = string.Empty;
+
+ public bool IsDebug => Environment != "live";
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Models/Karma.cs b/bottomly.net/Bottomly/Models/Karma.cs
new file mode 100644
index 0000000..cff481c
--- /dev/null
+++ b/bottomly.net/Bottomly/Models/Karma.cs
@@ -0,0 +1,30 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Bottomly.Models;
+
+public class Karma
+{
+ public const int ExpiryDays = 30;
+
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]
+ public string? Id { get; set; }
+
+ [BsonElement("awarded_to_username")] public string AwardedToUsername { get; set; } = string.Empty;
+
+ [BsonElement("awarded_by_username")] public string AwardedByUsername { get; set; } = string.Empty;
+
+ [BsonElement("reason")] public string Reason { get; set; } = string.Empty;
+
+ [BsonElement("awarded")] public DateTime Awarded { get; set; }
+
+ [BsonElement("karma_type")] public string KarmaTypeValue { get; set; } = string.Empty;
+
+ [BsonIgnore]
+ public KarmaType KarmaType
+ {
+ get => KarmaTypeValue == nameof(KarmaType.PozzyPoz) ? KarmaType.PozzyPoz : KarmaType.NeggyNeg;
+ set => KarmaTypeValue = value.ToString();
+ }
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Models/KarmaType.cs b/bottomly.net/Bottomly/Models/KarmaType.cs
new file mode 100644
index 0000000..7f6bb15
--- /dev/null
+++ b/bottomly.net/Bottomly/Models/KarmaType.cs
@@ -0,0 +1,7 @@
+namespace Bottomly.Models;
+
+public enum KarmaType
+{
+ PozzyPoz = 1,
+ NeggyNeg = -1
+}
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Repositories/IKarmaRepository.cs b/bottomly.net/Bottomly/Repositories/IKarmaRepository.cs
new file mode 100644
index 0000000..da71998
--- /dev/null
+++ b/bottomly.net/Bottomly/Repositories/IKarmaRepository.cs
@@ -0,0 +1,16 @@
+using Bottomly.Models;
+
+namespace Bottomly.Repositories;
+
+public interface IKarmaRepository
+{
+ Task AddAsync(Karma karma);
+ Task GetCurrentNetKarmaAsync(string recipient);
+ Task GetKarmaReasonsAsync(string recipient);
+ Task> GetLeaderBoardAsync(int size = 3);
+ Task> GetLoserBoardAsync(int size = 3);
+}
+
+public record KarmaScore(string Username, int NetKarma);
+
+public record KarmaReasonsResult(int Reasonless, IReadOnlyList Reasoned);
\ No newline at end of file
diff --git a/bottomly.net/Bottomly/Slack/ReactionHandlers/IReactionHandler.cs b/bottomly.net/Bottomly/Slack/ReactionHandlers/IReactionHandler.cs
new file mode 100644
index 0000000..9b2e301
--- /dev/null
+++ b/bottomly.net/Bottomly/Slack/ReactionHandlers/IReactionHandler.cs
@@ -0,0 +1,9 @@
+using SlackNet.Events;
+
+namespace Bottomly.Slack.ReactionHandlers;
+
+public interface IReactionHandler
+{
+ bool CanHandle(ReactionAdded reactionEvent);
+ Task HandleAsync(ReactionAdded reactionEvent);
+}
\ No newline at end of file