mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-06 05:56:29 +03:00
Tidy up project structure, fix bug with edit logging (#47)
The project structure has been changed because the previous one had everything in 1 folder. From this PR onwards, the following is true: - The source code is stored in `src/` - `*.resx` and `Messages.Designer.cs` is stored in `locale/` - Documentation is stored on the wiki and in `docs/` - Miscellaneous files, such as dotfiles, are stored in the root folder of the repository This PR additionally fixes an issue that would cause logs of edited messages to not be syntax highlighted. This happened because the responder of edited messages was changed to use the universal `InBlockCode` extension method which did not support syntax highlighting until this PR This PR additionally changes CODEOWNERS to be more reliable. Previously, it would be possible for some PRs to be unable to be approved because the only person who can approve them is the same person who opened the PR. --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
2dd9f023ef
commit
3eb17b96c5
29 changed files with 180 additions and 179 deletions
96
src/Boyfriend.cs
Normal file
96
src/Boyfriend.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using Boyfriend.Commands;
|
||||
using Boyfriend.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Remora.Commands.Extensions;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Commands;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Caching.Extensions;
|
||||
using Remora.Discord.Caching.Services;
|
||||
using Remora.Discord.Commands.Extensions;
|
||||
using Remora.Discord.Commands.Services;
|
||||
using Remora.Discord.Gateway;
|
||||
using Remora.Discord.Gateway.Extensions;
|
||||
using Remora.Discord.Hosting.Extensions;
|
||||
using Remora.Discord.Interactivity.Extensions;
|
||||
using Remora.Rest.Core;
|
||||
|
||||
namespace Boyfriend;
|
||||
|
||||
public class Boyfriend {
|
||||
public static readonly AllowedMentions NoMentions = new(
|
||||
Array.Empty<MentionType>(), Array.Empty<Snowflake>(), Array.Empty<Snowflake>());
|
||||
|
||||
public static async Task Main(string[] args) {
|
||||
var host = CreateHostBuilder(args).UseConsoleLifetime().Build();
|
||||
var services = host.Services;
|
||||
|
||||
var slashService = services.GetRequiredService<SlashService>();
|
||||
// Providing a guild ID to this call will result in command duplicates!
|
||||
// To get rid of them, provide the ID of the guild containing duplicates,
|
||||
// comment out calls to WithCommandGroup in CreateHostBuilder
|
||||
// then launch the bot again and remove the guild ID
|
||||
await slashService.UpdateSlashCommandsAsync();
|
||||
|
||||
await host.RunAsync();
|
||||
}
|
||||
|
||||
private static IHostBuilder CreateHostBuilder(string[] args) {
|
||||
return Host.CreateDefaultBuilder(args)
|
||||
.AddDiscordService(
|
||||
services => {
|
||||
var configuration = services.GetRequiredService<IConfiguration>();
|
||||
|
||||
return configuration.GetValue<string?>("BOT_TOKEN")
|
||||
?? throw new InvalidOperationException(
|
||||
"No bot token has been provided. Set the "
|
||||
+ "BOT_TOKEN environment variable to a valid token.");
|
||||
}
|
||||
).ConfigureServices(
|
||||
(_, services) => {
|
||||
services.Configure<DiscordGatewayClientOptions>(
|
||||
options => options.Intents |= GatewayIntents.MessageContents
|
||||
| GatewayIntents.GuildMembers
|
||||
| GatewayIntents.GuildScheduledEvents);
|
||||
services.Configure<CacheSettings>(
|
||||
settings => {
|
||||
settings.SetDefaultAbsoluteExpiration(TimeSpan.FromHours(1));
|
||||
settings.SetDefaultSlidingExpiration(TimeSpan.FromMinutes(30));
|
||||
settings.SetAbsoluteExpiration<IMessage>(TimeSpan.FromDays(7));
|
||||
settings.SetSlidingExpiration<IMessage>(TimeSpan.FromDays(7));
|
||||
});
|
||||
|
||||
services.AddTransient<IConfigurationBuilder, ConfigurationBuilder>()
|
||||
.AddDiscordCaching()
|
||||
.AddDiscordCommands(true)
|
||||
.AddPreparationErrorEvent<ErrorLoggingPreparationErrorEvent>()
|
||||
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
|
||||
.AddInteractivity()
|
||||
.AddInteractionGroup<InteractionResponders>()
|
||||
.AddSingleton<GuildDataService>()
|
||||
.AddSingleton<UtilityService>()
|
||||
.AddHostedService<GuildUpdateService>()
|
||||
.AddCommandTree()
|
||||
.WithCommandGroup<AboutCommandGroup>()
|
||||
.WithCommandGroup<BanCommandGroup>()
|
||||
.WithCommandGroup<ClearCommandGroup>()
|
||||
.WithCommandGroup<KickCommandGroup>()
|
||||
.WithCommandGroup<MuteCommandGroup>()
|
||||
.WithCommandGroup<PingCommandGroup>()
|
||||
.WithCommandGroup<RemindCommandGroup>()
|
||||
.WithCommandGroup<SettingsCommandGroup>();
|
||||
var responderTypes = typeof(Boyfriend).Assembly
|
||||
.GetExportedTypes()
|
||||
.Where(t => t.IsResponder());
|
||||
foreach (var responderType in responderTypes) services.AddResponder(responderType);
|
||||
}
|
||||
).ConfigureLogging(
|
||||
c => c.AddConsole()
|
||||
.AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning)
|
||||
.AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue