Make sure every member has the starter role when ticking guilds

Closes #20

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-01-23 21:06:04 +05:00
parent c1e3abce57
commit 9d5bafbbf5
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
5 changed files with 102 additions and 57 deletions

View file

@ -14,26 +14,69 @@ csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = false csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = none 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_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_elsewhere = true : suggestion
csharp_style_var_for_built_in_types = true:suggestion csharp_style_var_for_built_in_types = true : suggestion
csharp_style_var_when_type_is_apparent = 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_arithmetic_binary_operators = never_if_unnecessary : none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity: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_parentheses_in_relational_binary_operators = never_if_unnecessary : none
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion dotnet_style_predefined_type_for_member_access = true : suggestion
dotnet_style_qualification_for_event = false:suggestion dotnet_style_qualification_for_event = false : suggestion
dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_field = false : suggestion
dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_method = false : suggestion
dotnet_style_qualification_for_property = false:suggestion dotnet_style_qualification_for_property = false : suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion dotnet_style_require_accessibility_modifiers = for_non_interface_members : suggestion
# ReSharper properties # ReSharper properties
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_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_case_statement_on_same_line = true
resharper_place_simple_embedded_block_on_same_line = true resharper_place_simple_embedded_block_on_same_line = true
resharper_place_simple_switch_expression_on_single_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_arrow_with_expressions = true
resharper_wrap_before_eq = true resharper_wrap_before_eq = true
resharper_wrap_before_extends_colon = true resharper_wrap_before_extends_colon = true
resharper_wrap_before_linq_expression = 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

View file

@ -145,13 +145,16 @@ public static class Boyfriend {
mentions.Clear(); mentions.Clear();
} }
_ = ulong.TryParse(config["StarterRole"], out var starterRoleId);
foreach (var mData in data.MemberData.Values) { foreach (var mData in data.MemberData.Values) {
var user = guild.GetUser(mData.Id);
if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id); if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id);
if (!mData.IsInGuild) continue; if (!mData.IsInGuild) continue;
if (!mData.Roles.Contains(starterRoleId)) _ = user.AddRoleAsync(starterRoleId);
if (DateTimeOffset.Now >= mData.MutedUntil) { if (DateTimeOffset.Now >= mData.MutedUntil) {
await Utils.UnmuteMemberAsync( await Utils.UnmuteMemberAsync(
data, Client.CurrentUser.ToString(), guild.GetUser(mData.Id), data, Client.CurrentUser.ToString(), user,
Messages.PunishmentExpired); Messages.PunishmentExpired);
saveData = true; saveData = true;
} }
@ -161,18 +164,16 @@ public static class Boyfriend {
if (DateTimeOffset.Now < reminder.RemindAt) continue; if (DateTimeOffset.Now < reminder.RemindAt) continue;
var channel = guild.GetTextChannel(reminder.ReminderChannel); var channel = guild.GetTextChannel(reminder.ReminderChannel);
if (channel is null) { if (channel is not null)
await Utils.SendDirectMessage(Client.GetUser(mData.Id), reminder.ReminderText);
continue;
}
await channel.SendMessageAsync($"<@{mData.Id}> {Utils.Wrap(reminder.ReminderText)}"); await channel.SendMessageAsync($"<@{mData.Id}> {Utils.Wrap(reminder.ReminderText)}");
mData.Reminders.RemoveAt(i); else
await Utils.SendDirectMessage(user, reminder.ReminderText);
mData.Reminders.RemoveAt(i);
saveData = true; saveData = true;
} }
} }
if (saveData) data.Save(true).Wait(); if (saveData) await data.Save(true);
} }
} }

View file

@ -104,7 +104,8 @@ public record GuildData {
set => _cachedMuteRole = value; set => _cachedMuteRole = value;
} }
public SocketTextChannel? PublicFeedbackChannel => Boyfriend.Client.GetGuild(_id) public SocketTextChannel? PublicFeedbackChannel
=> Boyfriend.Client.GetGuild(_id)
.GetTextChannel( .GetTextChannel(
ulong.Parse(Preferences["PublicFeedbackChannel"])); ulong.Parse(Preferences["PublicFeedbackChannel"]));

View file

@ -17,14 +17,14 @@ public static class EventHandler {
Client.MessageUpdated += MessageUpdatedEvent; Client.MessageUpdated += MessageUpdatedEvent;
Client.UserJoined += UserJoinedEvent; Client.UserJoined += UserJoinedEvent;
Client.UserLeft += UserLeftEvent; Client.UserLeft += UserLeftEvent;
Client.GuildMemberUpdated += RolesUpdatedEvent; Client.GuildMemberUpdated += MemberRolesUpdatedEvent;
Client.GuildScheduledEventCreated += ScheduledEventCreatedEvent; Client.GuildScheduledEventCreated += ScheduledEventCreatedEvent;
Client.GuildScheduledEventCancelled += ScheduledEventCancelledEvent; Client.GuildScheduledEventCancelled += ScheduledEventCancelledEvent;
Client.GuildScheduledEventStarted += ScheduledEventStartedEvent; Client.GuildScheduledEventStarted += ScheduledEventStartedEvent;
Client.GuildScheduledEventCompleted += ScheduledEventCompletedEvent; Client.GuildScheduledEventCompleted += ScheduledEventCompletedEvent;
} }
private static Task RolesUpdatedEvent(Cacheable<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) { private static Task MemberRolesUpdatedEvent(Cacheable<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) {
var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id]; var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id];
data.Roles = ((IGuildUser)newUser).RoleIds.ToList(); data.Roles = ((IGuildUser)newUser).RoleIds.ToList();
data.Roles.Remove(newUser.Guild.Id); data.Roles.Remove(newUser.Guild.Id);