Skip to content

Modernize to .NET 8 / Discord.Net 3.18 + add Permissions, Rules Cache, User Records - #1

Open
blubskye wants to merge 1 commit into
WaifuShork:mainfrom
blubskye:modernize-and-add-features
Open

blubskye wants to merge 1 commit into
WaifuShork:mainfrom
blubskye:modernize-and-add-features

Conversation

@blubskye

Copy link
Copy Markdown

Summary

This PR modernizes the boilerplate from its original .NET 5 / Discord.Net 2.4 state and adds the three features listed in the README TODO.

Modernization

  • Framework: net5.0 → net8.0
  • Discord.Net: 2.4.0 → 3.18.0 with mandatory GatewayIntents (MessageContent + GuildMembers — privileged, must be enabled in the Developer Portal)
  • Discord.Addons.Hosting: 4.0.2 → 6.1.0; migrated from deprecated IHostBuilder extensions (ConfigureDiscordHost, UseCommandService) to the new IServiceCollection API (AddDiscordHost, AddCommandService)
  • Discord.Addons.Interactive removed; replaced with Fergun.Interactive 1.9.1 (actively maintained fork) registered as an InteractiveService singleton
  • EF Core: 5.0.7 → 9.0.2 | Serilog: 2.x → 4.3.1 with updated sinks
  • DI lifetime mismatch fixed: AddDbContext → AddDbContextFactory<TemplateBotContext> so singleton services create/dispose their own short-lived contexts per operation
  • Removed broken async void Dispose pattern from GuildConfigs
  • Removed unused imports (SQLitePCL, EF Query.Internal, System.Net.Sockets)
  • Filled in all CommandHandler error switch cases (previously all TODOs)
  • TemplateModuleBase now inherits ModuleBase<SocketCommandContext> directly

Permissions system (role + user based)

  • BotPermission enum: None / Moderator / Admin
  • GuildRolePermission + GuildUserPermission EF entities
  • GuildPermissions repository: user-level overrides take precedence over role-level grants; guild owner always resolves to Admin
  • RequirePermissionLevelAttribute precondition (named to avoid conflict with Discord.Commands.RequireBotPermissionAttribute)
  • Commands (require Discord Administrator): !permit role/user, !revoke role/user, !permissions

Rules Cache

  • GuildRule entity; GuildRules repository with automatic contiguous renumbering on removal
  • RulesCacheService singleton — ConcurrentDictionary<ulong, List<GuildRule>> populated lazily per guild, invalidated on any write
  • Commands: !rules (public), !rules add/remove/edit (Moderator+)

User Records / moderation database

  • RecordType enum (Warning / Mute / Unmute / Kick / Ban / Unban)
  • UserRecord entity: guild, user, moderator, type, reason, timestamp
  • UserRecords repository
  • Commands: !warn @user <reason> (Moderator+), !history @user (Moderator+), !clearwarnings @user (Admin+)

Database migration

New migration AddPermissionsRulesAndRecords adds four tables: GuildRolePermissions, GuildUserPermissions, GuildRules, UserRecords.

Docs

README fully rewritten with setup instructions, Developer Portal steps, full command reference, extension guide, and package table.

Test plan

  • dotnet build passes with 0 errors, 0 warnings
  • Enable Server Members Intent and Message Content Intent in Developer Portal
  • dotnet run — bot connects and logs show no gateway intent errors
  • !ping returns Pong!
  • !permit role @SomeRole Moderator — success embed; !permissions shows the grant
  • !rules add No spamming — rule Modernize to .NET 8 / Discord.Net 3.18 + add Permissions, Rules Cache, User Records #1 added; !rules displays it
  • !rules remove 1 — rule removed; !rules shows empty
  • !warn @user test warning — warning embed shown; !history @user lists the record
  • !clearwarnings @user — clears warnings (requires Admin)

🤖 Generated with Claude Code

…he, User Records

## Modernization
- Upgrade target framework net5.0 → net8.0
- Discord.Net 2.4.0 → 3.18.0 with required GatewayIntents
  (MessageContent + GuildMembers — must enable in Developer Portal)
- Discord.Addons.Hosting 4.0.2 → 6.1.0; migrate from IHostBuilder
  extensions to IServiceCollection (AddDiscordHost, AddCommandService)
- Discord.Addons.Interactive removed; Fergun.Interactive 1.9.1 added
- EF Core 5.0.7 → 9.0.2; Serilog 2.x → 4.3.1 + updated sinks
- Fix DI lifetime mismatch: AddDbContext → AddDbContextFactory so
  singleton repositories create/dispose contexts per operation
- Remove broken async-void IDisposable from GuildConfigs
- Remove unused imports (SQLitePCL, EF Query.Internal, Net.Sockets)
- Fill in all CommandHandler error switch cases
- TemplateModuleBase now inherits ModuleBase<SocketCommandContext>

## Permissions system (role + user based)
- BotPermission enum: None / Moderator / Admin
- GuildRolePermission + GuildUserPermission entities
- GuildPermissions repository: user overrides > role max; owner = Admin
- RequirePermissionLevelAttribute precondition
- Commands: !permit role/user, !revoke role/user, !permissions

## Rules Cache
- GuildRule entity; GuildRules repository with auto-renumbering
- RulesCacheService singleton (ConcurrentDictionary, lazy-loaded,
  invalidated on write)
- Commands: !rules, !rules add/remove/edit (Moderator+)

## User Records / moderation database
- RecordType enum + UserRecord entity (Warning/Mute/Kick/Ban/…)
- UserRecords repository
- Commands: !warn, !history, !clearwarnings

## Database
- EF Core migration AddPermissionsRulesAndRecords adds four new tables:
  GuildRolePermissions, GuildUserPermissions, GuildRules, UserRecords

## Docs
- README rewritten with setup instructions, command reference,
  extension guide, and package table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant