Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Attributes/HiddenAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Cliptok.Attributes
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class HiddenAttribute : Attribute;
}
51 changes: 0 additions & 51 deletions Commands/BanCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,57 +177,6 @@ public async Task BanInfoSlashCommand(
await ctx.RespondAsync(embed: await BanHelpers.BanStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic);
}

[Command("massbantextcmd")]
[TextAlias("massban", "bigbonk")]
[Description("Ban multiple users from the server at once.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassBanCmd(TextCommandContext ctx, [Description("The list of users to ban, separated by newlines or spaces, optionally followed by a reason."), RemainingText] string input)
{
List<string> inputString = input.Replace("\n", " ").Replace("\r", "").Split(' ').ToList();
List<ulong> users = new();
string reason = "";
foreach (var word in inputString)
{
if (ulong.TryParse(word, out var id))
users.Add(id);
else
reason += $"{word} ";
}
reason = reason.Trim();

if (users.Count == 1 || users.Count == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Not accepting a massban with a single user. Please use `!ban`.");
return;
}

List<Task<bool>> taskList = new();
int successes = 0;

await ctx.RespondAsync("Processing, please wait.");
var loading = await ctx.GetResponseAsync();

foreach (ulong user in users)
{
if (string.IsNullOrWhiteSpace(reason))
taskList.Add(BanSilently(ctx.Guild, user));
else
taskList.Add(BanSilently(ctx.Guild, user, $"Mass ban: {reason}"));
}

var tasks = await Task.WhenAll(taskList);

foreach (var task in taskList)
{
if (task.Result)
successes += 1;
}

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Banned} **{successes}**/{users.Count} users were banned successfully.");
await loading.DeleteAsync();
}

[Command("bantextcmd")]
[TextAlias("ban", "tempban", "bonk", "isekaitruck")]
[Description("Bans a user that you have permission to ban, deleting all their messages in the process. See also: bankeep.")]
Expand Down
77 changes: 0 additions & 77 deletions Commands/DehoistCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,82 +135,5 @@ public async Task PermadehoistStatusSlashCmd(CommandContext ctx, [Parameter("mem
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Off} {discordUser.Mention} is not permadehoisted.", mentions: false);
}
}

[Command("massdehoisttextcmd")]
[TextAlias("massdehoist")]
[Description("Dehoist everyone on the server who has a bad name. This may take a while and can exhaust rate limits.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassDehoist(TextCommandContext ctx)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Loading} Working on it. This will take a while.");
var msg = await ctx.GetResponseAsync();

var (totalMembers, failedMembers) = await DehoistHelpers.MassDehoistAsync(ctx.Guild, ctx.User);

_ = msg.DeleteAsync();
await ctx.Channel.SendMessageAsync(new DiscordMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Success} Successfully dehoisted {totalMembers - failedMembers} of {totalMembers} member(s)! (Check Audit Log for details)").WithReply(ctx.Message.Id, true, false));
}

[Command("massundehoisttextcmd")]
[TextAlias("massundehoist")]
[Description("Remove the dehoist for users attached via a txt file.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassUndhoist(TextCommandContext ctx)
{
int failedCount = 0;

if (ctx.Message.Attachments.Count == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Please upload an attachment as well.");
}
else
{
string strList;
using (HttpClient client = new())
{
strList = await client.GetStringAsync(ctx.Message.Attachments[0].Url);
}

var list = strList.Split(' ');

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Loading} Working on it. This will take a while.");
var msg = await ctx.GetResponseAsync();

foreach (string strID in list)
{
ulong id = Convert.ToUInt64(strID);
DiscordMember member = default;
try
{
member = await ctx.Guild.GetMemberAsync(id);
}
catch (DSharpPlus.Exceptions.NotFoundException)
{
failedCount++;
continue;
}

if (member.DisplayName[0] == DehoistHelpers.dehoistCharacter && !member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername) && !member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedGuildTag))
{
var newNickname = member.Nickname[1..];
await member.ModifyAsync(a =>
{
a.Nickname = newNickname;
a.AuditLogReason = $"[Mass undehoist by {DiscordHelpers.UniqueUsername(ctx.User)}]";
}
);
}
else
{
failedCount++;
}
}

await msg.ModifyAsync($"{Program.cfgjson.Emoji.Success} Successfully undehoisted {list.Length - failedCount} of {list.Length} member(s)! (Check Audit Log for details)");

}
}
}
}
3 changes: 2 additions & 1 deletion Commands/GlobalCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static async Task Help(CommandContext ctx, [Description("Command to provi

IEnumerable<Command> cmds = ctx.Extension.Commands.Values.Where(cmd =>
cmd.Attributes.Any(attr => attr is AllowedProcessorsAttribute apAttr
&& apAttr.Processors.Contains(typeof(TextCommandProcessor))));
&& apAttr.Processors.Contains(typeof(TextCommandProcessor)))
&& !cmd.Attributes.Any(attr => attr is HiddenAttribute && command == ""));

if (commandSplit.Length != 0 && commandSplit[0] != "")
{
Expand Down
92 changes: 1 addition & 91 deletions Commands/KickCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class KickCmds
{
if (DiscordHelpers.AllowedToMod(await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id), member))
{
await KickAndLogAsync(member, reason, ctx.Member);
await KickHelpers.KickAndLogAsync(member, reason, ctx.Member);
await ctx.Channel.SendMessageAsync($"{Program.cfgjson.Emoji.Ejected} {target.Mention} has been kicked: **{reason}**");
if (ctx is SlashCommandContext)
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Done!", ephemeral: true);
Expand All @@ -53,95 +53,5 @@ public class KickCmds
return;
}
}

[Command("masskicktextcmd")]
[TextAlias("masskick")]
[Description("Kick multiple users from the server at once.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassKickCmd(TextCommandContext ctx, [Description("The list of users to kick, separated by newlines or spaces, optionally followed by a reason."), RemainingText] string input)
{

List<string> inputString = input.Replace("\n", " ").Replace("\r", "").Split(' ').ToList();
List<ulong> users = new();
string reason = "";
foreach (var word in inputString)
{
if (ulong.TryParse(word, out var id))
users.Add(id);
else
reason += $"{word} ";
}
reason = reason.Trim();

if (users.Count == 1 || users.Count == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Not accepting a masskick with a single user. Please use `!kick`.");
return;
}

List<Task<bool>> taskList = new();
int successes = 0;

await ctx.RespondAsync("Processing, please wait.");
var loading = await ctx.GetResponseAsync();

foreach (ulong user in users)
{
try
{
var member = await ctx.Guild.GetMemberAsync(user);
if (member is not null)
{

taskList.Add(SafeKickAndLogAsync(member, $"Mass kick{(string.IsNullOrWhiteSpace(reason) ? "" : $": {reason}")}", ctx.Member));
}
}
catch
{
// not successful, move on
}
}

var tasks = await Task.WhenAll(taskList);

foreach (var task in taskList)
{
if (task.Result)
successes += 1;
}

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Deleted} **{successes}**/{users.Count} users were kicked successfully.");
await loading.DeleteAsync();
}


public async static Task KickAndLogAsync(DiscordMember target, string reason, DiscordMember moderator)
{
await target.RemoveAsync(reason);
await LogChannelHelper.LogMessageAsync("mod",
new DiscordMessageBuilder()
.WithContent($"{Program.cfgjson.Emoji.Ejected} {target.Mention} was kicked by {moderator.Mention}.\nReason: **{reason}**")
.WithAllowedMentions(Mentions.None)
);
}

public async static Task<bool> SafeKickAndLogAsync(DiscordMember target, string reason, DiscordMember moderator)
{
try
{
await target.RemoveAsync(reason);
await LogChannelHelper.LogMessageAsync("mod",
new DiscordMessageBuilder()
.WithContent($"{Program.cfgjson.Emoji.Ejected} {target.Mention} was kicked by {moderator.Mention}.\nReason: **{reason}**")
.WithAllowedMentions(Mentions.None)
);
return true;
}
catch
{
return false;
}
}
}
}
Loading
Loading