2022-08-16 03:08:00 +00:00
|
|
|
|
namespace RegexBot;
|
2022-03-29 05:03:01 +00:00
|
|
|
|
partial class RegexbotClient {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts to ban the given user from the specified guild. It is greatly preferred to call this method
|
|
|
|
|
/// instead of manually executing the equivalent method found in Discord.Net. It notifies other services
|
|
|
|
|
/// that the action originated from the bot, and allows them to handle the action appropriately.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A structure containing results of the ban operation.</returns>
|
|
|
|
|
/// <param name="guild">The guild in which to attempt the ban.</param>
|
|
|
|
|
/// <param name="source">The user, module, or service which is requesting this action to be taken.</param>
|
|
|
|
|
/// <param name="targetUser">The user which to perform the action to.</param>
|
|
|
|
|
/// <param name="purgeDays">Number of days of prior post history to delete on ban. Must be between 0-7.</param>
|
|
|
|
|
/// <param name="reason">Reason for the action. Sent to the Audit Log and user (if specified).</param>
|
|
|
|
|
/// <param name="sendDMToTarget">Specify whether to send a direct message to the target user informing them of the action.</param>
|
2022-05-26 02:27:53 +00:00
|
|
|
|
public Task<BanKickResult> BanAsync(SocketGuild guild,
|
|
|
|
|
string source,
|
|
|
|
|
ulong targetUser,
|
|
|
|
|
int purgeDays,
|
|
|
|
|
string? reason,
|
|
|
|
|
bool sendDMToTarget)
|
2022-12-03 04:28:23 +00:00
|
|
|
|
=> _svcCommonFunctions.BanOrKickAsync(true, guild, source, targetUser, purgeDays, reason, sendDMToTarget);
|
2022-03-29 05:03:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Similar to <see cref="BanAsync(SocketGuild, string, ulong, int, string, bool)"/>, but making use of an
|
|
|
|
|
/// EntityCache lookup to determine the target.
|
|
|
|
|
/// </summary>
|
2022-07-21 01:55:08 +00:00
|
|
|
|
/// <param name="guild">The guild in which to attempt the ban.</param>
|
|
|
|
|
/// <param name="source">The user, module, or service which is requesting this action to be taken.</param>
|
|
|
|
|
/// <param name="targetSearch">The user which to perform the action to (as a query to the entity cache).</param>
|
|
|
|
|
/// <param name="purgeDays">Number of days of prior post history to delete on ban. Must be between 0-7.</param>
|
|
|
|
|
/// <param name="reason">Reason for the action. Sent to the Audit Log and user (if specified).</param>
|
|
|
|
|
/// <param name="sendDMToTarget">Specify whether to send a direct message to the target user informing them of the action.</param>
|
2022-05-26 02:27:53 +00:00
|
|
|
|
public async Task<BanKickResult> BanAsync(SocketGuild guild,
|
|
|
|
|
string source,
|
|
|
|
|
string targetSearch,
|
|
|
|
|
int purgeDays,
|
|
|
|
|
string? reason,
|
|
|
|
|
bool sendDMToTarget) {
|
2022-05-12 03:26:28 +00:00
|
|
|
|
var result = EcQueryGuildUser(guild.Id, targetSearch);
|
2022-12-03 04:28:23 +00:00
|
|
|
|
if (result == null) return new BanKickResult(null, false, true, true, 0);
|
2022-05-12 03:26:28 +00:00
|
|
|
|
return await BanAsync(guild, source, (ulong)result.UserId, purgeDays, reason, sendDMToTarget);
|
2022-03-29 05:03:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts to ban the given user from the specified guild. It is greatly preferred to call this method
|
|
|
|
|
/// instead of manually executing the equivalent method found in Discord.Net. It notifies other services
|
|
|
|
|
/// that the action originated from the bot, and allows them to handle the action appropriately.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A structure containing results of the ban operation.</returns>
|
|
|
|
|
/// <param name="guild">The guild in which to attempt the kick.</param>
|
|
|
|
|
/// <param name="source">The user, module, or service which is requesting this action to be taken.</param>
|
2022-05-12 03:26:28 +00:00
|
|
|
|
/// <param name="targetUser">The user which to perform the action towards.</param>
|
|
|
|
|
/// <param name="reason">
|
|
|
|
|
/// Reason for the action. Sent to the guild's audit log and, if
|
|
|
|
|
/// <paramref name="sendDMToTarget"/> is <see langword="true"/>, the target.
|
|
|
|
|
/// </param>
|
2022-07-21 01:55:08 +00:00
|
|
|
|
/// <param name="sendDMToTarget">Specify whether to send a direct message to the target user informing them of the action.</param>
|
2022-05-26 02:27:53 +00:00
|
|
|
|
public Task<BanKickResult> KickAsync(SocketGuild guild,
|
|
|
|
|
string source,
|
|
|
|
|
ulong targetUser,
|
|
|
|
|
string? reason,
|
|
|
|
|
bool sendDMToTarget)
|
2022-12-03 04:28:23 +00:00
|
|
|
|
=> _svcCommonFunctions.BanOrKickAsync(false, guild, source, targetUser, default, reason, sendDMToTarget);
|
2022-03-29 05:03:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Similar to <see cref="KickAsync(SocketGuild, string, ulong, string, bool)"/>, but making use of an
|
|
|
|
|
/// EntityCache lookup to determine the target.
|
|
|
|
|
/// </summary>
|
2022-07-21 01:55:08 +00:00
|
|
|
|
/// <param name="guild">The guild in which to attempt the kick.</param>
|
|
|
|
|
/// <param name="source">The user, module, or service which is requesting this action to be taken.</param>
|
|
|
|
|
/// <param name="targetSearch">The user which to perform the action towards (processed as a query to the entity cache).</param>
|
|
|
|
|
/// <param name="reason">
|
|
|
|
|
/// Reason for the action. Sent to the guild's audit log and, if
|
|
|
|
|
/// <paramref name="sendDMToTarget"/> is <see langword="true"/>, the target.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="sendDMToTarget">Specify whether to send a direct message to the target user informing them of the action.</param>
|
2022-05-26 02:27:53 +00:00
|
|
|
|
public async Task<BanKickResult> KickAsync(SocketGuild guild,
|
|
|
|
|
string source,
|
|
|
|
|
string targetSearch,
|
|
|
|
|
string? reason,
|
|
|
|
|
bool sendDMToTarget) {
|
2022-05-12 03:26:28 +00:00
|
|
|
|
var result = EcQueryGuildUser(guild.Id, targetSearch);
|
2022-12-03 04:28:23 +00:00
|
|
|
|
if (result == null) return new BanKickResult(null, false, true, false, 0);
|
2022-05-12 03:26:28 +00:00
|
|
|
|
return await KickAsync(guild, source, (ulong)result.UserId, reason, sendDMToTarget);
|
2018-12-05 03:41:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|