forked from TeamInklings/Octobot
Keep reply emojis as consts in a separate class (#8)
This commit is contained in:
parent
1258496697
commit
2596b48bde
9 changed files with 65 additions and 52 deletions
|
@ -7,12 +7,6 @@ using Discord.WebSocket;
|
||||||
namespace Boyfriend;
|
namespace Boyfriend;
|
||||||
|
|
||||||
public sealed class CommandProcessor {
|
public sealed class CommandProcessor {
|
||||||
private const string Success = ":white_check_mark: ";
|
|
||||||
private const string MissingArgument = ":keyboard: ";
|
|
||||||
private const string InvalidArgument = ":construction: ";
|
|
||||||
private const string NoAccess = ":no_entry_sign: ";
|
|
||||||
private const string CantInteract = ":vertical_traffic_light: ";
|
|
||||||
|
|
||||||
private static readonly string Mention = $"<@{Boyfriend.Client.CurrentUser.Id}>";
|
private static readonly string Mention = $"<@{Boyfriend.Client.CurrentUser.Id}>";
|
||||||
|
|
||||||
public static readonly ICommand[] Commands = {
|
public static readonly ICommand[] Commands = {
|
||||||
|
@ -79,7 +73,7 @@ public sealed class CommandProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reply(string response, string? customEmoji = null) {
|
public void Reply(string response, string? customEmoji = null) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? Success}{response}", Context.Message);
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}", Context.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Audit(string action, bool isPublic = true) {
|
public void Audit(string action, bool isPublic = true) {
|
||||||
|
@ -111,14 +105,14 @@ public sealed class CommandProcessor {
|
||||||
public string? GetRemaining(string[] from, int startIndex, string? argument) {
|
public string? GetRemaining(string[] from, int startIndex, string? argument) {
|
||||||
if (startIndex >= from.Length && argument is not null)
|
if (startIndex >= from.Length && argument is not null)
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{MissingArgument}{Utils.GetMessage($"Missing{argument}")}", Context.Message);
|
$"{ReplyEmojis.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message);
|
||||||
else return string.Join(" ", from, startIndex, from.Length - startIndex);
|
else return string.Join(" ", from, startIndex, from.Length - startIndex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SocketUser? GetUser(string[] args, string[] cleanArgs, int index, string? argument) {
|
public SocketUser? GetUser(string[] args, string[] cleanArgs, int index, string? argument) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{MissingArgument}{Messages.MissingUser}",
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -126,14 +120,14 @@ public sealed class CommandProcessor {
|
||||||
var user = Boyfriend.Client.GetUser(Utils.ParseMention(args[index]));
|
var user = Boyfriend.Client.GetUser(Utils.ParseMention(args[index]));
|
||||||
if (user is null && argument is not null)
|
if (user is null && argument is not null)
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{InvalidArgument}{string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasPermission(GuildPermission permission) {
|
public bool HasPermission(GuildPermission permission) {
|
||||||
if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) {
|
if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{NoAccess}{Utils.GetMessage($"BotCannot{permission}")}",
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.NoPermission} {Utils.GetMessage($"BotCannot{permission}")}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +135,7 @@ public sealed class CommandProcessor {
|
||||||
if (Context.Guild.GetUser(Context.User.Id).GuildPermissions.Has(permission)
|
if (Context.Guild.GetUser(Context.User.Id).GuildPermissions.Has(permission)
|
||||||
|| Context.Guild.OwnerId == Context.User.Id) return true;
|
|| Context.Guild.OwnerId == Context.User.Id) return true;
|
||||||
|
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{NoAccess}{Utils.GetMessage($"UserCannot{permission}")}",
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.NoPermission} {Utils.GetMessage($"UserCannot{permission}")}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +146,7 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public SocketGuildUser? GetMember(string[] args, string[] cleanArgs, int index, string? argument) {
|
public SocketGuildUser? GetMember(string[] args, string[] cleanArgs, int index, string? argument) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{MissingArgument}{Messages.MissingMember}",
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +154,7 @@ public sealed class CommandProcessor {
|
||||||
var member = Context.Guild.GetUser(Utils.ParseMention(args[index]));
|
var member = Context.Guild.GetUser(Utils.ParseMention(args[index]));
|
||||||
if (member is null && argument is not null)
|
if (member is null && argument is not null)
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{InvalidArgument}{string.Format(Messages.InvalidMember, Utils.Wrap(cleanArgs[index]))}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidMember, Utils.Wrap(cleanArgs[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +165,7 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public ulong? GetBan(string[] args, int index) {
|
public ulong? GetBan(string[] args, int index) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{MissingArgument}{Messages.MissingUser}",
|
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -188,14 +182,14 @@ public sealed class CommandProcessor {
|
||||||
public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) {
|
public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{MissingArgument}{string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}",
|
$"{ReplyEmojis.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(args[index], out var i)) {
|
if (!int.TryParse(args[index], out var i)) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{InvalidArgument}{string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -203,14 +197,14 @@ public sealed class CommandProcessor {
|
||||||
if (argument is null) return i;
|
if (argument is null) return i;
|
||||||
if (i < min) {
|
if (i < min) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{InvalidArgument}{string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i <= max) return i;
|
if (i <= max) return i;
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{InvalidArgument}{string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -252,31 +246,31 @@ public sealed class CommandProcessor {
|
||||||
public bool CanInteractWith(SocketGuildUser user, string action) {
|
public bool CanInteractWith(SocketGuildUser user, string action) {
|
||||||
if (Context.User.Id == user.Id) {
|
if (Context.User.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.CurrentUser.Id == user.Id) {
|
if (Context.Guild.CurrentUser.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.Owner.Id == user.Id) {
|
if (Context.Guild.Owner.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.Owner.Id == Context.User.Id || GetMember().Hierarchy > user.Hierarchy) return true;
|
if (Context.Guild.Owner.Id == Context.User.Id || GetMember().Hierarchy > user.Hierarchy) return true;
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||||
$"{CantInteract}{Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
@ -29,7 +29,7 @@ public sealed class BanCommand : ICommand {
|
||||||
|
|
||||||
var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention,
|
var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention,
|
||||||
Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason));
|
Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason));
|
||||||
cmd.Reply(feedback, ":hammer: ");
|
cmd.Reply(feedback, ReplyEmojis.Banned);
|
||||||
cmd.Audit(feedback);
|
cmd.Audit(feedback);
|
||||||
|
|
||||||
if (duration.TotalSeconds > 0)
|
if (duration.TotalSeconds > 0)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public sealed class HelpCommand : ICommand {
|
||||||
foreach (var command in CommandProcessor.Commands)
|
foreach (var command in CommandProcessor.Commands)
|
||||||
toSend.Append(
|
toSend.Append(
|
||||||
$"\n`{prefix}{command.Aliases[0]}`: {Utils.GetMessage($"CommandDescription{command.Aliases[0].Titleize()}")}");
|
$"\n`{prefix}{command.Aliases[0]}`: {Utils.GetMessage($"CommandDescription{command.Aliases[0].Titleize()}")}");
|
||||||
cmd.Reply(toSend.ToString(), ":page_facing_up: ");
|
cmd.Reply(toSend.ToString(), ReplyEmojis.Help);
|
||||||
toSend.Clear();
|
toSend.Clear();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
@ -24,7 +24,7 @@ public sealed class KickCommand : ICommand {
|
||||||
|
|
||||||
await toKick.KickAsync(guildKickMessage);
|
await toKick.KickAsync(guildKickMessage);
|
||||||
var format = string.Format(Messages.FeedbackMemberKicked, toKick.Mention, Utils.Wrap(reason));
|
var format = string.Format(Messages.FeedbackMemberKicked, toKick.Mention, Utils.Wrap(reason));
|
||||||
cmd.Reply(format, ":police_car: ");
|
cmd.Reply(format, ReplyEmojis.Kicked);
|
||||||
cmd.Audit(format);
|
cmd.Audit(format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public sealed class MuteCommand : ICommand {
|
||||||
|| (toMute.TimedOutUntil is not null
|
|| (toMute.TimedOutUntil is not null
|
||||||
&& toMute.TimedOutUntil.Value.ToUnixTimeSeconds()
|
&& toMute.TimedOutUntil.Value.ToUnixTimeSeconds()
|
||||||
> DateTimeOffset.Now.ToUnixTimeSeconds())) {
|
> DateTimeOffset.Now.ToUnixTimeSeconds())) {
|
||||||
cmd.Reply(Messages.MemberAlreadyMuted, ":x: ");
|
cmd.Reply(Messages.MemberAlreadyMuted, ReplyEmojis.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public sealed class MuteCommand : ICommand {
|
||||||
foreach (var roleId in mutedRemovedRoles) await toMute.AddRoleAsync(roleId);
|
foreach (var roleId in mutedRemovedRoles) await toMute.AddRoleAsync(roleId);
|
||||||
rolesRemoved.Remove(toMute.Id);
|
rolesRemoved.Remove(toMute.Id);
|
||||||
cmd.ConfigWriteScheduled = true;
|
cmd.ConfigWriteScheduled = true;
|
||||||
cmd.Reply(Messages.RolesReturned, ":warning: ");
|
cmd.Reply(Messages.RolesReturned, ReplyEmojis.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.HasPermission(GuildPermission.ModerateMembers) && cmd.CanInteractWith(toMute, "Mute"))
|
if (cmd.HasPermission(GuildPermission.ModerateMembers) && cmd.CanInteractWith(toMute, "Mute"))
|
||||||
|
@ -55,7 +55,7 @@ public sealed class MuteCommand : ICommand {
|
||||||
rolesRemoved.Add(userRole.Id);
|
rolesRemoved.Add(userRole.Id);
|
||||||
} catch (HttpException e) {
|
} catch (HttpException e) {
|
||||||
cmd.Reply(string.Format(Messages.RoleRemovalFailed, $"<@&{userRole}>", Utils.Wrap(e.Reason)),
|
cmd.Reply(string.Format(Messages.RoleRemovalFailed, $"<@&{userRole}>", Utils.Wrap(e.Reason)),
|
||||||
":warning: ");
|
ReplyEmojis.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boyfriend.GetRemovedRoles(guild.Id).Add(toMute.Id, rolesRemoved.AsReadOnly());
|
Boyfriend.GetRemovedRoles(guild.Id).Add(toMute.Id, rolesRemoved.AsReadOnly());
|
||||||
|
@ -68,12 +68,12 @@ public sealed class MuteCommand : ICommand {
|
||||||
await Task.FromResult(Utils.DelayedUnmuteAsync(cmd, toMute, Messages.PunishmentExpired, duration));
|
await Task.FromResult(Utils.DelayedUnmuteAsync(cmd, toMute, Messages.PunishmentExpired, duration));
|
||||||
} else {
|
} else {
|
||||||
if (!hasDuration || duration.TotalDays > 28) {
|
if (!hasDuration || duration.TotalDays > 28) {
|
||||||
cmd.Reply(Messages.DurationRequiredForTimeOuts, ":x: ");
|
cmd.Reply(Messages.DurationRequiredForTimeOuts, ReplyEmojis.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toMute.IsBot) {
|
if (toMute.IsBot) {
|
||||||
cmd.Reply(Messages.CannotTimeOutBot, ":x: ");
|
cmd.Reply(Messages.CannotTimeOutBot, ReplyEmojis.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public sealed class MuteCommand : ICommand {
|
||||||
var feedback = string.Format(Messages.FeedbackMemberMuted, toMute.Mention,
|
var feedback = string.Format(Messages.FeedbackMemberMuted, toMute.Mention,
|
||||||
Utils.GetHumanizedTimeOffset(duration),
|
Utils.GetHumanizedTimeOffset(duration),
|
||||||
Utils.Wrap(reason));
|
Utils.Wrap(reason));
|
||||||
cmd.Reply(feedback, ":mute: ");
|
cmd.Reply(feedback, ReplyEmojis.Muted);
|
||||||
cmd.Audit(feedback);
|
cmd.Audit(feedback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
public sealed class PingCommand : ICommand {
|
public sealed class PingCommand : ICommand {
|
||||||
public string[] Aliases { get; } = { "ping", "latency", "pong", "пинг", "задержка", "понг" };
|
public string[] Aliases { get; } = { "ping", "latency", "pong", "пинг", "задержка", "понг" };
|
||||||
|
@ -10,7 +10,7 @@ public sealed class PingCommand : ICommand {
|
||||||
.Append(Math.Abs(DateTimeOffset.Now.Subtract(cmd.Context.Message.Timestamp).TotalMilliseconds))
|
.Append(Math.Abs(DateTimeOffset.Now.Subtract(cmd.Context.Message.Timestamp).TotalMilliseconds))
|
||||||
.Append(Messages.Milliseconds);
|
.Append(Messages.Milliseconds);
|
||||||
|
|
||||||
cmd.Reply(builder.ToString(), ":signal_strength: ");
|
cmd.Reply(builder.ToString(), ReplyEmojis.Ping);
|
||||||
builder.Clear();
|
builder.Clear();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public sealed class SettingsCommand : ICommand {
|
||||||
.AppendFormat(format, currentValue).AppendLine();
|
.AppendFormat(format, currentValue).AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Reply(currentSettings.ToString(), ":gear: ");
|
cmd.Reply(currentSettings.ToString(), ReplyEmojis.SettingsList);
|
||||||
currentSettings.Clear();
|
currentSettings.Clear();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public sealed class SettingsCommand : ICommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
cmd.Reply(Messages.SettingDoesntExist, ":x: ");
|
cmd.Reply(Messages.SettingDoesntExist, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public sealed class SettingsCommand : ICommand {
|
||||||
value = value.Replace(" ", "").ToLower();
|
value = value.Replace(" ", "").ToLower();
|
||||||
if (value.StartsWith(",") || value.Count(x => x is ',') > 1 ||
|
if (value.StartsWith(",") || value.Count(x => x is ',') > 1 ||
|
||||||
(!value.Contains("interested") && !value.Contains("users") && !value.Contains("role"))) {
|
(!value.Contains("interested") && !value.Contains("users") && !value.Contains("role"))) {
|
||||||
cmd.Reply(Messages.InvalidSettingValue, ":x: ");
|
cmd.Reply(Messages.InvalidSettingValue, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public sealed class SettingsCommand : ICommand {
|
||||||
_ => value
|
_ => value
|
||||||
};
|
};
|
||||||
if (!IsBool(value)) {
|
if (!IsBool(value)) {
|
||||||
cmd.Reply(Messages.InvalidSettingValue, ":x: ");
|
cmd.Reply(Messages.InvalidSettingValue, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,22 +106,22 @@ public sealed class SettingsCommand : ICommand {
|
||||||
} else {
|
} else {
|
||||||
if (value == config[selectedSetting]) {
|
if (value == config[selectedSetting]) {
|
||||||
cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue),
|
cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue),
|
||||||
":x: ");
|
ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedSetting is "Lang" && !Utils.CultureInfoCache.ContainsKey(value)) {
|
if (selectedSetting is "Lang" && !Utils.CultureInfoCache.ContainsKey(value)) {
|
||||||
cmd.Reply(Messages.LanguageNotSupported, ":x: ");
|
cmd.Reply(Messages.LanguageNotSupported, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedSetting.EndsWith("Channel") && guild.GetTextChannel(mention) is null) {
|
if (selectedSetting.EndsWith("Channel") && guild.GetTextChannel(mention) is null) {
|
||||||
cmd.Reply(Messages.InvalidChannel, ":x: ");
|
cmd.Reply(Messages.InvalidChannel, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedSetting.EndsWith("Role") && guild.GetRole(mention) is null) {
|
if (selectedSetting.EndsWith("Role") && guild.GetRole(mention) is null) {
|
||||||
cmd.Reply(Messages.InvalidRole, ":x: ");
|
cmd.Reply(Messages.InvalidRole, ReplyEmojis.Error);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public sealed class SettingsCommand : ICommand {
|
||||||
cmd.ConfigWriteScheduled = true;
|
cmd.ConfigWriteScheduled = true;
|
||||||
|
|
||||||
var replyFormat = string.Format(Messages.FeedbackSettingsUpdated, localizedSelectedSetting, formattedValue);
|
var replyFormat = string.Format(Messages.FeedbackSettingsUpdated, localizedSelectedSetting, formattedValue);
|
||||||
cmd.Reply(replyFormat, ":control_knobs: ");
|
cmd.Reply(replyFormat, ReplyEmojis.SettingsSet);
|
||||||
cmd.Audit(replyFormat, false);
|
cmd.Audit(replyFormat, false);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
@ -34,7 +34,7 @@ public sealed class UnmuteCommand : ICommand {
|
||||||
} else {
|
} else {
|
||||||
if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() <
|
if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() <
|
||||||
DateTimeOffset.Now.ToUnixTimeSeconds()) {
|
DateTimeOffset.Now.ToUnixTimeSeconds()) {
|
||||||
cmd.Reply(Messages.MemberNotMuted, ":x: ");
|
cmd.Reply(Messages.MemberNotMuted, ReplyEmojis.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public sealed class UnmuteCommand : ICommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
|
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
|
||||||
cmd.Reply(feedback, ":loud_sound: ");
|
cmd.Reply(feedback, ReplyEmojis.Unmuted);
|
||||||
cmd.Audit(feedback);
|
cmd.Audit(feedback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
Boyfriend/ReplyEmojis.cs
Normal file
19
Boyfriend/ReplyEmojis.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
namespace Boyfriend;
|
||||||
|
|
||||||
|
public static class ReplyEmojis {
|
||||||
|
public const string Success = ":white_check_mark:";
|
||||||
|
public const string Warning = ":warning: ";
|
||||||
|
public const string Error = ":x:";
|
||||||
|
public const string MissingArgument = ":keyboard:";
|
||||||
|
public const string InvalidArgument = ":construction:";
|
||||||
|
public const string NoPermission = ":no_entry_sign:";
|
||||||
|
public const string CantInteract = ":vertical_traffic_light:";
|
||||||
|
public const string Help = ":page_facing_up:";
|
||||||
|
public const string SettingsList = ":gear:";
|
||||||
|
public const string SettingsSet = ":control_knobs:";
|
||||||
|
public const string Ping = ":signal_strength:";
|
||||||
|
public const string Banned = ":hammer:";
|
||||||
|
public const string Kicked = ":police_car:";
|
||||||
|
public const string Muted = ":mute:";
|
||||||
|
public const string Unmuted = ":loud_sound:";
|
||||||
|
}
|
Reference in a new issue