Skip to content

Commit

Permalink
v7.02, adds the invite button to the most used commands, can be toggl…
Browse files Browse the repository at this point in the history
…ed off with the config command. Adds autoplay and fixes timedafk. fixes protection commands not taking timeout as a parameter for action. Fixes replacements causing escaped json to appear due to non escaped raw usernames.
  • Loading branch information
SylveonDeko committed Sep 6, 2022
1 parent ec3c3a1 commit 20bc0c1
Show file tree
Hide file tree
Showing 26 changed files with 567 additions and 159 deletions.
18 changes: 18 additions & 0 deletions src/Mewdeko.Database/Migrations/FixTimedAfk.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Mewdeko.Database/Migrations/FixTimedAfk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mewdeko.Database.Migrations;

public partial class FixTimedAfk : Migration
{
protected override void Up(MigrationBuilder migrationBuilder) => migrationBuilder.AddColumn<DateTime>("When", "Afk", nullable: true);
}
1 change: 1 addition & 0 deletions src/Mewdeko.Database/Models/AFK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class Afk : DbEntity
public ulong GuildId { get; set; }
public string Message { get; set; }
public int WasTimed { get; set; } = 0;
public DateTime? When { get; set; }
}
5 changes: 4 additions & 1 deletion src/Mewdeko.Database/Models/MusicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ public enum PlayerRepeatType
{
None,
Track,
Queue
Queue,
Song = 1,
All = 2,
Off = 0
}
4 changes: 4 additions & 0 deletions src/Mewdeko/Common/Configs/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public BotConfig()
Prefix = ".";
RotateStatuses = false;
GroupGreets = false;
ShowInviteButton = true;
}

[Comment(@"DO NOT CHANGE")] public int Version { get; set; }
Expand Down Expand Up @@ -89,6 +90,9 @@ This setting can be changed via .rots command.
[Comment(@"Used for global command logs")]
public ulong CommandLogChannel { get; set; }

[Comment(@"Used to enable or disable showing the invite button on some commands")]
public bool ShowInviteButton { get; set; }

// [Comment(@"Whether the prefix will be a suffix, or prefix.
// For example, if your prefix is ! you will run a command called 'cash' by typing either
// '!cash @Someone' if your prefixIsSuffix: false or
Expand Down
14 changes: 7 additions & 7 deletions src/Mewdeko/Common/Replacements/ReplacementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ReplacementBuilder WithServer(DiscordSocketClient client, SocketGuild? g)
_reps.TryAdd("%time.year%", () => DateTime.UtcNow.ToString("yyyy"));
_reps.TryAdd("%server.icon%", () => g == null ? "DM" : $"{g.IconUrl}?size=2048");
_reps.TryAdd("%server.id%", () => g == null ? "DM" : g.Id.ToString());
_reps.TryAdd("%server.name%", () => g == null ? "DM" : g.Name);
_reps.TryAdd("%server.name%", () => g == null ? "DM" : g.Name.EscapeQuotes());
_reps.TryAdd("%server.boostlevel%", () =>
{
var e = g.PremiumTier.ToString();
Expand Down Expand Up @@ -219,11 +219,11 @@ public ReplacementBuilder WithChannel(IMessageChannel? ch)
_reps.TryAdd("%cid%", () => ch?.Id.ToString());
/*NEW*/
_reps.TryAdd("%channel.mention%", () => (ch as ITextChannel)?.Mention ?? $"#{ch.Name}");
_reps.TryAdd("%channel.name%", () => ch.Name);
_reps.TryAdd("%channel.name%", () => ch.Name.EscapeQuotes());
_reps.TryAdd("%channel.id%", () => ch.Id.ToString());
_reps.TryAdd("%channel.created%", () => ch.CreatedAt.ToString("HH:mm dd.MM.yyyy"));
_reps.TryAdd("%channel.nsfw%", () => (ch as ITextChannel)?.IsNsfw.ToString() ?? "-");
_reps.TryAdd("%channel.topic%", () => (ch as ITextChannel)?.Topic ?? "-");
_reps.TryAdd("%channel.topic%", () => (ch as ITextChannel)?.Topic.EscapeQuotes() ?? "-");
return this;
}

Expand All @@ -237,17 +237,17 @@ public ReplacementBuilder WithManyUsers(IEnumerable<IUser> users)
{
/*OBSOLETE*/
_reps.TryAdd("%user%", () => string.Join(" ", users.Select(user => user.Mention)));
_reps.TryAdd("%userfull%", () => string.Join(" ", users.Select(user => user.ToString())));
_reps.TryAdd("%username%", () => string.Join(" ", users.Select(user => user.Username)));
_reps.TryAdd("%userfull%", () => string.Join(" ", users.Select(user => user.ToString().EscapeQuotes())));
_reps.TryAdd("%username%", () => string.Join(" ", users.Select(user => user.Username.EscapeQuotes())));
_reps.TryAdd("%userdiscrim%", () => string.Join(" ", users.Select(user => user.Discriminator)));
_reps.TryAdd("%useravatar%",
() => string.Join(" ", users.Select(user => user.RealAvatarUrl().ToString())));
_reps.TryAdd("%id%", () => string.Join(" ", users.Select(user => user.Id.ToString())));
_reps.TryAdd("%uid%", () => string.Join(" ", users.Select(user => user.Id.ToString())));
/*NEW*/
_reps.TryAdd("%user.mention%", () => string.Join(" ", users.Select(user => user.Mention)));
_reps.TryAdd("%user.fullname%", () => string.Join(" ", users.Select(user => user.ToString())));
_reps.TryAdd("%user.name%", () => string.Join(" ", users.Select(user => user.Username)));
_reps.TryAdd("%user.fullname%", () => string.Join(" ", users.Select(user => user.ToString().EscapeQuotes())));
_reps.TryAdd("%user.name%", () => string.Join(" ", users.Select(user => user.Username.EscapeQuotes())));
_reps.TryAdd("%user.banner%",
() => string.Join(" ",
users.Select(async user => (await _client.Rest.GetUserAsync(user.Id).ConfigureAwait(false)).GetBannerUrl(size: 2048))));
Expand Down
4 changes: 1 addition & 3 deletions src/Mewdeko/Common/Replacements/Replacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public Replacer(IEnumerable<(string, Func<string>)> replacements,
input = input.Replace(key, text(), StringComparison.InvariantCulture);
}

foreach (var item in _regex) input = item.Regex.Replace(input, m => item.Replacement(m));

return input;
return _regex.Aggregate(input, (current, item) => item.Regex.Replace(current, m => item.Replacement(m)));
}
}
14 changes: 9 additions & 5 deletions src/Mewdeko/Modules/Administration/ProtectionCommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Discord.Commands;
using Humanizer;
using Mewdeko.Common.Attributes.TextCommands;
using Mewdeko.Common.TypeReaders.Models;
using Mewdeko.Modules.Administration.Common;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task AntiAlt(StoopidTime minAge, PunishmentAction action,
case PunishmentAction.Timeout when punishTime.Time.Days > 28:
await ReplyErrorLocalizedAsync("timeout_length_too_long").ConfigureAwait(false);
return;
case PunishmentAction.Timeout when punishTime.Time.Days == 0:
case PunishmentAction.Timeout when punishTime.Time == TimeSpan.Zero:
await ReplyErrorLocalizedAsync("timeout_needs_time").ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -92,7 +93,7 @@ private async Task InternalAntiRaid(int userThreshold, int seconds = 10,
case PunishmentAction.Timeout when punishTime.Time.Days > 28:
await ReplyErrorLocalizedAsync("timeout_length_too_long").ConfigureAwait(false);
return;
case PunishmentAction.Timeout when punishTime.Time.Days == 0:
case PunishmentAction.Timeout when punishTime.Time == TimeSpan.Zero:
await ReplyErrorLocalizedAsync("timeout_needs_time").ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -172,7 +173,10 @@ public async Task InternalAntiSpam(int messageCount, PunishmentAction action,
if (timeData is not null)
{
if (!ProtectionService.IsDurationAllowed(action))
{
await ReplyErrorLocalizedAsync("prot_cant_use_time").ConfigureAwait(false);
return;
}
}

var time = (int?)timeData?.Time.TotalMinutes ?? 0;
Expand All @@ -183,7 +187,7 @@ public async Task InternalAntiSpam(int messageCount, PunishmentAction action,
case PunishmentAction.Timeout when timeData.Time.Days > 28:
await ReplyErrorLocalizedAsync("timeout_length_too_long").ConfigureAwait(false);
return;
case PunishmentAction.Timeout when timeData.Time.Days == 0:
case PunishmentAction.Timeout when timeData.Time == TimeSpan.Zero:
await ReplyErrorLocalizedAsync("timeout_needs_time").ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -259,7 +263,7 @@ public async Task AntiList()
ignoredString = "none";

var add = "";
if (settings.MuteTime > 0) add = $" ({TimeSpan.FromMinutes(settings.MuteTime):hh\\hmm\\m})";
if (settings.MuteTime > 0) add = $" ({TimeSpan.FromMinutes(settings.MuteTime).Humanize()})";

return GetText("spam_stats",
Format.Bold(settings.MessageThreshold.ToString()),
Expand All @@ -272,7 +276,7 @@ public async Task AntiList()
var actionString = Format.Bold(stats.AntiRaidSettings.Action.ToString());

if (stats.AntiRaidSettings.PunishDuration > 0)
actionString += $" **({TimeSpan.FromMinutes(stats.AntiRaidSettings.PunishDuration):hh\\hmm\\m})**";
actionString += $" **({TimeSpan.FromMinutes(stats.AntiRaidSettings.PunishDuration).Humanize()})**";

return GetText("raid_stats",
Format.Bold(stats.AntiRaidSettings.UserThreshold.ToString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public static bool IsDurationAllowed(PunishmentAction action) =>
PunishmentAction.ChatMute => true,
PunishmentAction.VoiceMute => true,
PunishmentAction.AddRole => true,
PunishmentAction.Timeout => true,
_ => false
};

Expand Down
21 changes: 4 additions & 17 deletions src/Mewdeko/Modules/Afk/AFK.cs → src/Mewdeko/Modules/Afk/Afk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public class Afk : MewdekoModuleBase<AfkService>
{
private readonly InteractiveService _interactivity;
private readonly DiscordSocketClient _client;
private readonly GuildSettingsService _guildSettings;
public Afk(InteractiveService serv, DiscordSocketClient client, GuildSettingsService guildSettings)

public Afk(InteractiveService serv, DiscordSocketClient client)
{
_interactivity = serv;
_client = client;
_guildSettings = guildSettings;
}

public enum AfkTypeEnum
Expand Down Expand Up @@ -151,21 +150,9 @@ public async Task TimedAfk(StoopidTime time, [Remainder] string message)
await ctx.Channel.SendErrorAsync("Hold your horses I just started back up! Give me a few seconds then this command will be ready!\nIn the meantime check out https://mewdeko.tech/changelog for bot updates!").ConfigureAwait(false);
return;
}
if (Service.IsAfk(ctx.Guild, ctx.User as IGuildUser))
{
await ctx.Channel.SendErrorAsync(
$"You already have a regular afk set! Please disable it by doing {await _guildSettings.GetPrefix(ctx.Guild)}afk and try again").ConfigureAwait(false);
return;
}

await ctx.Channel.SendConfirmAsync(
$"AFK Message set to:\n{message}\n\nAFK will unset in {time.Time.Humanize()}").ConfigureAwait(false);
await Service.TimedAfk(ctx.Guild, ctx.User, message, time.Time).ConfigureAwait(false);
if (Service.IsAfk(ctx.Guild, ctx.User as IGuildUser))
{
await ctx.Channel.SendMessageAsync(
$"Welcome back {ctx.User.Mention} I have removed your timed AFK.").ConfigureAwait(false);
}
await Service.AfkSet(ctx.Guild, ctx.User as IGuildUser, message, 1, DateTime.UtcNow + time.Time);
await ctx.Channel.SendConfirmAsync($"Timed AFK has been set, and will unset in `{time.Time.Humanize()}`.\nMessage set to:\n{message}");
}

[Cmd, Aliases, UserPerm(GuildPermission.Administrator)]
Expand Down
Loading

0 comments on commit 20bc0c1

Please sign in to comment.