1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

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

@ -29,11 +29,54 @@ dotnet_style_qualification_for_property = false:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members : suggestion
# 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_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

View file

@ -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)}");
mData.Reminders.RemoveAt(i);
else
await Utils.SendDirectMessage(user, reminder.ReminderText);
mData.Reminders.RemoveAt(i);
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;
}
public SocketTextChannel? PublicFeedbackChannel => Boyfriend.Client.GetGuild(_id)
public SocketTextChannel? PublicFeedbackChannel
=> Boyfriend.Client.GetGuild(_id)
.GetTextChannel(
ulong.Parse(Preferences["PublicFeedbackChannel"]));

View file

@ -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<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) {
private static Task MemberRolesUpdatedEvent(Cacheable<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) {
var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id];
data.Roles = ((IGuildUser)newUser).RoleIds.ToList();
data.Roles.Remove(newUser.Guild.Id);