diff --git a/.editorconfig b/.editorconfig index a647b0a..bb647a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,39 +1,82 @@ [*] -charset = utf-8 -end_of_line = lf -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space -indent_size = 4 -tab_width = 4 +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 +tab_width = 4 # Microsoft .NET properties -csharp_new_line_before_catch = false -csharp_new_line_before_else = false -csharp_new_line_before_finally = false -csharp_new_line_before_members_in_object_initializers = false -csharp_new_line_before_open_brace = none -csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async -csharp_style_var_elsewhere = true:suggestion -csharp_style_var_for_built_in_types = true:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion -dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none -dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion -dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_property = false:suggestion -dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion +csharp_new_line_before_catch = false +csharp_new_line_before_else = false +csharp_new_line_before_finally = false +csharp_new_line_before_members_in_object_initializers = false +csharp_new_line_before_open_brace = none +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async +csharp_style_var_elsewhere = true : suggestion +csharp_style_var_for_built_in_types = true : suggestion +csharp_style_var_when_type_is_apparent = true : suggestion +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary : none +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary : none +dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion +dotnet_style_predefined_type_for_member_access = true : suggestion +dotnet_style_qualification_for_event = false : suggestion +dotnet_style_qualification_for_field = false : suggestion +dotnet_style_qualification_for_method = false : suggestion +dotnet_style_qualification_for_property = false : suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members : suggestion # ReSharper properties -resharper_csharp_wrap_before_first_type_parameter_constraint = true -resharper_place_simple_case_statement_on_same_line = true -resharper_place_simple_embedded_block_on_same_line = true -resharper_place_simple_switch_expression_on_single_line = true -resharper_wrap_before_arrow_with_expressions = true -resharper_wrap_before_eq = true -resharper_wrap_before_extends_colon = true -resharper_wrap_before_linq_expression = true +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_parameter = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_tuple_components = true +resharper_allow_comment_after_lbrace = true +resharper_csharp_empty_block_style = together_same_line +resharper_csharp_indent_type_constraints = false +resharper_csharp_int_align_comments = true +resharper_csharp_outdent_commas = true +resharper_csharp_stick_comment = false +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_after_invocation_lpar = true +resharper_csharp_wrap_before_binary_opsign = true +resharper_csharp_wrap_before_first_type_parameter_constraint = true +resharper_csharp_wrap_multiple_declaration_style = wrap_if_long +resharper_csharp_wrap_multiple_type_parameter_constraints_style = chop_always +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_indent_preprocessor_if = usual_indent +resharper_indent_preprocessor_other = usual_indent +resharper_int_align_fields = true +resharper_int_align_methods = true +resharper_int_align_parameters = true +resharper_int_align_properties = true +resharper_int_align_switch_expressions = true +resharper_int_align_switch_sections = true +resharper_keep_existing_switch_expression_arrangement = false +resharper_outdent_statement_labels = true +resharper_place_field_attribute_on_same_line = if_owner_is_single_line +resharper_place_simple_accessorholder_on_single_line = true +resharper_place_simple_accessor_on_single_line = false +resharper_place_simple_case_statement_on_same_line = true +resharper_place_simple_embedded_block_on_same_line = true +resharper_place_simple_switch_expression_on_single_line = true +resharper_space_around_arrow_op = true +resharper_wrap_before_arrow_with_expressions = true +resharper_wrap_before_eq = true +resharper_wrap_before_extends_colon = true +resharper_wrap_before_linq_expression = true +resharper_wrap_chained_binary_expressions = chop_if_long +resharper_wrap_for_stmt_header_style = wrap_if_long +resharper_wrap_switch_expression = chop_if_long diff --git a/Boyfriend.cs b/Boyfriend.cs index c5c8a73..ffb3fbc 100644 --- a/Boyfriend.cs +++ b/Boyfriend.cs @@ -121,7 +121,7 @@ public static class Boyfriend { if (schEvent.Status is GuildScheduledEventStatus.Scheduled && config["AutoStartEvents"] is "true" && DateTimeOffset - .Now + .Now >= schEvent.StartTime) await schEvent.StartAsync(); else if (!data.EarlyNotifications.Contains(schEvent.Id) && DateTimeOffset.Now >= schEvent.StartTime.Subtract(new TimeSpan(0, offset, 0))) { @@ -133,8 +133,8 @@ public static class Boyfriend { if (receivers.Contains("role") && role is not null) mentions.Append($"{role.Mention} "); if (receivers.Contains("users") || receivers.Contains("interested")) mentions = (await schEvent.GetUsersAsync(15)) - .Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id)) - .Aggregate(mentions, (current, user) => current.Append($"{user.Mention} ")); + .Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id)) + .Aggregate(mentions, (current, user) => current.Append($"{user.Mention} ")); await Utils.GetEventNotificationChannel(guild)?.SendMessageAsync( string.Format( @@ -145,13 +145,16 @@ public static class Boyfriend { mentions.Clear(); } + _ = ulong.TryParse(config["StarterRole"], out var starterRoleId); foreach (var mData in data.MemberData.Values) { + var user = guild.GetUser(mData.Id); if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id); if (!mData.IsInGuild) continue; + if (!mData.Roles.Contains(starterRoleId)) _ = user.AddRoleAsync(starterRoleId); if (DateTimeOffset.Now >= mData.MutedUntil) { await Utils.UnmuteMemberAsync( - data, Client.CurrentUser.ToString(), guild.GetUser(mData.Id), + data, Client.CurrentUser.ToString(), user, Messages.PunishmentExpired); saveData = true; } @@ -161,18 +164,16 @@ public static class Boyfriend { if (DateTimeOffset.Now < reminder.RemindAt) continue; var channel = guild.GetTextChannel(reminder.ReminderChannel); - if (channel is null) { - await Utils.SendDirectMessage(Client.GetUser(mData.Id), reminder.ReminderText); - continue; - } + if (channel is not null) + await channel.SendMessageAsync($"<@{mData.Id}> {Utils.Wrap(reminder.ReminderText)}"); + else + await Utils.SendDirectMessage(user, reminder.ReminderText); - await channel.SendMessageAsync($"<@{mData.Id}> {Utils.Wrap(reminder.ReminderText)}"); mData.Reminders.RemoveAt(i); - saveData = true; } } - if (saveData) data.Save(true).Wait(); + if (saveData) await data.Save(true); } } diff --git a/Commands/SettingsCommand.cs b/Commands/SettingsCommand.cs index e056cdc..b987394 100644 --- a/Commands/SettingsCommand.cs +++ b/Commands/SettingsCommand.cs @@ -34,7 +34,7 @@ public sealed class SettingsCommand : ICommand { } currentSettings.Append($"{Utils.GetMessage($"Settings{setting.Key}")} (`{setting.Key}`): ") - .AppendFormat(format, currentValue).AppendLine(); + .AppendFormat(format, currentValue).AppendLine(); } cmd.Reply(currentSettings.ToString(), ReplyEmojis.SettingsList); diff --git a/Data/GuildData.cs b/Data/GuildData.cs index 53d7114..41947d6 100644 --- a/Data/GuildData.cs +++ b/Data/GuildData.cs @@ -99,19 +99,20 @@ public record GuildData { get { if (Preferences["MuteRole"] is "0") return null; return _cachedMuteRole ??= Boyfriend.Client.GetGuild(_id).Roles - .Single(x => x.Id == ulong.Parse(Preferences["MuteRole"])); + .Single(x => x.Id == ulong.Parse(Preferences["MuteRole"])); } set => _cachedMuteRole = value; } - public SocketTextChannel? PublicFeedbackChannel => Boyfriend.Client.GetGuild(_id) - .GetTextChannel( - ulong.Parse(Preferences["PublicFeedbackChannel"])); + public SocketTextChannel? PublicFeedbackChannel + => Boyfriend.Client.GetGuild(_id) + .GetTextChannel( + ulong.Parse(Preferences["PublicFeedbackChannel"])); public SocketTextChannel? PrivateFeedbackChannel => Boyfriend.Client.GetGuild(_id) - .GetTextChannel( - ulong.Parse( - Preferences["PrivateFeedbackChannel"])); + .GetTextChannel( + ulong.Parse( + Preferences["PrivateFeedbackChannel"])); public static GuildData Get(SocketGuild guild) { if (GuildDataDictionary.TryGetValue(guild.Id, out var stored)) return stored; diff --git a/EventHandler.cs b/EventHandler.cs index 0fb41d8..e91f228 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -17,14 +17,14 @@ public static class EventHandler { Client.MessageUpdated += MessageUpdatedEvent; Client.UserJoined += UserJoinedEvent; Client.UserLeft += UserLeftEvent; - Client.GuildMemberUpdated += RolesUpdatedEvent; + Client.GuildMemberUpdated += MemberRolesUpdatedEvent; Client.GuildScheduledEventCreated += ScheduledEventCreatedEvent; Client.GuildScheduledEventCancelled += ScheduledEventCancelledEvent; Client.GuildScheduledEventStarted += ScheduledEventStartedEvent; Client.GuildScheduledEventCompleted += ScheduledEventCompletedEvent; } - private static Task RolesUpdatedEvent(Cacheable oldUser, SocketGuildUser newUser) { + private static Task MemberRolesUpdatedEvent(Cacheable oldUser, SocketGuildUser newUser) { var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id]; data.Roles = ((IGuildUser)newUser).RoleIds.ToList(); data.Roles.Remove(newUser.Guild.Id); @@ -207,8 +207,8 @@ public static class EventHandler { if (receivers.Contains("role") && role is not null) mentions.Append($"{role.Mention} "); if (receivers.Contains("users") || receivers.Contains("interested")) mentions = (await scheduledEvent.GetUsersAsync(15)) - .Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id)) - .Aggregate(mentions, (current, user) => current.Append($"{user.Mention} ")); + .Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id)) + .Aggregate(mentions, (current, user) => current.Append($"{user.Mention} ")); await channel.SendMessageAsync( string.Format(