Skip to content

Commit

Permalink
Fix moving data from sqlite to psql. Add deny sending messages in thr…
Browse files Browse the repository at this point in the history
…eads to lockdown, fixed action commands
  • Loading branch information
SylveonDeko committed Oct 7, 2024
1 parent 56564d1 commit ad8ded9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Mewdeko/Common/Attributes/DB/NewPropertyAttriburte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Mewdeko.Common.Attributes.DB;
/// <summary>
/// Used for specifying when a db column is new and to not copy it
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
public class NewPropertyAttribute : Attribute;
2 changes: 1 addition & 1 deletion src/Mewdeko/Common/Replacements/ReplacementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public partial class ReplacementBuilder
/// <param name="client">The Discord client.</param>
public ReplacementBuilder(DiscordShardedClient? client = null)
{
nekosBestApi = new NekosBestApi();
nekosBestApi = new NekosBestApi(client?.CurrentUser.Username ?? "Mewdeko");
this.client = client;
WithRngRegex();
}
Expand Down
10 changes: 10 additions & 0 deletions src/Mewdeko/Database/Models/AntiProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,67 @@ public class AntiSpamSetting : DbEntity
/// <summary>
/// Represents settings for anti-mass mention protection in a guild.
/// </summary>
[NewProperty]
[Table("AntiMassMentionSetting")]
public class AntiMassMentionSetting : DbEntity
{
/// <summary>
/// Gets or sets the ID of the associated guild configuration.
/// </summary>
[NewProperty]
[ForeignKey("GuildConfigId")]
public int GuildConfigId { get; set; }

/// <summary>
/// Gets or sets the action to be taken when anti-mass mention measures are triggered.
/// </summary>
[NewProperty]
public PunishmentAction Action { get; set; }

/// <summary>
/// Gets or sets the maximum number of mentions allowed in a single message before triggering anti-mass mention
/// measures.
/// </summary>
[NewProperty]
public int MentionThreshold { get; set; } = 3;

/// <summary>
/// Gets or sets the maximum number of mentions allowed within a specified time window.
/// </summary>
[NewProperty]
public int MaxMentionsInTimeWindow { get; set; } = 5;

/// <summary>
/// Gets or sets the time window in seconds in which mentions are tracked.
/// If the number of mentions exceeds MaxMentionsInTimeWindow within this time, anti-mass mention actions are
/// triggered.
/// </summary>
[NewProperty]
public int TimeWindowSeconds { get; set; } = 60;

/// <summary>
/// Gets or sets the mute duration in minutes.
/// This is applied when a mute action is chosen as the punishment.
/// </summary>
[NewProperty]
public int MuteTime { get; set; } = 0;

/// <summary>
/// Gets or sets the ID of the role to be assigned as punishment.
/// </summary>
[NewProperty]
public ulong? RoleId { get; set; }

/// <summary>
/// Gets or sets a boolean indicating whether bots should be ignored by anti-mass mention measures.
/// </summary>
[NewProperty]
public bool IgnoreBots { get; set; } = true;

/// <summary>
/// Gets or sets the collection of ignored channels for anti-mass mention measures.
/// </summary>
[NewProperty]
public HashSet<AntiSpamIgnore> IgnoredChannels { get; set; } = new();
}

Expand Down
1 change: 1 addition & 0 deletions src/Mewdeko/Database/Models/GuildConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ public class GuildConfig : DbEntity
/// <summary>
/// Gets or sets the anti mass mention settings for the guild.
/// </summary>
[NewProperty]
public AntiMassMentionSetting AntiMassMentionSetting { get; set; }

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Mewdeko/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
global using Mewdeko.Database.Models;
global using Mewdeko.Extensions;
global using Mewdeko.Services;
global using Mewdeko.Common.Attributes.DB;
global using NonBlocking;
global using EventHandler = Mewdeko.Services.Impl.EventHandler;
2 changes: 1 addition & 1 deletion src/Mewdeko/Mewdeko.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0-preview.5.24306.7"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0-preview.5.24306.7"/>
<PackageReference Include="morelinq" Version="4.1.0"/>
<PackageReference Include="NekosBestApiNet" Version="1.0.6"/>
<PackageReference Include="NekosBestApiNet" Version="1.0.7"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="NHentaiAPI" Version="1.7.0"/>
<PackageReference Include="NonBlocking" Version="2.1.2"/>
Expand Down
2 changes: 0 additions & 2 deletions src/Mewdeko/Modules/Music/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public async Task Join()
{
var (player, result) = await GetPlayerAsync();
if (string.IsNullOrWhiteSpace(result))
{
await ReplyConfirmLocalizedAsync("music_join_success", player.VoiceChannelId).ConfigureAwait(false);
}
else
{
var eb = new EmbedBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public async Task ApplyLockdown(IGuild guild)
createPrivateThreads: PermValue.Deny,
sendMessages: PermValue.Allow),
_ => existingPerms.Modify(sendMessages: PermValue.Deny, createPublicThreads: PermValue.Deny,
createPrivateThreads: PermValue.Deny)
createPrivateThreads: PermValue.Deny, sendMessagesInThreads: PermValue.Deny)
};

channelPermissions.Add((channel, lockdownPerms));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ private async Task HandleRoleUpdatedAsync(IGuild guild, IAuditLogEntry entry)
/// </summary>
private async Task<bool> IsUserWhitelistedAsync(IGuild guild, ulong userId)
{
// if (guild.OwnerId == userId)
// return true;
if (guild.OwnerId == userId)
return true;
var redisDb = dataCache.Redis.GetDatabase();
var key = $"guild:{guild.Id}:whitelisted_users";

Expand Down
2 changes: 1 addition & 1 deletion src/Mewdeko/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static void ConfigureServices(IServiceCollection services, BotCredential
{
ReturnAfterSendingPaginator = true
}))
.AddSingleton(new NekosBestApi())
.AddSingleton(new NekosBestApi("Mewdeko"))
.AddSingleton(p => new InteractionService(p.GetRequiredService<DiscordShardedClient>()))
.AddSingleton<Localization>()
.AddSingleton<BotConfigService>()
Expand Down

0 comments on commit ad8ded9

Please sign in to comment.