i can't be bothered to keep track of these changes

This commit is contained in:
l1ttleO 2022-06-06 20:39:47 +05:00
parent 790f77aa49
commit 36d844148e
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
15 changed files with 649 additions and 926 deletions

View file

@ -5,7 +5,7 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class BanCommand : Command {
public override string[] Aliases { get; } = {"ban", "бан"};
public override string[] Aliases { get; } = { "ban", "бан" };
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
@ -17,7 +17,7 @@ public class BanCommand : Command {
}
var guild = context.Guild;
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.BanMembers);
if (permissionCheckResponse != "") {
@ -40,6 +40,11 @@ public class BanCommand : Command {
if (duration.TotalSeconds < 0) {
Warn(Messages.DurationParseFailed);
reason = Utils.JoinString(ref args, 1);
if (reason == "") {
Error(Messages.ReasonRequired, false);
return;
}
}
await BanUser(guild, author, toBan, duration, reason);
@ -50,12 +55,12 @@ public class BanCommand : Command {
var guildBanMessage = $"({author}) {reason}";
await Utils.SendDirectMessage(toBan,
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.WrapInline(reason)));
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
await guild.AddBanAsync(toBan, 0, guildBanMessage);
var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention,
Utils.GetHumanizedTimeOffset(ref duration), Utils.WrapInline(reason));
Utils.GetHumanizedTimeOffset(ref duration), Utils.Wrap(reason));
Success(feedback, author.Mention, false, false);
await Utils.SendFeedback(feedback, guild.Id, author.Mention, true);
@ -65,8 +70,7 @@ public class BanCommand : Command {
await UnbanCommand.UnbanUser(guild, guild.CurrentUser, toBan, Messages.PunishmentExpired);
}
var task = new Task(DelayUnban);
task.Start();
new Task(DelayUnban).Start();
}
}
}

View file

@ -4,7 +4,6 @@ using Discord.Commands;
namespace Boyfriend.Commands;
public abstract class Command {
public abstract string[] Aliases { get; }
public abstract int ArgsLengthRequired { get; }

View file

@ -5,11 +5,11 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class KickCommand : Command {
public override string[] Aliases { get; } = {"kick", "кик", "выгнать"};
public override string[] Aliases { get; } = { "kick", "кик", "выгнать" };
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.KickMembers);
if (permissionCheckResponse != "") {
@ -34,7 +34,7 @@ public class KickCommand : Command {
Success(
string.Format(Messages.FeedbackMemberKicked, toKick.Mention,
Utils.WrapInline(Utils.JoinString(ref args, 1))), author.Mention);
Utils.Wrap(Utils.JoinString(ref args, 1))), author.Mention);
}
private static async Task KickMember(IGuild guild, SocketUser author, SocketGuildUser toKick, string reason) {
@ -42,7 +42,7 @@ public class KickCommand : Command {
var guildKickMessage = $"({author}) {reason}";
await Utils.SendDirectMessage(toKick,
string.Format(Messages.YouWereKicked, authorMention, guild.Name, Utils.WrapInline(reason)));
string.Format(Messages.YouWereKicked, authorMention, guild.Name, Utils.Wrap(reason)));
await toKick.KickAsync(guildKickMessage);
}

View file

@ -6,7 +6,7 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class MuteCommand : Command {
public override string[] Aliases { get; } = {"mute", "timeout", "заглушить", "мут"};
public override string[] Aliases { get; } = { "mute", "timeout", "заглушить", "мут" };
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
@ -17,6 +17,11 @@ public class MuteCommand : Command {
if (duration.TotalSeconds < 0) {
Warn(Messages.DurationParseFailed);
reason = Utils.JoinString(ref args, 1);
if (reason == "") {
Error(Messages.ReasonRequired, false);
return;
}
}
if (toMute == null) {
@ -28,15 +33,9 @@ public class MuteCommand : Command {
var role = Utils.GetMuteRole(ref guild);
if (role != null) {
var hasMuteRole = false;
foreach (var x in toMute.Roles) {
if (x != role) continue;
hasMuteRole = true;
break;
}
if (hasMuteRole || (toMute.TimedOutUntil != null && toMute.TimedOutUntil.Value.ToUnixTimeMilliseconds() >
DateTimeOffset.Now.ToUnixTimeMilliseconds())) {
if (toMute.Roles.Contains(role) || (toMute.TimedOutUntil != null &&
toMute.TimedOutUntil.Value.ToUnixTimeMilliseconds() >
DateTimeOffset.Now.ToUnixTimeMilliseconds())) {
Error(Messages.MemberAlreadyMuted, false);
return;
}
@ -51,7 +50,7 @@ public class MuteCommand : Command {
Warn(Messages.RolesReturned);
}
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.ModerateMembers);
if (permissionCheckResponse != "") {
@ -69,7 +68,7 @@ public class MuteCommand : Command {
Success(
string.Format(Messages.FeedbackMemberMuted, toMute.Mention, Utils.GetHumanizedTimeOffset(ref duration),
Utils.WrapInline(reason)), author.Mention, true);
Utils.Wrap(reason)), author.Mention, true);
}
private static async Task MuteMember(SocketGuild guild, SocketUser author, SocketGuildUser toMute,
@ -88,7 +87,7 @@ public class MuteCommand : Command {
await toMute.RemoveRoleAsync(role);
rolesRemoved.Add(userRole.Id);
} catch (HttpException e) {
Warn(string.Format(Messages.RoleRemovalFailed, $"<@&{userRole}>", Utils.WrapInline(e.Reason)));
Warn(string.Format(Messages.RoleRemovalFailed, $"<@&{userRole}>", Utils.Wrap(e.Reason)));
}
Boyfriend.GetRemovedRoles(guild.Id).Add(toMute.Id, rolesRemoved.AsReadOnly());
@ -100,8 +99,7 @@ public class MuteCommand : Command {
await UnmuteCommand.UnmuteMember(guild, guild.CurrentUser, toMute, Messages.PunishmentExpired);
}
var task = new Task(DelayUnmute);
task.Start();
new Task(DelayUnmute).Start();
}
}
@ -111,6 +109,7 @@ public class MuteCommand : Command {
Error(Messages.DurationRequiredForTimeOuts, false);
return;
}
if (toMute.IsBot) {
Error(Messages.CannotTimeOutBot, false);
return;
@ -119,4 +118,4 @@ public class MuteCommand : Command {
await toMute.SetTimeOutAsync(duration, requestOptions);
}
}
}
}

View file

@ -5,11 +5,11 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class SettingsCommand : Command {
public override string[] Aliases { get; } = {"settings", "config", "настройки", "конфиг"};
public override string[] Aliases { get; } = { "settings", "config", "настройки", "конфиг" };
public override int ArgsLengthRequired => 0;
public override Task Run(SocketCommandContext context, string[] args) {
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.ManageGuild);
if (permissionCheckResponse != "") {
@ -41,7 +41,7 @@ public class SettingsCommand : Command {
if (IsBool(currentValue))
currentValue = YesOrNo(currentValue == "true");
else
format = Utils.WrapInline("{0}")!;
format = Utils.Wrap("{0}")!;
}
currentSettings.Append($"{Utils.GetMessage($"Settings{setting.Key}")} (`{setting.Key}`): ")
@ -56,9 +56,11 @@ public class SettingsCommand : Command {
var selectedSetting = args[0].ToLower();
var exists = false;
foreach (var setting in Boyfriend.DefaultConfig) {
if (selectedSetting != setting.Key.ToLower()) continue;
selectedSetting = setting.Key;
// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
// The performance impact is not worth it
foreach (var setting in Boyfriend.DefaultConfig.Keys) {
if (selectedSetting != setting.ToLower()) continue;
selectedSetting = setting;
exists = true;
break;
}
@ -78,9 +80,7 @@ public class SettingsCommand : Command {
Error(Messages.InvalidSettingValue, false);
return Task.CompletedTask;
}
} else {
value = "reset";
}
} else { value = "reset"; }
if (IsBool(Boyfriend.DefaultConfig[selectedSetting]) && !IsBool(value)) {
value = value switch {
@ -99,7 +99,7 @@ public class SettingsCommand : Command {
var mention = Utils.ParseMention(value);
if (mention != 0) value = mention.ToString();
var formatting = Utils.WrapInline("{0}")!;
var formatting = Utils.Wrap("{0}")!;
if (selectedSetting.EndsWith("Channel"))
formatting = "<#{0}>";
if (selectedSetting.EndsWith("Role"))
@ -131,6 +131,8 @@ public class SettingsCommand : Command {
return Task.CompletedTask;
}
if (selectedSetting == "MuteRole") Utils.RemoveMuteRoleFromCache(ulong.Parse(config[selectedSetting]));
config[selectedSetting] = value;
}
@ -153,4 +155,4 @@ public class SettingsCommand : Command {
private static bool IsBool(string value) {
return value is "true" or "false";
}
}
}

View file

@ -5,11 +5,11 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class UnbanCommand : Command {
public override string[] Aliases { get; } = {"unban", "разбан"};
public override string[] Aliases { get; } = { "unban", "разбан" };
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.BanMembers);
if (permissionCheckResponse != "") {
@ -38,8 +38,8 @@ public class UnbanCommand : Command {
var requestOptions = Utils.GetRequestOptions($"({author}) {reason}");
await guild.RemoveBanAsync(toUnban, requestOptions);
var feedback = string.Format(Messages.FeedbackUserUnbanned, toUnban.Mention, Utils.WrapInline(reason));
var feedback = string.Format(Messages.FeedbackUserUnbanned, toUnban.Mention, Utils.Wrap(reason));
Success(feedback, author.Mention, false, false);
await Utils.SendFeedback(feedback, guild.Id, author.Mention, true);
}
}
}

View file

@ -5,11 +5,11 @@ using Discord.WebSocket;
namespace Boyfriend.Commands;
public class UnmuteCommand : Command {
public override string[] Aliases { get; } = {"unmute", "размут"};
public override string[] Aliases { get; } = { "unmute", "размут" };
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
var author = (SocketGuildUser) context.User;
var author = (SocketGuildUser)context.User;
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.ModerateMembers);
if (permissionCheckResponse != "") {
@ -40,13 +40,6 @@ public class UnmuteCommand : Command {
var role = Utils.GetMuteRole(ref guild);
if (role != null) {
var muted = false;
foreach (var x in toUnmute.Roles) {
if (x != role) continue;
muted = true;
break;
}
var rolesRemoved = Boyfriend.GetRemovedRoles(guild.Id);
if (rolesRemoved.ContainsKey(toUnmute.Id)) {
@ -55,9 +48,7 @@ public class UnmuteCommand : Command {
CommandHandler.ConfigWriteScheduled = true;
}
if (muted) {
await toUnmute.RemoveRoleAsync(role, requestOptions);
} else {
if (toUnmute.Roles.Contains(role)) { await toUnmute.RemoveRoleAsync(role, requestOptions); } else {
Error(Messages.MemberNotMuted, false);
return;
}
@ -71,7 +62,7 @@ public class UnmuteCommand : Command {
await toUnmute.RemoveTimeOutAsync();
}
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.WrapInline(reason));
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
Success(feedback, author.Mention, false, false);
await Utils.SendFeedback(feedback, guild.Id, author.Mention, true);
}