diff --git a/Boyfriend/Boyfriend.cs b/Boyfriend/Boyfriend.cs index 8ff5ca8..b4aa241 100644 --- a/Boyfriend/Boyfriend.cs +++ b/Boyfriend/Boyfriend.cs @@ -19,30 +19,28 @@ public static class Boyfriend { private static readonly Game Activity = new("Retrospecter - Genocide", ActivityType.Listening); private static readonly Dictionary> GuildConfigDictionary = new(); + private static readonly Dictionary>> RemovedRolesDictionary = new(); - private static readonly Dictionary EmptyGuildConfig = new(); - private static readonly Dictionary> EmptyRemovedRoles = new(); - public static readonly Dictionary DefaultConfig = new() { - {"Lang", "en"}, - {"Prefix", "!"}, - {"RemoveRolesOnMute", "false"}, - {"SendWelcomeMessages", "true"}, - {"ReceiveStartupMessages", "false"}, - {"FrowningFace", "true"}, - {"WelcomeMessage", Messages.DefaultWelcomeMessage}, - {"EventStartedReceivers", "interested,role"}, - {"StarterRole", "0"}, - {"MuteRole", "0"}, - {"EventNotifyReceiverRole", "0"}, - {"AdminLogChannel", "0"}, - {"BotLogChannel", "0"}, - {"EventCreatedChannel", "0"}, - {"EventStartedChannel", "0"}, - {"EventCancelledChannel", "0"}, - {"EventCompletedChannel", "0"} + { "Lang", "en" }, + { "Prefix", "!" }, + { "RemoveRolesOnMute", "false" }, + { "SendWelcomeMessages", "true" }, + { "ReceiveStartupMessages", "false" }, + { "FrowningFace", "true" }, + { "WelcomeMessage", Messages.DefaultWelcomeMessage }, + { "EventStartedReceivers", "interested,role" }, + { "StarterRole", "0" }, + { "MuteRole", "0" }, + { "EventNotifyReceiverRole", "0" }, + { "AdminLogChannel", "0" }, + { "BotLogChannel", "0" }, + { "EventCreatedChannel", "0" }, + { "EventStartedChannel", "0" }, + { "EventCancelledChannel", "0" }, + { "EventCompletedChannel", "0" } }; public static void Main() { @@ -79,7 +77,7 @@ public static class Boyfriend { public static Dictionary GetGuildConfig(ulong id) { if (!RemovedRolesDictionary.ContainsKey(id)) - RemovedRolesDictionary.Add(id, EmptyRemovedRoles); + RemovedRolesDictionary.Add(id, new Dictionary>()); if (GuildConfigDictionary.ContainsKey(id)) return GuildConfigDictionary[id]; @@ -88,15 +86,19 @@ public static class Boyfriend { if (!File.Exists(path)) File.Create(path).Dispose(); var json = File.ReadAllText(path); - var config = JsonConvert.DeserializeObject>(json) ?? EmptyGuildConfig; + var config = JsonConvert.DeserializeObject>(json) + ?? new Dictionary(); - foreach (var key in DefaultConfig.Keys) - if (!config.ContainsKey(key)) - config.Add(key, DefaultConfig[key]); - - foreach (var key in config.Keys) - if (!DefaultConfig.ContainsKey(key)) + if (config.Keys.Count < DefaultConfig.Keys.Count) { + // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator + // Avoids a closure allocation with the config variable + foreach (var key in DefaultConfig.Keys) + if (!config.ContainsKey(key)) + config.Add(key, DefaultConfig[key]); + } else if (config.Keys.Count > DefaultConfig.Keys.Count) { + foreach (var key in config.Keys.Where(key => !DefaultConfig.ContainsKey(key))) config.Remove(key); + } GuildConfigDictionary.Add(id, config); @@ -111,8 +113,8 @@ public static class Boyfriend { if (!File.Exists(path)) File.Create(path); var json = File.ReadAllText(path); - var removedRoles = JsonConvert.DeserializeObject>>(json) ?? - EmptyRemovedRoles; + var removedRoles = JsonConvert.DeserializeObject>>(json) + ?? new Dictionary>(); RemovedRolesDictionary.Add(id, removedRoles); @@ -121,9 +123,8 @@ public static class Boyfriend { public static SocketGuild FindGuild(ulong channel) { if (GuildCache.ContainsKey(channel)) return GuildCache[channel]; - foreach (var guild in Client.Guilds) - foreach (var x in guild.Channels) { - if (x.Id != channel) continue; + foreach (var guild in Client.Guilds) { + if (guild.Channels.All(x => x.Id != channel)) continue; GuildCache.Add(channel, guild); return guild; } diff --git a/Boyfriend/Boyfriend.csproj b/Boyfriend/Boyfriend.csproj index a05d38d..80329ec 100644 --- a/Boyfriend/Boyfriend.csproj +++ b/Boyfriend/Boyfriend.csproj @@ -15,10 +15,10 @@ - + - + diff --git a/Boyfriend/CommandHandler.cs b/Boyfriend/CommandHandler.cs index 7754d53..0cd494b 100644 --- a/Boyfriend/CommandHandler.cs +++ b/Boyfriend/CommandHandler.cs @@ -8,7 +8,6 @@ using Discord.WebSocket; namespace Boyfriend; public static class CommandHandler { - public static readonly Command[] Commands = { new BanCommand(), new ClearCommand(), new HelpCommand(), new KickCommand(), new MuteCommand(), new PingCommand(), @@ -34,9 +33,7 @@ public static class CommandHandler { var config = Boyfriend.GetGuildConfig(guild.Id); Regex regex; - if (RegexCache.ContainsKey(config["Prefix"])) { - regex = RegexCache[config["Prefix"]]; - } else { + if (RegexCache.ContainsKey(config["Prefix"])) { regex = RegexCache[config["Prefix"]]; } else { regex = new Regex(Regex.Escape(config["Prefix"])); RegexCache.Add(config["Prefix"], regex); } @@ -61,13 +58,14 @@ public static class CommandHandler { if (currentLine != list.Length) continue; if (ConfigWriteScheduled) await Boyfriend.WriteGuildConfig(guild.Id); - await context.Message.ReplyAsync(StackedReplyMessage.ToString(), false, null, AllowedMentions.None); + await message.ReplyAsync(StackedReplyMessage.ToString(), false, null, AllowedMentions.None); var adminChannel = Utils.GetAdminLogChannel(guild.Id); var systemChannel = guild.SystemChannel; - if (adminChannel != null) + if (StackedPrivateFeedback.Length > 0 && adminChannel != null && adminChannel.Id != message.Channel.Id) await Utils.SilentSendAsync(adminChannel, StackedPrivateFeedback.ToString()); - if (systemChannel != null) + if (StackedPublicFeedback.Length > 0 && systemChannel != null && systemChannel.Id != adminChannel?.Id + && systemChannel.Id != message.Channel.Id) await Utils.SilentSendAsync(systemChannel, StackedPublicFeedback.ToString()); } } diff --git a/Boyfriend/Commands/BanCommand.cs b/Boyfriend/Commands/BanCommand.cs index 80e8b0c..b2cad58 100644 --- a/Boyfriend/Commands/BanCommand.cs +++ b/Boyfriend/Commands/BanCommand.cs @@ -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(); } } } diff --git a/Boyfriend/Commands/Command.cs b/Boyfriend/Commands/Command.cs index 4903177..ec8590b 100644 --- a/Boyfriend/Commands/Command.cs +++ b/Boyfriend/Commands/Command.cs @@ -4,7 +4,6 @@ using Discord.Commands; namespace Boyfriend.Commands; public abstract class Command { - public abstract string[] Aliases { get; } public abstract int ArgsLengthRequired { get; } diff --git a/Boyfriend/Commands/KickCommand.cs b/Boyfriend/Commands/KickCommand.cs index ffa61eb..505178e 100644 --- a/Boyfriend/Commands/KickCommand.cs +++ b/Boyfriend/Commands/KickCommand.cs @@ -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); } diff --git a/Boyfriend/Commands/MuteCommand.cs b/Boyfriend/Commands/MuteCommand.cs index 144d76f..47c3ded 100644 --- a/Boyfriend/Commands/MuteCommand.cs +++ b/Boyfriend/Commands/MuteCommand.cs @@ -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); } } -} \ No newline at end of file +} diff --git a/Boyfriend/Commands/SettingsCommand.cs b/Boyfriend/Commands/SettingsCommand.cs index 368c5d8..cfd1c23 100644 --- a/Boyfriend/Commands/SettingsCommand.cs +++ b/Boyfriend/Commands/SettingsCommand.cs @@ -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"; } -} +} \ No newline at end of file diff --git a/Boyfriend/Commands/UnbanCommand.cs b/Boyfriend/Commands/UnbanCommand.cs index 8741a3e..a6576af 100644 --- a/Boyfriend/Commands/UnbanCommand.cs +++ b/Boyfriend/Commands/UnbanCommand.cs @@ -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); } -} +} \ No newline at end of file diff --git a/Boyfriend/Commands/UnmuteCommand.cs b/Boyfriend/Commands/UnmuteCommand.cs index e4af83b..f0e7951 100644 --- a/Boyfriend/Commands/UnmuteCommand.cs +++ b/Boyfriend/Commands/UnmuteCommand.cs @@ -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); } diff --git a/Boyfriend/EventHandler.cs b/Boyfriend/EventHandler.cs index 8109395..fd31995 100644 --- a/Boyfriend/EventHandler.cs +++ b/Boyfriend/EventHandler.cs @@ -1,6 +1,7 @@ using Boyfriend.Commands; using Discord; using Discord.Commands; +using Discord.Rest; using Discord.WebSocket; namespace Boyfriend; @@ -42,21 +43,23 @@ public class EventHandler { Utils.SetCurrentLanguage(guild.Id); + var mention = msg.Author.Mention; + + await Task.Delay(500); + var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First(); - var mention = auditLogEntry.User.Mention; - if (auditLogEntry.Action != ActionType.MessageDeleted || - DateTimeOffset.Now.Subtract(auditLogEntry.CreatedAt).TotalMilliseconds > 500 || - auditLogEntry.User.IsBot) mention = msg.Author.Mention; + if (auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id) + mention = auditLogEntry.User.Mention; await Utils.SendFeedback( string.Format(Messages.CachedMessageDeleted, msg.Author.Mention, Utils.MentionChannel(channel.Id), - Utils.WrapAsNeeded(msg.CleanContent)), guild.Id, mention); + Utils.Wrap(msg.CleanContent)), guild.Id, mention); } private static async Task MessageReceivedEvent(SocketMessage messageParam) { if (messageParam is not SocketUserMessage message) return; - var user = (SocketGuildUser) message.Author; + var user = (SocketGuildUser)message.Author; var guild = user.Guild; var guildConfig = Boyfriend.GetGuildConfig(guild.Id); @@ -98,10 +101,12 @@ public class EventHandler { Utils.SetCurrentLanguage(guildId); + var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940; + await Utils.SendFeedback( string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id), - Utils.WrapAsNeeded(msg.CleanContent), Utils.WrapAsNeeded(messageSocket.Content)), guildId, - msg.Author.Mention); + Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)), + guildId, msg.Author.Mention); } private static async Task UserJoinedEvent(SocketGuildUser user) { @@ -127,11 +132,11 @@ public class EventHandler { if (role != null) roleMention = $"{role.Mention} "; - var location = Utils.WrapInline(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id); + var location = Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id); await Utils.SilentSendAsync(channel, string.Format(Messages.EventCreated, "\n", roleMention, scheduledEvent.Creator.Mention, - Utils.WrapInline(scheduledEvent.Name), location, + Utils.Wrap(scheduledEvent.Name), location, scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), Utils.Wrap(scheduledEvent.Description)), true); } @@ -142,7 +147,7 @@ public class EventHandler { var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCancelledChannel"])); if (channel != null) - await channel.SendMessageAsync(string.Format(Messages.EventCancelled, Utils.WrapInline(scheduledEvent.Name), + await channel.SendMessageAsync(string.Format(Messages.EventCancelled, Utils.Wrap(scheduledEvent.Name), eventConfig["FrowningFace"] == "true" ? $" {Messages.SettingsFrowningFace}" : "")); } @@ -158,12 +163,12 @@ public class EventHandler { if (receivers.Contains("role") && role != null) mentions.Append($"{role.Mention} "); if (receivers.Contains("users") || receivers.Contains("interested")) - foreach (var user in await scheduledEvent.GetUsersAsync(15)) - mentions = mentions.Append($"{user.Mention} "); + mentions = (await scheduledEvent.GetUsersAsync(15)).Aggregate(mentions, + (current, user) => current.Append($"{user.Mention} ")); await channel.SendMessageAsync(string.Format(Messages.EventStarted, mentions, - Utils.WrapInline(scheduledEvent.Name), - Utils.WrapInline(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id))); + Utils.Wrap(scheduledEvent.Name), + Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id))); mentions.Clear(); } } @@ -173,7 +178,7 @@ public class EventHandler { var eventConfig = Boyfriend.GetGuildConfig(guild.Id); var channel = guild.GetTextChannel(Convert.ToUInt64(eventConfig["EventCompletedChannel"])); if (channel != null) - await channel.SendMessageAsync(string.Format(Messages.EventCompleted, Utils.WrapInline(scheduledEvent.Name), - Utils.WrapInline(scheduledEvent.StartTime.Subtract(DateTimeOffset.Now).Negate().ToString()))); + await channel.SendMessageAsync(string.Format(Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name), + Utils.Wrap(scheduledEvent.StartTime.Subtract(DateTimeOffset.Now).Negate().ToString()))); } } diff --git a/Boyfriend/Messages.Designer.cs b/Boyfriend/Messages.Designer.cs index 31866d9..08276fc 100644 --- a/Boyfriend/Messages.Designer.cs +++ b/Boyfriend/Messages.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,46 +11,32 @@ namespace Boyfriend { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Messages { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Messages() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Boyfriend.Messages", typeof(Messages).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Boyfriend.Messages", typeof(Messages).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,823 +45,556 @@ namespace Boyfriend { } } - /// - /// Looks up a localized string similar to Too many mentions in 1 message. - /// - internal static string AutobanReason { - get { - return ResourceManager.GetString("AutobanReason", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Bah! . - /// - internal static string Beep1 { - get { - return ResourceManager.GetString("Beep1", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Bop! . - /// - internal static string Beep2 { - get { - return ResourceManager.GetString("Beep2", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Beep! . - /// - internal static string Beep3 { - get { - return ResourceManager.GetString("Beep3", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Deleted message from {0} in channel {1}: {2}. - /// - internal static string CachedMessageDeleted { - get { - return ResourceManager.GetString("CachedMessageDeleted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Edited message in channel {0}: {1} -> {2}. - /// - internal static string CachedMessageEdited { - get { - return ResourceManager.GetString("CachedMessageEdited", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I cannot use time-outs on other bots! Try to set a mute role in settings. - /// - internal static string CannotTimeOutBot { - get { - return ResourceManager.GetString("CannotTimeOutBot", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not specified. - /// - internal static string ChannelNotSpecified { - get { - return ResourceManager.GetString("ChannelNotSpecified", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Too many messages specified!. - /// - internal static string ClearAmountTooLarge { - get { - return ResourceManager.GetString("ClearAmountTooLarge", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid message amount specified!. - /// - internal static string ClearInvalidAmountSpecified { - get { - return ResourceManager.GetString("ClearInvalidAmountSpecified", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Negative message amount specified!. - /// - internal static string ClearNegativeAmount { - get { - return ResourceManager.GetString("ClearNegativeAmount", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Bans a user. - /// - internal static string CommandDescriptionBan { - get { - return ResourceManager.GetString("CommandDescriptionBan", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Deletes a specified amount of messages in this channel. - /// - internal static string CommandDescriptionClear { - get { - return ResourceManager.GetString("CommandDescriptionClear", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shows this message. - /// - internal static string CommandDescriptionHelp { - get { - return ResourceManager.GetString("CommandDescriptionHelp", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Kicks a member. - /// - internal static string CommandDescriptionKick { - get { - return ResourceManager.GetString("CommandDescriptionKick", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Mutes a member. - /// - internal static string CommandDescriptionMute { - get { - return ResourceManager.GetString("CommandDescriptionMute", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shows latency to Discord servers (not counting local processing time). - /// - internal static string CommandDescriptionPing { - get { - return ResourceManager.GetString("CommandDescriptionPing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Allows you to change certain preferences for this guild. - /// - internal static string CommandDescriptionSettings { - get { - return ResourceManager.GetString("CommandDescriptionSettings", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unbans a user. - /// - internal static string CommandDescriptionUnban { - get { - return ResourceManager.GetString("CommandDescriptionUnban", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unmutes a member. - /// - internal static string CommandDescriptionUnmute { - get { - return ResourceManager.GetString("CommandDescriptionUnmute", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Command help:. - /// - internal static string CommandHelp { - get { - return ResourceManager.GetString("CommandHelp", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I do not have permission to execute this command!. - /// - internal static string CommandNoPermissionBot { - get { - return ResourceManager.GetString("CommandNoPermissionBot", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to You do not have permission to execute this command!. - /// - internal static string CommandNoPermissionUser { - get { - return ResourceManager.GetString("CommandNoPermissionUser", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Couldn't find guild by message!. - /// internal static string CouldntFindGuildByChannel { get { return ResourceManager.GetString("CouldntFindGuildByChannel", resourceCulture); } } - /// - /// Looks up a localized string similar to Current settings:. - /// - internal static string CurrentSettings { - get { - return ResourceManager.GetString("CurrentSettings", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0}, welcome to {1}. - /// - internal static string DefaultWelcomeMessage { - get { - return ResourceManager.GetString("DefaultWelcomeMessage", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I couldn't parse the specified duration! One of the components could be outside it's valid range (e.g. `24h` or `60m`). - /// - internal static string DurationParseFailed { - get { - return ResourceManager.GetString("DurationParseFailed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I cannot mute someone forever using timeouts! Either specify a proper duration, or set a mute role in settings. - /// - internal static string DurationRequiredForTimeOuts { - get { - return ResourceManager.GetString("DurationRequiredForTimeOuts", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Event {0} is cancelled!{1}. - /// - internal static string EventCancelled { - get { - return ResourceManager.GetString("EventCancelled", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Event {0} has completed! Duration: {1}. - /// - internal static string EventCompleted { - get { - return ResourceManager.GetString("EventCompleted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {1}{2} created event {3}! It will take place in {4} and will start <t:{5}:R>!{0}{6}. - /// - internal static string EventCreated { - get { - return ResourceManager.GetString("EventCreated", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0}Event {1} is starting at {2}!. - /// - internal static string EventStarted { - get { - return ResourceManager.GetString("EventStarted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to ever. - /// - internal static string Ever { - get { - return ResourceManager.GetString("Ever", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to *[{0}: {1}]*. - /// - internal static string FeedbackFormat { - get { - return ResourceManager.GetString("FeedbackFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Kicked {0}: {1}. - /// - internal static string FeedbackMemberKicked { - get { - return ResourceManager.GetString("FeedbackMemberKicked", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Muted {0} for{1}: {2}. - /// - internal static string FeedbackMemberMuted { - get { - return ResourceManager.GetString("FeedbackMemberMuted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unmuted {0}: {1}. - /// - internal static string FeedbackMemberUnmuted { - get { - return ResourceManager.GetString("FeedbackMemberUnmuted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Deleted {0} messages in {1}. - /// - internal static string FeedbackMessagesCleared { - get { - return ResourceManager.GetString("FeedbackMessagesCleared", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Value of setting `{0}` is now set to {1}. - /// - internal static string FeedbackSettingsUpdated { - get { - return ResourceManager.GetString("FeedbackSettingsUpdated", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Banned {0} for{1}: {2}. - /// - internal static string FeedbackUserBanned { - get { - return ResourceManager.GetString("FeedbackUserBanned", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unbanned {0}: {1}. - /// - internal static string FeedbackUserUnbanned { - get { - return ResourceManager.GetString("FeedbackUserUnbanned", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Members are in different guilds!. - /// - internal static string InteractionsDifferentGuilds { - get { - return ResourceManager.GetString("InteractionsDifferentGuilds", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I cannot interact with this member!. - /// - internal static string InteractionsFailedBot { - get { - return ResourceManager.GetString("InteractionsFailedBot", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to You cannot interact with this member!. - /// - internal static string InteractionsFailedUser { - get { - return ResourceManager.GetString("InteractionsFailedUser", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to You cannot interact with me!. - /// - internal static string InteractionsMe { - get { - return ResourceManager.GetString("InteractionsMe", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to You cannot interact with guild owner!. - /// - internal static string InteractionsOwner { - get { - return ResourceManager.GetString("InteractionsOwner", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to You cannot interact with yourself!. - /// - internal static string InteractionsYourself { - get { - return ResourceManager.GetString("InteractionsYourself", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to This channel does not exist!. - /// - internal static string InvalidChannel { - get { - return ResourceManager.GetString("InvalidChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to This role does not exist!. - /// - internal static string InvalidRole { - get { - return ResourceManager.GetString("InvalidRole", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid setting value specified!. - /// - internal static string InvalidSettingValue { - get { - return ResourceManager.GetString("InvalidSettingValue", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Language not supported!. - /// - internal static string LanguageNotSupported { - get { - return ResourceManager.GetString("LanguageNotSupported", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Member is already muted!. - /// - internal static string MemberAlreadyMuted { - get { - return ResourceManager.GetString("MemberAlreadyMuted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Member not muted!. - /// - internal static string MemberNotMuted { - get { - return ResourceManager.GetString("MemberNotMuted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} unmuted {1} for {2}. - /// - internal static string MemberUnmuted { - get { - return ResourceManager.GetString("MemberUnmuted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to ms. - /// - internal static string Milliseconds { - get { - return ResourceManager.GetString("Milliseconds", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to No. - /// - internal static string No { - get { - return ResourceManager.GetString("No", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not enough arguments! Needed: {0}, provided: {1}. - /// - internal static string NotEnoughArguments { - get { - return ResourceManager.GetString("NotEnoughArguments", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Punishment expired. - /// - internal static string PunishmentExpired { - get { - return ResourceManager.GetString("PunishmentExpired", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0}I'm ready! (C#). - /// internal static string Ready { get { return ResourceManager.GetString("Ready", resourceCulture); } } - /// - /// Looks up a localized string similar to Not specified. - /// - internal static string RoleNotSpecified { - get { - return ResourceManager.GetString("RoleNotSpecified", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to I couldn't remove role {0} because of an error! {1}. - /// - internal static string RoleRemovalFailed { - get { - return ResourceManager.GetString("RoleRemovalFailed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Someone removed the mute role manually! I added back all roles that I removed during the mute. - /// - internal static string RolesReturned { - get { - return ResourceManager.GetString("RolesReturned", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to That setting doesn't exist!. - /// - internal static string SettingDoesntExist { - get { - return ResourceManager.GetString("SettingDoesntExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not specified. - /// - internal static string SettingNotDefined { - get { - return ResourceManager.GetString("SettingNotDefined", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Admin log channel. - /// - internal static string SettingsAdminLogChannel { - get { - return ResourceManager.GetString("SettingsAdminLogChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Bot log channel. - /// - internal static string SettingsBotLogChannel { - get { - return ResourceManager.GetString("SettingsBotLogChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Channel for event cancellation notifications. - /// - internal static string SettingsEventCancelledChannel { - get { - return ResourceManager.GetString("SettingsEventCancelledChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Channel for event completion notifications. - /// - internal static string SettingsEventCompletedChannel { - get { - return ResourceManager.GetString("SettingsEventCompletedChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Channel for event creation notifications. - /// - internal static string SettingsEventCreatedChannel { - get { - return ResourceManager.GetString("SettingsEventCreatedChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Role for event creation notifications. - /// - internal static string SettingsEventNotifyReceiverRole { - get { - return ResourceManager.GetString("SettingsEventNotifyReceiverRole", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Channel for event start notifications. - /// - internal static string SettingsEventStartedChannel { - get { - return ResourceManager.GetString("SettingsEventStartedChannel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Event start notifications receivers. - /// - internal static string SettingsEventStartedReceivers { - get { - return ResourceManager.GetString("SettingsEventStartedReceivers", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to :(. - /// - internal static string SettingsFrowningFace { - get { - return ResourceManager.GetString("SettingsFrowningFace", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Language. - /// - internal static string SettingsLang { - get { - return ResourceManager.GetString("SettingsLang", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Mute role. - /// - internal static string SettingsMuteRole { - get { - return ResourceManager.GetString("SettingsMuteRole", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Nothing changed! `{0}` is already set to {1}. - /// - internal static string SettingsNothingChanged { - get { - return ResourceManager.GetString("SettingsNothingChanged", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Prefix. - /// - internal static string SettingsPrefix { - get { - return ResourceManager.GetString("SettingsPrefix", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Receive startup messages. - /// - internal static string SettingsReceiveStartupMessages { - get { - return ResourceManager.GetString("SettingsReceiveStartupMessages", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Remove roles on mute. - /// - internal static string SettingsRemoveRolesOnMute { - get { - return ResourceManager.GetString("SettingsRemoveRolesOnMute", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Send welcome messages. - /// - internal static string SettingsSendWelcomeMessages { - get { - return ResourceManager.GetString("SettingsSendWelcomeMessages", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Starter role. - /// - internal static string SettingsStarterRole { - get { - return ResourceManager.GetString("SettingsStarterRole", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Welcome message. - /// - internal static string SettingsWelcomeMessage { - get { - return ResourceManager.GetString("SettingsWelcomeMessage", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Message deleted in {0}, but I forgot what was there. - /// internal static string UncachedMessageDeleted { get { return ResourceManager.GetString("UncachedMessageDeleted", resourceCulture); } } - /// - /// Looks up a localized string similar to Message edited from {0} in channel {1}, but I forgot what was there before the edit: {2}. - /// + internal static string CachedMessageDeleted { + get { + return ResourceManager.GetString("CachedMessageDeleted", resourceCulture); + } + } + + internal static string AutobanReason { + get { + return ResourceManager.GetString("AutobanReason", resourceCulture); + } + } + internal static string UncachedMessageEdited { get { return ResourceManager.GetString("UncachedMessageEdited", resourceCulture); } } - /// - /// Looks up a localized string similar to That user doesn't exist!. - /// - internal static string UserDoesntExist { + internal static string CachedMessageEdited { get { - return ResourceManager.GetString("UserDoesntExist", resourceCulture); + return ResourceManager.GetString("CachedMessageEdited", resourceCulture); } } - /// - /// Looks up a localized string similar to User not banned!. - /// - internal static string UserNotBanned { + internal static string DefaultWelcomeMessage { get { - return ResourceManager.GetString("UserNotBanned", resourceCulture); + return ResourceManager.GetString("DefaultWelcomeMessage", resourceCulture); } } - /// - /// Looks up a localized string similar to The specified user is not a member of this server!. - /// - internal static string UserNotInGuild { + internal static string Beep1 { get { - return ResourceManager.GetString("UserNotInGuild", resourceCulture); + return ResourceManager.GetString("Beep1", resourceCulture); } } - /// - /// Looks up a localized string similar to {0} unbanned {1} for {2}. - /// - internal static string UserUnbanned { + internal static string Beep2 { get { - return ResourceManager.GetString("UserUnbanned", resourceCulture); + return ResourceManager.GetString("Beep2", resourceCulture); } } - /// - /// Looks up a localized string similar to Yes. - /// - internal static string Yes { + internal static string Beep3 { get { - return ResourceManager.GetString("Yes", resourceCulture); + return ResourceManager.GetString("Beep3", resourceCulture); + } + } + + internal static string CommandNoPermissionBot { + get { + return ResourceManager.GetString("CommandNoPermissionBot", resourceCulture); + } + } + + internal static string CommandNoPermissionUser { + get { + return ResourceManager.GetString("CommandNoPermissionUser", resourceCulture); + } + } + + internal static string InteractionsDifferentGuilds { + get { + return ResourceManager.GetString("InteractionsDifferentGuilds", resourceCulture); + } + } + + internal static string InteractionsOwner { + get { + return ResourceManager.GetString("InteractionsOwner", resourceCulture); + } + } + + internal static string InteractionsYourself { + get { + return ResourceManager.GetString("InteractionsYourself", resourceCulture); + } + } + + internal static string InteractionsMe { + get { + return ResourceManager.GetString("InteractionsMe", resourceCulture); + } + } + + internal static string InteractionsFailedUser { + get { + return ResourceManager.GetString("InteractionsFailedUser", resourceCulture); + } + } + + internal static string InteractionsFailedBot { + get { + return ResourceManager.GetString("InteractionsFailedBot", resourceCulture); } } - /// - /// Looks up a localized string similar to You were banned by {0} in guild {1} for {2}. - /// internal static string YouWereBanned { get { return ResourceManager.GetString("YouWereBanned", resourceCulture); } } - /// - /// Looks up a localized string similar to You were kicked by {0} in guild {1} for {2}. - /// + internal static string PunishmentExpired { + get { + return ResourceManager.GetString("PunishmentExpired", resourceCulture); + } + } + + internal static string ClearNegativeAmount { + get { + return ResourceManager.GetString("ClearNegativeAmount", resourceCulture); + } + } + + internal static string ClearAmountTooLarge { + get { + return ResourceManager.GetString("ClearAmountTooLarge", resourceCulture); + } + } + + internal static string CommandHelp { + get { + return ResourceManager.GetString("CommandHelp", resourceCulture); + } + } + internal static string YouWereKicked { get { return ResourceManager.GetString("YouWereKicked", resourceCulture); } } + + internal static string Milliseconds { + get { + return ResourceManager.GetString("Milliseconds", resourceCulture); + } + } + + internal static string MemberAlreadyMuted { + get { + return ResourceManager.GetString("MemberAlreadyMuted", resourceCulture); + } + } + + internal static string ChannelNotSpecified { + get { + return ResourceManager.GetString("ChannelNotSpecified", resourceCulture); + } + } + + internal static string RoleNotSpecified { + get { + return ResourceManager.GetString("RoleNotSpecified", resourceCulture); + } + } + + internal static string CurrentSettings { + get { + return ResourceManager.GetString("CurrentSettings", resourceCulture); + } + } + + internal static string SettingsLang { + get { + return ResourceManager.GetString("SettingsLang", resourceCulture); + } + } + + internal static string SettingsPrefix { + get { + return ResourceManager.GetString("SettingsPrefix", resourceCulture); + } + } + + internal static string SettingsRemoveRolesOnMute { + get { + return ResourceManager.GetString("SettingsRemoveRolesOnMute", resourceCulture); + } + } + + internal static string SettingsSendWelcomeMessages { + get { + return ResourceManager.GetString("SettingsSendWelcomeMessages", resourceCulture); + } + } + + internal static string SettingsStarterRole { + get { + return ResourceManager.GetString("SettingsStarterRole", resourceCulture); + } + } + + internal static string SettingsMuteRole { + get { + return ResourceManager.GetString("SettingsMuteRole", resourceCulture); + } + } + + internal static string SettingsAdminLogChannel { + get { + return ResourceManager.GetString("SettingsAdminLogChannel", resourceCulture); + } + } + + internal static string SettingsBotLogChannel { + get { + return ResourceManager.GetString("SettingsBotLogChannel", resourceCulture); + } + } + + internal static string LanguageNotSupported { + get { + return ResourceManager.GetString("LanguageNotSupported", resourceCulture); + } + } + + internal static string Yes { + get { + return ResourceManager.GetString("Yes", resourceCulture); + } + } + + internal static string No { + get { + return ResourceManager.GetString("No", resourceCulture); + } + } + + internal static string UserNotBanned { + get { + return ResourceManager.GetString("UserNotBanned", resourceCulture); + } + } + + internal static string MemberNotMuted { + get { + return ResourceManager.GetString("MemberNotMuted", resourceCulture); + } + } + + internal static string RolesReturned { + get { + return ResourceManager.GetString("RolesReturned", resourceCulture); + } + } + + internal static string MemberUnmuted { + get { + return ResourceManager.GetString("MemberUnmuted", resourceCulture); + } + } + + internal static string UserUnbanned { + get { + return ResourceManager.GetString("UserUnbanned", resourceCulture); + } + } + + internal static string SettingsWelcomeMessage { + get { + return ResourceManager.GetString("SettingsWelcomeMessage", resourceCulture); + } + } + + internal static string NotEnoughArguments { + get { + return ResourceManager.GetString("NotEnoughArguments", resourceCulture); + } + } + + internal static string ClearInvalidAmountSpecified { + get { + return ResourceManager.GetString("ClearInvalidAmountSpecified", resourceCulture); + } + } + + internal static string FeedbackUserBanned { + get { + return ResourceManager.GetString("FeedbackUserBanned", resourceCulture); + } + } + + internal static string UserNotInGuild { + get { + return ResourceManager.GetString("UserNotInGuild", resourceCulture); + } + } + + internal static string SettingDoesntExist { + get { + return ResourceManager.GetString("SettingDoesntExist", resourceCulture); + } + } + + internal static string SettingsReceiveStartupMessages { + get { + return ResourceManager.GetString("SettingsReceiveStartupMessages", resourceCulture); + } + } + + internal static string InvalidSettingValue { + get { + return ResourceManager.GetString("InvalidSettingValue", resourceCulture); + } + } + + internal static string InvalidRole { + get { + return ResourceManager.GetString("InvalidRole", resourceCulture); + } + } + + internal static string InvalidChannel { + get { + return ResourceManager.GetString("InvalidChannel", resourceCulture); + } + } + + internal static string DurationParseFailed { + get { + return ResourceManager.GetString("DurationParseFailed", resourceCulture); + } + } + + internal static string RoleRemovalFailed { + get { + return ResourceManager.GetString("RoleRemovalFailed", resourceCulture); + } + } + + internal static string DurationRequiredForTimeOuts { + get { + return ResourceManager.GetString("DurationRequiredForTimeOuts", resourceCulture); + } + } + + internal static string CannotTimeOutBot { + get { + return ResourceManager.GetString("CannotTimeOutBot", resourceCulture); + } + } + + internal static string EventCreated { + get { + return ResourceManager.GetString("EventCreated", resourceCulture); + } + } + + internal static string SettingsEventNotifyReceiverRole { + get { + return ResourceManager.GetString("SettingsEventNotifyReceiverRole", resourceCulture); + } + } + + internal static string SettingsEventCreatedChannel { + get { + return ResourceManager.GetString("SettingsEventCreatedChannel", resourceCulture); + } + } + + internal static string SettingsEventStartedChannel { + get { + return ResourceManager.GetString("SettingsEventStartedChannel", resourceCulture); + } + } + + internal static string SettingsEventStartedReceivers { + get { + return ResourceManager.GetString("SettingsEventStartedReceivers", resourceCulture); + } + } + + internal static string EventStarted { + get { + return ResourceManager.GetString("EventStarted", resourceCulture); + } + } + + internal static string SettingsFrowningFace { + get { + return ResourceManager.GetString("SettingsFrowningFace", resourceCulture); + } + } + + internal static string EventCancelled { + get { + return ResourceManager.GetString("EventCancelled", resourceCulture); + } + } + + internal static string SettingsEventCancelledChannel { + get { + return ResourceManager.GetString("SettingsEventCancelledChannel", resourceCulture); + } + } + + internal static string SettingsEventCompletedChannel { + get { + return ResourceManager.GetString("SettingsEventCompletedChannel", resourceCulture); + } + } + + internal static string EventCompleted { + get { + return ResourceManager.GetString("EventCompleted", resourceCulture); + } + } + + internal static string UserDoesntExist { + get { + return ResourceManager.GetString("UserDoesntExist", resourceCulture); + } + } + + internal static string FeedbackFormat { + get { + return ResourceManager.GetString("FeedbackFormat", resourceCulture); + } + } + + internal static string Ever { + get { + return ResourceManager.GetString("Ever", resourceCulture); + } + } + + internal static string FeedbackMessagesCleared { + get { + return ResourceManager.GetString("FeedbackMessagesCleared", resourceCulture); + } + } + + internal static string FeedbackMemberKicked { + get { + return ResourceManager.GetString("FeedbackMemberKicked", resourceCulture); + } + } + + internal static string FeedbackMemberMuted { + get { + return ResourceManager.GetString("FeedbackMemberMuted", resourceCulture); + } + } + + internal static string FeedbackUserUnbanned { + get { + return ResourceManager.GetString("FeedbackUserUnbanned", resourceCulture); + } + } + + internal static string FeedbackMemberUnmuted { + get { + return ResourceManager.GetString("FeedbackMemberUnmuted", resourceCulture); + } + } + + internal static string SettingsNothingChanged { + get { + return ResourceManager.GetString("SettingsNothingChanged", resourceCulture); + } + } + + internal static string SettingNotDefined { + get { + return ResourceManager.GetString("SettingNotDefined", resourceCulture); + } + } + + internal static string FeedbackSettingsUpdated { + get { + return ResourceManager.GetString("FeedbackSettingsUpdated", resourceCulture); + } + } + + internal static string CommandDescriptionBan { + get { + return ResourceManager.GetString("CommandDescriptionBan", resourceCulture); + } + } + + internal static string CommandDescriptionClear { + get { + return ResourceManager.GetString("CommandDescriptionClear", resourceCulture); + } + } + + internal static string CommandDescriptionHelp { + get { + return ResourceManager.GetString("CommandDescriptionHelp", resourceCulture); + } + } + + internal static string CommandDescriptionKick { + get { + return ResourceManager.GetString("CommandDescriptionKick", resourceCulture); + } + } + + internal static string CommandDescriptionMute { + get { + return ResourceManager.GetString("CommandDescriptionMute", resourceCulture); + } + } + + internal static string CommandDescriptionPing { + get { + return ResourceManager.GetString("CommandDescriptionPing", resourceCulture); + } + } + + internal static string CommandDescriptionSettings { + get { + return ResourceManager.GetString("CommandDescriptionSettings", resourceCulture); + } + } + + internal static string CommandDescriptionUnban { + get { + return ResourceManager.GetString("CommandDescriptionUnban", resourceCulture); + } + } + + internal static string CommandDescriptionUnmute { + get { + return ResourceManager.GetString("CommandDescriptionUnmute", resourceCulture); + } + } + + internal static string ReasonRequired { + get { + return ResourceManager.GetString("ReasonRequired", resourceCulture); + } + } } } diff --git a/Boyfriend/Messages.resx b/Boyfriend/Messages.resx index 1f8a6e8..ed21ef5 100644 --- a/Boyfriend/Messages.resx +++ b/Boyfriend/Messages.resx @@ -297,4 +297,7 @@ Unmutes a member + + You must specify a reason! + diff --git a/Boyfriend/Messages.ru.resx b/Boyfriend/Messages.ru.resx index e5eb732..f252015 100644 --- a/Boyfriend/Messages.ru.resx +++ b/Boyfriend/Messages.ru.resx @@ -288,4 +288,7 @@ Разглушает участника + + Требуется указать причину! + diff --git a/Boyfriend/Utils.cs b/Boyfriend/Utils.cs index 32e3bfa..3238cd6 100644 --- a/Boyfriend/Utils.cs +++ b/Boyfriend/Utils.cs @@ -10,7 +10,6 @@ using Humanizer.Localisation; namespace Boyfriend; public static class Utils { - private static readonly string[] Formats = { "%d'd'%h'h'%m'm'%s's'", "%d'd'%h'h'%m'm'", "%d'd'%h'h'%s's'", "%d'd'%h'h'", "%d'd'%m'm'%s's'", "%d'd'%m'm'", "%d'd'%s's'", "%d'd'", "%h'h'%m'm'%s's'", "%h'h'%m'm'", "%h'h'%s's'", "%h'h'", "%m'm'%s's'", "%m'm'", "%s's'", @@ -21,10 +20,12 @@ public static class Utils { public static readonly Random Random = new(); private static readonly Dictionary ReflectionMessageCache = new(); + private static readonly Dictionary CultureInfoCache = new() { - {"ru", new CultureInfo("ru-RU")}, - {"en", new CultureInfo("en-US")} + { "ru", new CultureInfo("ru-RU") }, + { "en", new CultureInfo("en-US") } }; + private static readonly Dictionary MuteRoleCache = new(); private static readonly AllowedMentions AllowRoles = new() { @@ -40,19 +41,12 @@ public static class Utils { .GetTextChannel(ParseMention(Boyfriend.GetGuildConfig(id)["AdminLogChannel"])); } - public static string Wrap(string? original) { - if (original == null) return ""; - var toReturn = original.Replace("```", "ˋˋˋ"); - return $"```{toReturn}{(toReturn.EndsWith("`") || toReturn.Trim().Equals("") ? " " : "")}```"; - } - - public static string? WrapInline(string? original) { - return original == null ? null : $"`{original.Replace("`", "ˋ")}`"; - } - - public static string? WrapAsNeeded(string? original) { + public static string? Wrap(string? original, bool limitedSpace = false) { if (original == null) return null; - return original.Contains('\n') ? Wrap(original) : WrapInline(original); + var maxChars = limitedSpace ? 970 : 1940; + if (original.Length > maxChars) original = original[..maxChars]; + var style = original.Contains('\n') ? "```" : "`"; + return $"{style}{original}{(original.Equals("") ? " " : "")}{style}"; } public static string MentionChannel(ulong id) { @@ -73,9 +67,7 @@ public static class Utils { } public static async Task SendDirectMessage(SocketUser user, string toSend) { - try { - await user.SendMessageAsync(toSend); - } catch (HttpException e) { + try { await user.SendMessageAsync(toSend); } catch (HttpException e) { if (e.DiscordCode != DiscordErrorCode.CannotSendMessageToUser) throw; } @@ -91,14 +83,21 @@ public static class Utils { MuteRoleCache.Add(id, role); break; } + return role; } + public static void RemoveMuteRoleFromCache(ulong id) { + if (MuteRoleCache.ContainsKey(id)) MuteRoleCache.Remove(id); + } + public static async Task SilentSendAsync(SocketTextChannel? channel, string text, bool allowRoles = false) { - if (channel == null || text.Length is 0 or > 2000) return; + if (channel == null || text.Length is 0 or > 2000) + throw new Exception($"Message length is out of range: {text.Length}"); await channel.SendMessageAsync(text, false, null, null, allowRoles ? AllowRoles : AllowedMentions.None); } + public static TimeSpan? GetTimeSpan(ref string from) { if (TimeSpan.TryParseExact(from.ToLowerInvariant(), Formats, CultureInfo.InvariantCulture, out var timeSpan)) return timeSpan; @@ -122,7 +121,7 @@ public static class Utils { var toReturn = typeof(Messages).GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) - ?.ToString()! ?? throw new Exception($"Could not find localized property: {name}"); + ?.ToString()! ?? throw new Exception($"Could not find localized property: {propertyName}"); ReflectionMessageCache.Add(name, toReturn); return toReturn; } @@ -144,11 +143,12 @@ public static class Utils { } public static string GetHumanizedTimeOffset(ref TimeSpan span) { - return span.TotalSeconds > 0 ? $" {span.Humanize(minUnit: TimeUnit.Second, culture: Messages.Culture)}" + return span.TotalSeconds > 0 + ? $" {span.Humanize(minUnit: TimeUnit.Second, culture: Messages.Culture)}" : Messages.Ever; } public static void SetCurrentLanguage(ulong guildId) { Messages.Culture = CultureInfoCache[Boyfriend.GetGuildConfig(guildId)["Lang"]]; } -} +} \ No newline at end of file