diff --git a/Boyfriend/Boyfriend.cs b/Boyfriend/Boyfriend.cs index a1130b4..2e36a76 100644 --- a/Boyfriend/Boyfriend.cs +++ b/Boyfriend/Boyfriend.cs @@ -11,7 +11,7 @@ public static class Boyfriend { private static readonly DiscordSocketConfig Config = new() { MessageCacheSize = 250, - GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers, + GatewayIntents = (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) & ~GatewayIntents.GuildInvites, AlwaysDownloadUsers = true, AlwaysResolveStickers = false, AlwaysDownloadDefaultStickers = false, @@ -103,11 +103,11 @@ public static class Boyfriend { } public static async Task WriteGuildConfigAsync(ulong id) { - var json = JsonConvert.SerializeObject(GuildConfigDictionary[id], Formatting.Indented); - var removedRoles = JsonConvert.SerializeObject(RemovedRolesDictionary[id], Formatting.Indented); + await File.WriteAllTextAsync($"config_{id}.json", JsonConvert.SerializeObject(GuildConfigDictionary[id], Formatting.Indented)); - await File.WriteAllTextAsync($"config_{id}.json", json); - await File.WriteAllTextAsync($"removedroles_{id}.json", removedRoles); + if (RemovedRolesDictionary.TryGetValue(id, out var removedRoles)) + await File.WriteAllTextAsync($"removedroles_{id}.json", + JsonConvert.SerializeObject(removedRoles, Formatting.Indented)); } public static Dictionary GetGuildConfig(ulong id) { diff --git a/Boyfriend/CommandProcessor.cs b/Boyfriend/CommandProcessor.cs index da21d00..f34242d 100644 --- a/Boyfriend/CommandProcessor.cs +++ b/Boyfriend/CommandProcessor.cs @@ -41,7 +41,7 @@ public sealed class CommandProcessor { Utils.SetCurrentLanguage(guild.Id); if (GetMember().Roles.Contains(muteRole)) { - await Context.Message.ReplyAsync(Messages.UserCannotUnmuteThemselves); + _ = Context.Message.ReplyAsync(Messages.UserCannotUnmuteThemselves); return; } @@ -51,11 +51,6 @@ public sealed class CommandProcessor { RunCommandOnLine(list[i], cleanList[i], config["Prefix"]); if (_stackedReplyMessage.Length > 0) _ = Context.Channel.TriggerTypingAsync(); - var member = Boyfriend.Client.GetGuild(Context.Guild.Id) - .GetUser(Context.User.Id); // Getting an up-to-date copy - if (member is null || member.Roles.Contains(muteRole) - || member.TimedOutUntil.GetValueOrDefault(DateTimeOffset.UnixEpoch).ToUnixTimeSeconds() > - DateTimeOffset.Now.ToUnixTimeSeconds()) break; } await Task.WhenAll(_tasks); @@ -67,8 +62,8 @@ public sealed class CommandProcessor { } private void RunCommandOnLine(string line, string cleanLine, string prefix) { - var prefixed = line[..prefix.Length] == prefix; - if (!prefixed && line[..Mention.Length] is not Mention) return; + var prefixed = line.StartsWith(prefix); + if (!prefixed && !line.StartsWith(Mention)) return; foreach (var command in Commands) { var lineNoMention = line.Remove(0, prefixed ? prefix.Length : Mention.Length); if (!command.Aliases.Contains(lineNoMention.Trim().Split()[0])) continue; @@ -141,18 +136,15 @@ public sealed class CommandProcessor { } if (Context.Guild.GetUser(Context.User.Id).GuildPermissions.Has(permission) - || Context.Guild.Owner.Id == Context.User.Id) return true; + || Context.Guild.OwnerId == Context.User.Id) return true; Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{NoAccess}{Utils.GetMessage($"UserCannot{permission}")}", Context.Message); return false; } - public SocketGuildUser? GetMember(SocketUser user, string? argument) { - var member = Context.Guild.GetUser(user.Id); - if (member is null && argument is not null) - Utils.SafeAppendToBuilder(_stackedReplyMessage, $":x: {Messages.UserNotInGuild}", Context.Message); - return member; + public SocketGuildUser? GetMember(SocketUser user) { + return Context.Guild.GetUser(user.Id); } public SocketGuildUser? GetMember(string[] args, string[] cleanArgs, int index, string? argument) { diff --git a/Boyfriend/Commands/BanCommand.cs b/Boyfriend/Commands/BanCommand.cs index b4d8e1b..78cae2c 100644 --- a/Boyfriend/Commands/BanCommand.cs +++ b/Boyfriend/Commands/BanCommand.cs @@ -10,7 +10,7 @@ public sealed class BanCommand : ICommand { var toBan = cmd.GetUser(args, cleanArgs, 0, "ToBan"); if (toBan is null || !cmd.HasPermission(GuildPermission.BanMembers)) return; - var memberToBan = cmd.GetMember(toBan, null); + var memberToBan = cmd.GetMember(toBan); if (memberToBan is not null && !cmd.CanInteractWith(memberToBan, "Ban")) return; var duration = CommandProcessor.GetTimeSpan(args, 1); diff --git a/Boyfriend/Commands/SettingsCommand.cs b/Boyfriend/Commands/SettingsCommand.cs index baccdc2..46cec36 100644 --- a/Boyfriend/Commands/SettingsCommand.cs +++ b/Boyfriend/Commands/SettingsCommand.cs @@ -16,7 +16,7 @@ public sealed class SettingsCommand : ICommand { foreach (var setting in Boyfriend.DefaultConfig) { var format = "{0}"; - var currentValue = config[setting.Key]; + var currentValue = config[setting.Key] is "default" ? Messages.DefaultWelcomeMessage : config[setting.Key]; if (setting.Key.EndsWith("Channel")) { if (guild.GetTextChannel(ulong.Parse(currentValue)) is not null) format = "<#{0}>"; diff --git a/Boyfriend/Messages.Designer.cs b/Boyfriend/Messages.Designer.cs index 1264e3f..f11dd7b 100644 --- a/Boyfriend/Messages.Designer.cs +++ b/Boyfriend/Messages.Designer.cs @@ -716,15 +716,6 @@ namespace Boyfriend { } } - /// - /// 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. /// @@ -734,33 +725,6 @@ namespace Boyfriend { } } - /// - /// 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 Early event start notification offset. /// @@ -771,20 +735,20 @@ namespace Boyfriend { } /// - /// Looks up a localized string similar to Role for event creation notifications. + /// Looks up a localized string similar to Channel for event notifications. /// - internal static string SettingsEventNotifyReceiverRole { + internal static string SettingsEventNotificationChannel { get { - return ResourceManager.GetString("SettingsEventNotifyReceiverRole", resourceCulture); + return ResourceManager.GetString("SettingsEventNotificationChannel", resourceCulture); } } /// - /// Looks up a localized string similar to Channel for event start notifications. + /// Looks up a localized string similar to Role for event creation notifications. /// - internal static string SettingsEventStartedChannel { + internal static string SettingsEventNotificationRole { get { - return ResourceManager.GetString("SettingsEventStartedChannel", resourceCulture); + return ResourceManager.GetString("SettingsEventNotificationRole", resourceCulture); } } diff --git a/Boyfriend/Messages.resx b/Boyfriend/Messages.resx index 5b41851..e98e804 100644 --- a/Boyfriend/Messages.resx +++ b/Boyfriend/Messages.resx @@ -102,9 +102,6 @@ Mute role - - Admin log channel - Bot log channel @@ -165,14 +162,11 @@ {0} has created event {1}! It will take place in {2} and will start <t:{3}:R>!\n{4} - + Role for event creation notifications - - Channel for event creation notifications - - - Channel for event start notifications + + Channel for event notifications Event start notifications receivers @@ -186,12 +180,6 @@ Event {0} is cancelled!{1} - - Channel for event cancellation notifications - - - Channel for event completion notifications - Event {0} has completed! Duration: {1} diff --git a/Boyfriend/Messages.ru.resx b/Boyfriend/Messages.ru.resx index f009e22..e55cabe 100644 --- a/Boyfriend/Messages.ru.resx +++ b/Boyfriend/Messages.ru.resx @@ -90,9 +90,6 @@ Роль мута - - Канал админ-уведомлений - Канал бот-уведомлений @@ -156,14 +153,11 @@ {0} создал событие {1}! Оно пройдёт в {2} и начнётся <t:{3}:R>!\n{4} - + Роль для уведомлений о создании событий - - Канал для уведомлений о создании событий - - - Канал для уведомлений о начале событий + + Канал для уведомлений о событиях Получатели уведомлений о начале событий @@ -177,12 +171,6 @@ Событие {0} отменено!{1} - - Канал для уведомлений о отмене событий - - - Канал для уведомлений о завершении событий - Событие {0} завершено! Продолжительность: {1} diff --git a/Boyfriend/Messages.tt-ru.resx b/Boyfriend/Messages.tt-ru.resx index 2b8c8ae..ba3f2a2 100644 --- a/Boyfriend/Messages.tt-ru.resx +++ b/Boyfriend/Messages.tt-ru.resx @@ -90,9 +90,6 @@ роль замученного - - канал админ-уведомлений - канал бот-уведомлений @@ -156,14 +153,11 @@ {0} приготовил новый квест {1}! он пройдёт в {2} и начнётся <t:{3}:R>!\n{4} - + роль для уведомлений о создании квеста - - канал для уведомлений о создании квеста - - - канал для уведомлений о начале квеста + + канал для уведомлений о квестах получатели уведомлений о начале квеста @@ -177,12 +171,6 @@ квест {0} отменен!{1} - - канал для уведомлений о отмене событий - - - канал для уведомлений о завершении квеста - квест {0} завершен! все это длилось {1}