Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CB.Accessors/Contracts/IFunAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CB.Accessors.Contracts;

public interface IFunAccessor
{
Task<int> IncrementHaiBai();
}
19 changes: 19 additions & 0 deletions src/CB.Accessors/Implementations/FunAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CB.Accessors.Contracts;
using CB.Data;
using CB.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class FunAccessor(CbContext context) : IFunAccessor
{
public async Task<int> IncrementHaiBai()
{
var result = await context
.FunStuff
.FromSqlRaw("UPDATE \"FunStuff\" SET \"HaiBaiCount\" = \"HaiBaiCount\" + 1 RETURNING \"HaiBaiCount\"")
.ToListAsync();

return result.First().HaiBaiCount;
}
}
25 changes: 25 additions & 0 deletions src/CB.Bot/Commands/Application/FunSlashCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Security.Cryptography;
using CB.Accessors.Contracts;
using Discord.Interactions;

namespace CB.Bot.Commands.Application;

public class FunSlashCommands(IFunAccessor funAccessor) : InteractionModuleBase
{
[SlashCommand("roll", "Roll a D20")]
public async Task RollAsync()
{
var rollResult = RandomNumberGenerator.GetInt32(1, 21);
await RespondAsync($"You rolled a {rollResult}!");
}

[SlashCommand("haibai", "They comes .. they goes ..")]
public async Task HaiBaiAsync()
{
var haiBaiCount = await funAccessor.IncrementHaiBai();

await RespondAsync(
$"_ _" +
$"[`HaiBai Count: {haiBaiCount}`](https://cdn.discordapp.com/attachments/313015271566868480/502228420881678336/couch.gif?ex=6882a2aa&is=6881512a&hm=8541f1b54df685b3ee50627db3c2c1fae730e371d3e4fd7d78eadb40a1d1102f&)");
}
}
1 change: 1 addition & 0 deletions src/CB.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
builder.Services.AddScoped<IDiscordLiveConfigurationAccessor, DiscordLiveConfigurationAccessor>();
builder.Services.AddScoped<IDropdownPayloadAccessor, DropdownPayloadAccessor>();
builder.Services.AddScoped<IFilterAccessor, FilterAccessor>();
builder.Services.AddScoped<IFunAccessor, FunAccessor>();
builder.Services.AddScoped<IGuildAccessor, GuildAccessor>();
builder.Services.AddScoped<IGuildConfigurationAccessor, GuildConfigurationAccessor>();
builder.Services.AddScoped<ILiveEmbedAccessor, LiveEmbedAccessor>();
Expand Down
7 changes: 7 additions & 0 deletions src/CB.Data/CbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CbContext(DbContextOptions<CbContext> options) : DbContext(options)
public DbSet<DiscordLiveConfiguration> DiscordLiveConfigurations => Set<DiscordLiveConfiguration>();
public DbSet<DropdownPayload> DropdownPayloads => Set<DropdownPayload>();
public DbSet<Filter> Filters => Set<Filter>();
public DbSet<FunStuff> FunStuff => Set<FunStuff>();
public DbSet<Game> Games => Set<Game>();
public DbSet<GameChannel> GameChannels => Set<GameChannel>();
public DbSet<Guild> Guilds => Set<Guild>();
Expand Down Expand Up @@ -114,6 +115,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
new FilterType { Id = 2, DisplayName = "Title" }
);

// Configure FunStuff table
modelBuilder.Entity<FunStuff>()
.HasNoKey()
.Property(f => f.HaiBaiCount)
.HasDefaultValue(0);

// Configure GameChannels table
modelBuilder.Entity<GameChannel>()
.HasKey(cc => new { cc.GameId, cc.ChannelId });
Expand Down
6 changes: 6 additions & 0 deletions src/CB.Data/Entities/FunStuff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CB.Data.Entities;

public class FunStuff
{
public int HaiBaiCount { get; set; } = 0;
}
Loading
Loading