Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SquirrelKiev committed Apr 28, 2024
1 parent 212218e commit 9a67252
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 132 deletions.
5 changes: 5 additions & 0 deletions DibariBot.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=53eecf85_002Dd821_002D40e8_002Dac97_002Dfdb734542b84/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Instance fields (not private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=70345118_002D4b40_002D4ece_002D937c_002Dbbeb7a0b2e70/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static fields (not private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=f9fce829_002De6f4_002D4cb2_002D80f1_002D5497c44f51df/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cubari/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dibari/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=manga/@EntryIndexedValue">True</s:Boolean>
Expand Down
13 changes: 3 additions & 10 deletions DibariBot/Apis/MangadexApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
namespace DibariBot.Apis;

[Inject(Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)]
public class MangaDexApi
public class MangaDexApi(IHttpClientFactory http, ICacheProvider cache, BotConfig botConfig)
{
private readonly Api api;
private readonly Uri baseUri;

public MangaDexApi(IHttpClientFactory http, ICacheProvider cache, BotConfig botConfig)
{
api = new Api(http, cache);

baseUri = new Uri(botConfig.MangaDexApiUrl);
}
private readonly Api api = new(http, cache);
private readonly Uri baseUri = new(botConfig.MangaDexApiUrl);

public async Task<MangaListSchema> GetMangas(MangaListQueryParams queryParams)
{
Expand Down
14 changes: 4 additions & 10 deletions DibariBot/Apis/PhixivApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
namespace DibariBot.Apis;

[Inject(ServiceLifetime.Singleton)]
public class PhixivApi
public class PhixivApi(IHttpClientFactory http, ICacheProvider cache, BotConfig botConfig)
{
private readonly Api api;
private readonly Uri baseUri;
private readonly Api api = new(http, cache);
private readonly Uri baseUri = new(botConfig.PhixivUrl);

//private readonly BotConfig botConfig;

public PhixivApi(IHttpClientFactory http, ICacheProvider cache, BotConfig botConfig)
{
//this.botConfig = botConfig;
api = new Api(http, cache);

baseUri = new Uri(botConfig.PhixivUrl);
}
//this.botConfig = botConfig;

public Task<PhixivInfoSchema?> GetById(string id)
{
Expand Down
5 changes: 3 additions & 2 deletions DibariBot/Apis/QueryStringSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

namespace DibariBot.Apis;

// gotta be a faster way of doing this, like,, why is this not built in in some form
// gotta be a faster way of doing this, like, why is this not built-in in some form
// if perf was a concern this wouldn't exist
// future me: literally just use Fergun.Interactive why did you do all this work lol
public static class QueryStringSerializer
{
public static string ToQueryParams(object obj)
Expand All @@ -20,7 +21,7 @@ public static string ToQueryParams(object obj)
return string.Join("&", dict.Select(kvp => $"{kvp.Key}={kvp.Value}"));
}

public static Dictionary<string, string>? ToUrlEncodedKeyValue(object obj)
public static Dictionary<string, string>? ToUrlEncodedKeyValue(object? obj)
{
if (obj == null)
{
Expand Down
6 changes: 1 addition & 5 deletions DibariBot/Core/Database/BotDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

namespace DibariBot.Database
{
public class BotDbContext : BotDbContextBase
public class BotDbContext(string connectionString) : BotDbContextPrefixBase(connectionString)
{
public DbSet<DefaultManga> DefaultMangas { get; set; }
public DbSet<RegexFilter> RegexFilters { get; set; }
public DbSet<RegexChannelEntry> RegexChannelEntries { get; set; }

public BotDbContext(string connectionString) : base(connectionString)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<GuildPrefixPreference>()
Expand Down
4 changes: 2 additions & 2 deletions DibariBot/DibariBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="enonibobble.BotBase" Version="1.0.1" />
<PackageReference Include="enonibobble.BotBase" Version="2.2.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
10 changes: 4 additions & 6 deletions DibariBot/Modules/About/AboutModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

namespace DibariBot.Modules.About;

public class AboutModule : AboutModuleImpl
[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)]
public class AboutModule(AboutService aboutService, OverrideTrackerService overrideTrackerService)
: AboutModuleImpl(aboutService, overrideTrackerService)
{
public AboutModule(AboutService aboutService, OverrideTrackerService overrideTrackerService) : base(aboutService, overrideTrackerService)
{
}

[SlashCommand("about", "Info about the bot.")]
[HelpPageDescription("Pulls up info about the bot.")]
[EnabledInDm(true)]
public override Task AboutSlash()
{
return base.AboutSlash();
Expand Down
18 changes: 8 additions & 10 deletions DibariBot/Modules/ConfigCommand/ConfigCommandModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

namespace DibariBot.Modules.ConfigCommand;

public class ConfigCommandModule : ConfigCommandModuleBase<ConfigPage.Page>
[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[RequireContext(ContextType.DM | ContextType.Group, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public class ConfigCommandModule(ConfigCommandServiceBase<ConfigPage.Page> configService)
: ConfigCommandModuleBase<ConfigPage.Page>(configService)
{
public ConfigCommandModule(ConfigCommandServiceBase<ConfigPage.Page> configService) : base(configService)
{
}

[SlashCommand("config", "Pulls up various options for configuring the bot to the server's needs.")]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[RequireContext(ContextType.DM | ContextType.Group, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
[EnabledInDm(true)]
[SlashCommand("config", "Pulls up various options for configuring the bot.")]
public override Task ConfigSlash()
{
return base.ConfigSlash();
Expand Down
7 changes: 1 addition & 6 deletions DibariBot/Modules/ConfigCommand/ConfigCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@

namespace DibariBot.Modules.ConfigCommand;

public class ConfigCommandService : ConfigCommandServiceBase<ConfigPage.Page>
{
public ConfigCommandService(IServiceProvider services) : base(services)
{
}
}
public class ConfigCommandService(IServiceProvider services) : ConfigCommandServiceBase<ConfigPage.Page>(services);
16 changes: 3 additions & 13 deletions DibariBot/Modules/ConfigCommand/Pages/DefaultMangaPage.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using DibariBot.Database;
using BotBase;
using BotBase.Database;
using BotBase.Modules;
using BotBase.Modules.ConfigCommand;
using Microsoft.EntityFrameworkCore;
using DibariBot.Database.Models;

namespace DibariBot.Modules.ConfigCommand.Pages;

[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[RequireContext(ContextType.DM | ContextType.Group, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public class DefaultMangaPage : ConfigPage
{
public class DefaultMangaSetModal : IModal
Expand Down Expand Up @@ -114,8 +116,6 @@ private static EmbedBuilder GetCurrentDefaultsEmbed(DefaultManga[] defaults)
}

[ComponentInteraction(ModulePrefixes.CONFIG_DEFAULT_MANGA_REMOVE_DROPDOWN)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task RemoveMangaDropdown(string id)
{
await DeferAsync();
Expand All @@ -142,8 +142,6 @@ await ModifyOriginalResponseAsync(await GetMessageContents(
}

[ComponentInteraction(ModulePrefixes.CONFIG_DEFAULT_MANGA_REMOVE)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task RemoveMangaButton()
{
await DeferAsync();
Expand Down Expand Up @@ -190,17 +188,13 @@ await ModifyOriginalResponseAsync(new MessageContents(string.Empty, embed.Build(
}

[ComponentInteraction(ModulePrefixes.CONFIG_DEFAULT_MANGA_SET)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task OpenModal()
{
await RespondWithModalAsync<DefaultMangaSetModal>(ModulePrefixes.CONFIG_DEFAULT_MANGA_SET_MODAL);
}

// step 2 - confirm section
[ModalInteraction($"{ModulePrefixes.CONFIG_DEFAULT_MANGA_SET_MODAL}")]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task OnModalResponse(DefaultMangaSetModal modal)
{
await DeferAsync();
Expand All @@ -227,8 +221,6 @@ public async Task OnModalResponse(DefaultMangaSetModal modal)
}

[ComponentInteraction(ModulePrefixes.CONFIG_DEFAULT_MANGA_SET_CHANNEL_INPUT + "*")]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task OnChannelSet(string id, IChannel[] channel)
{
// should be doing UpdateAsync but i have no clue how to get that kekw
Expand Down Expand Up @@ -276,8 +268,6 @@ private MessageContents ConfirmPromptContents(ConfirmState confirmState)

// step 3 - we've got a submit!!
[ComponentInteraction(ModulePrefixes.CONFIG_DEFAULT_MANGA_SET_SUBMIT_BUTTON + "*")]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task OnConfirmed(string id)
{
await DeferAsync();
Expand Down
35 changes: 8 additions & 27 deletions DibariBot/Modules/ConfigCommand/Pages/RegexFiltersPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

namespace DibariBot.Modules.ConfigCommand.Pages;

public partial class RegexFiltersPage : ConfigPage
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public partial class RegexFiltersPage(
MangaService mangaService,
ConfigCommandServiceBase<ConfigPage.Page> configCommandService,
BotConfig config)
: ConfigPage
{
public class SetRegexModal : IModal
{
Expand All @@ -36,16 +42,7 @@ public class SetRegexModal : IModal
private const string EMBED_NAME_FILTER_TYPE = "Filter Type";
private const string EMBED_NAME_SCOPE = "Channel Scope";

private readonly MangaService mangaService;
private readonly ConfigCommandServiceBase<Page> configCommandService;
private readonly BotConfig config;

public RegexFiltersPage(MangaService mangaService, ConfigCommandServiceBase<Page> configCommandService, BotConfig config)
{
this.mangaService = mangaService;
this.configCommandService = configCommandService;
this.config = config;
}
private readonly BotConfig config = config;

public override async Task<MessageContents> GetMessageContents(ConfigCommandServiceBase<Page>.State state)
{
Expand Down Expand Up @@ -125,8 +122,6 @@ private static SelectMenuBuilder GetFilterSelectMenu(string customId, IEnumerabl
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_REMOVE_BUTTON)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task RemoveButton()
{
await DeferAsync();
Expand All @@ -143,8 +138,6 @@ await ModifyOriginalResponseAsync(x =>
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_REMOVE_FILTER_SELECT)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task RemoveFilterSelectChanged(string id)
{
await DeferAsync();
Expand All @@ -163,8 +156,6 @@ private async Task RemoveFilterSelectChanged(string id)
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_EDIT_BUTTON)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task EditButton()
{
await DeferAsync();
Expand All @@ -181,8 +172,6 @@ await ModifyOriginalResponseAsync(x =>
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_EDIT_FILTER_SELECT)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task EditFilterSelectChanged(string id)
{
await DeferAsync();
Expand All @@ -199,8 +188,6 @@ private async Task EditFilterSelectChanged(string id)
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_OPEN_MODAL_BUTTON + "*")]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
public async Task OpenModalButton(uint id)
{
RegexFilter? filter = null;
Expand Down Expand Up @@ -257,8 +244,6 @@ public async Task ModalResponse(bool existing, SetRegexModal modal)
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_CONFIRMATION_ADD_BUTTON)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task ConfirmationAddButton()
{
await DeferAsync();
Expand Down Expand Up @@ -383,8 +368,6 @@ private MessageContents UpsertConfirmation(RegexFilter filter)
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_CONFIRMATION_CHANNEL_SELECT)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task UpsertConfirmationChannelSelectChanged(IChannel[] channels)
{
await DeferAsync();
Expand All @@ -407,8 +390,6 @@ private async Task UpsertConfirmationFilterTypeChanged(string id)
}

[ComponentInteraction(ModulePrefixes.CONFIG_FILTERS_CONFIRMATION_CHANNEL_SCOPE)]
[RequireUserPermission(GuildPermission.ManageGuild, Group = BaseModulePrefixes.PERMISSION_GROUP)]
[HasOverride(Group = BaseModulePrefixes.PERMISSION_GROUP)]
private async Task UpsertConfirmationChannelScopeChanged(string id)
{
await DeferAsync();
Expand Down
17 changes: 4 additions & 13 deletions DibariBot/Modules/Help/HelpModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@

namespace DibariBot.Modules.Help;

public class HelpModule : BotModule
[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)]
public class HelpModule(DbService dbService, HelpService helpService, BotConfigBase botConfig)
: BotModule
{
private readonly DbService dbService;
private readonly HelpService helpService;
private readonly BotConfigBase botConfig;

public HelpModule(DbService dbService, HelpService helpService, BotConfigBase botConfig)
{
this.dbService = dbService;
this.helpService = helpService;
this.botConfig = botConfig;
}

[SlashCommand("help", "Help! What are all the commands?")]
[HelpPageDescription("Pulls up this page!")]
[EnabledInDm(true)]
public async Task HelpSlash()
{
await DeferAsync();
Expand Down
Loading

0 comments on commit 9a67252

Please sign in to comment.