Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Mar 20, 2024
2 parents f525288 + d6fe6fb commit ff498df
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Add NuGet source
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Add GitHub NuGet source
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Add GitHub NuGet source
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
Expand Down
15 changes: 13 additions & 2 deletions Marco/Commands/MacroCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ namespace Marco.Commands;
internal sealed class MacroCommand : ApplicationCommandModule
{
private readonly MacroService _macroService;
private readonly MacroCooldownService _cooldownService;

/// <summary>
/// Initializes a new instance of the <see cref="MacroCommand" /> class.
/// </summary>
/// <param name="macroService">The macro service.</param>
public MacroCommand(MacroService macroService)
/// <param name="cooldownService">The cooldown service.</param>
public MacroCommand(MacroService macroService, MacroCooldownService cooldownService)
{
_macroService = macroService;
_cooldownService = cooldownService;
}

[SlashCommand("macro", "Executes a macro.")]
Expand All @@ -32,11 +35,18 @@ public async Task MacroAsync(InteractionContext context,
return;
}

if (macro.ChannelId.HasValue && macro.ChannelId.Value != context.Channel.Id)
DiscordChannel channel = context.Channel;

if (macro.ChannelId.HasValue && macro.ChannelId.Value != channel.Id)
{
await context.CreateResponseAsync($"The macro `{macroName}` cannot be executed here.", true).ConfigureAwait(false);
return;
}
if (_cooldownService.IsOnCooldown(channel, macro))
{
await context.CreateResponseAsync($"The macro `{macroName}` is on cooldown because it was very recently executed.", true).ConfigureAwait(false);
return;
}

var builder = new DiscordInteractionResponseBuilder();
string response = macro.Response;
Expand All @@ -49,5 +59,6 @@ public async Task MacroAsync(InteractionContext context,

builder.WithContent(response);
await context.CreateResponseAsync(builder).ConfigureAwait(false);
_cooldownService.UpdateCooldown(channel, macro);
}
}
39 changes: 0 additions & 39 deletions Marco/Logging/ColorfulConsoleTarget.cs

This file was deleted.

40 changes: 0 additions & 40 deletions Marco/Logging/LogFileTarget.cs

This file was deleted.

18 changes: 10 additions & 8 deletions Marco/Marco.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<VersionPrefix>2.1.1</VersionPrefix>
<VersionPrefix>2.2.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
Expand All @@ -32,15 +32,17 @@
<PackageReference Include="DSharpPlus.Interactivity" Version="5.0.0-nightly-01574"/>
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01574"/>
<PackageReference Include="Humanizer.Core" Version="2.14.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.5"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1"/>
<PackageReference Include="NLog" Version="5.1.4"/>
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3"/>
<PackageReference Include="SmartFormat.NET" Version="3.2.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
<PackageReference Include="Serilog" Version="3.1.1"/>
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1"/>
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
<PackageReference Include="SmartFormat.NET" Version="3.3.2"/>
<PackageReference Include="X10D" Version="4.0.0-nightly.236"/>
<PackageReference Include="X10D.DSharpPlus" Version="4.0.0-nightly.236"/>
<PackageReference Include="X10D.Hosting" Version="4.0.0-nightly.236"/>
Expand Down
67 changes: 35 additions & 32 deletions Marco/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,42 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;
using X10D.Hosting.DependencyInjection;

Directory.CreateDirectory("data");

await Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder => builder.AddJsonFile("data/config.json", true, true))
.ConfigureLogging(builder =>
{
builder.ClearProviders();
builder.AddNLog();
})
.ConfigureServices(services =>
{
services.AddSingleton(new DiscordClient(new DiscordConfiguration
{
Token = Environment.GetEnvironmentVariable("DISCORD_TOKEN"),
LoggerFactory = new NLogLoggerFactory(),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.GuildMessages | DiscordIntents.MessageContents
}));
services.AddHostedSingleton<LoggingService>();
services.AddSingleton<HttpClient>();
services.AddSingleton<ConfigurationService>();
services.AddSingleton<MacroCooldownService>();
services.AddHostedSingleton<MacroListeningService>();
services.AddHostedSingleton<MacroService>();
services.AddDbContext<MarcoContext>();
services.AddHostedSingleton<BotService>();
})
.UseConsoleLifetime()
.RunConsoleAsync();
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
#if DEBUG
.MinimumLevel.Debug()
#endif
.CreateLogger();

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Configuration.AddJsonFile("data/config.json", true, true);
builder.Logging.ClearProviders();
builder.Logging.AddSerilog();

builder.Services.AddSingleton(new DiscordClient(new DiscordConfiguration
{
Token = Environment.GetEnvironmentVariable("DISCORD_TOKEN"),

Check warning on line 29 in Marco/Program.cs

View workflow job for this annotation

GitHub Actions / Build & Test

Possible null reference assignment.

Check warning on line 29 in Marco/Program.cs

View workflow job for this annotation

GitHub Actions / Build & Test

Possible null reference assignment.

Check warning on line 29 in Marco/Program.cs

View workflow job for this annotation

GitHub Actions / Tagged Release

Possible null reference assignment.

Check warning on line 29 in Marco/Program.cs

View workflow job for this annotation

GitHub Actions / Tagged Release

Possible null reference assignment.
LoggerFactory = new SerilogLoggerFactory(),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.GuildMessages | DiscordIntents.MessageContents
}));

builder.Services.AddSingleton<HttpClient>();
builder.Services.AddSingleton<ConfigurationService>();
builder.Services.AddSingleton<MacroCooldownService>();

builder.Services.AddHostedSingleton<MacroListeningService>();
builder.Services.AddHostedSingleton<MacroService>();

builder.Services.AddDbContext<MarcoContext>();

builder.Services.AddHostedSingleton<BotService>();

IHost app = builder.Build();
await app.RunAsync();
Loading

0 comments on commit ff498df

Please sign in to comment.