private async Task UpdateRelevantAutorolesForUserAsync ( AutoroleService autoroles, AutoroleUpdateService autoroleUpdates, IAsyncEnumerable <AutoroleConfiguration> relevantAutoroles, IGuildUser guildUser ) { await foreach (var relevantAutorole in relevantAutoroles) { var updateResult = await autoroleUpdates.UpdateAutoroleForUserAsync(relevantAutorole, guildUser); if (!updateResult.IsSuccess) { this.Log.LogError(updateResult.Exception, updateResult.ErrorReason); continue; } switch (updateResult.Status) { case AutoroleUpdateStatus.RequiresAffirmation: { await NotifyUserNeedsAffirmation(autoroles, relevantAutorole, guildUser); break; } } } }
private async IAsyncEnumerable <AutoroleConfiguration> GetRelevantReactionAutoroles ( AutoroleService autoroles, Cacheable <IUserMessage, ulong> message, SocketReaction?reaction = null ) { var realMessage = await message.GetOrDownloadAsync(); if (!(realMessage.Channel is ITextChannel textChannel)) { yield break; } var guildAutoroles = await autoroles.GetAutoroles(textChannel.Guild).ToListAsync(); if (guildAutoroles.Count == 0) { yield break; } foreach (var autorole in guildAutoroles) { var isRelevant = autorole.Conditions.Any ( c => { if (!(c is ReactionCondition reactionCondition)) { return(false); } if (reactionCondition.MessageID != (long)realMessage.Id) { return(false); } if (reaction is null) { return(true); } if (reactionCondition.EmoteName != reaction.Emote.Name) { return(false); } return(true); } ); if (isRelevant) { yield return(autorole); } } }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleUpdateService"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="guildAPI">The guild API.</param> public AutoroleUpdateService ( AutoroleService autoroles, IDiscordRestGuildAPI guildAPI ) { _autoroles = autoroles; _guildAPI = guildAPI; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> /// <param name="interactivity">The interactivity service.</param> public AutoroleCommands ( AutoroleService autoroles, UserFeedbackService feedback, InteractivityService interactivity ) { _autoroles = autoroles; _feedback = feedback; _interactivity = interactivity; }
/// <summary> /// Initializes a new instance of the <see cref="MessageCountConditionResponder"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="statistics">The statistics service.</param> /// <param name="autoroleUpdates">The autorole update service.</param> public MessageCountConditionResponder ( AutoroleService autoroles, UserStatisticsService statistics, AutoroleUpdateService autoroleUpdates ) { _autoroles = autoroles; _statistics = statistics; _autoroleUpdates = autoroleUpdates; }
/// <summary> /// Initializes a new instance of the <see cref="UserActivityResponder"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="autoroleUpdates">The autorole update service.</param> /// <param name="statistics">The statistics service.</param> public UserActivityResponder ( AutoroleService autoroles, AutoroleUpdateService autoroleUpdates, UserStatisticsService statistics ) { _autoroles = autoroles; _autoroleUpdates = autoroleUpdates; _statistics = statistics; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleSettingCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> /// <param name="context">The command context.</param> public AutoroleSettingCommands ( AutoroleService autoroles, FeedbackService feedback, ICommandContext context ) { _autoroles = autoroles; _feedback = feedback; _context = context; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="context">The command context.</param> /// <param name="feedback">The feedback service.</param> public AutoroleConditionCommands ( AutoroleService autoroles, ICommandContext context, FeedbackService feedback ) { _autoroles = autoroles; _context = context; _feedback = feedback; }
/// <summary> /// Initializes a new instance of the <see cref="ReactionConditionResponder"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="autoroleUpdates">The autorole update service.</param> /// <param name="guildAPI">The guild API.</param> public ReactionConditionResponder ( AutoroleService autoroles, AutoroleUpdateService autoroleUpdates, IDiscordRestGuildAPI guildAPI ) { _autoroles = autoroles; _autoroleUpdates = autoroleUpdates; _guildAPI = guildAPI; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> /// <param name="context">The command context.</param> /// <param name="guildAPI">The guild API.</param> public AutoroleCommands ( AutoroleService autoroles, FeedbackService feedback, ICommandContext context, IDiscordRestGuildAPI guildAPI ) { _autoroles = autoroles; _feedback = feedback; _context = context; _guildAPI = guildAPI; }
private async Task NotifyUserNeedsAffirmation ( AutoroleService autoroles, AutoroleConfiguration autorole, IGuildUser user ) { var getAutoroleConfirmation = await autoroles.GetOrCreateAutoroleConfirmationAsync(autorole, user); if (!getAutoroleConfirmation.IsSuccess) { this.Log.LogError(getAutoroleConfirmation.Exception, getAutoroleConfirmation.ErrorReason); return; } var autoroleConfirmation = getAutoroleConfirmation.Entity; if (autoroleConfirmation.HasNotificationBeenSent) { return; } var getSettings = await autoroles.GetOrCreateServerSettingsAsync(user.Guild); if (!getSettings.IsSuccess) { this.Log.LogError(getSettings.Exception, getSettings.ErrorReason); return; } var settings = getSettings.Entity; var notificationChannelID = settings.AffirmationRequiredNotificationChannelID; if (notificationChannelID is null) { return; } var notificationChannel = await user.Guild.GetTextChannelAsync((ulong)notificationChannelID.Value); if (notificationChannel is null) { return; } var embed = _feedback.CreateEmbedBase() .WithTitle("Confirmation Required") .WithDescription ( $"{MentionUtils.MentionUser(user.Id)} has met the requirements for the " + $"{MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} role.\n" + $"\n" + $"Use \"!at affirm {MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} " + $"{MentionUtils.MentionUser(user.Id)}\" to affirm and give the user the role." ) .WithColor(Color.Green); try { await _feedback.SendEmbedAsync(notificationChannel, embed.Build()); autoroleConfirmation.HasNotificationBeenSent = true; await autoroles.SaveChangesAsync(); } catch (HttpException hex) when(hex.WasCausedByMissingPermission()) { } }
/// <summary> /// Initializes a new instance of the <see cref="TimeSinceJoinConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public TimeSinceJoinConditionCommands(AutoroleService autoroles) { _autoroles = autoroles; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> public AutoroleConditionCommands(AutoroleService autoroles, UserFeedbackService feedback) { _autoroles = autoroles; _feedback = feedback; }
/// <summary> /// Initializes a new instance of the <see cref="MessageCountInChannelConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> public MessageCountInChannelConditionCommands(AutoroleService autoroles, UserFeedbackService feedback) { _autoroles = autoroles; _feedback = feedback; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public AutoroleConditionCommands(AutoroleService autoroles) { _autoroles = autoroles; }
/// <summary> /// Initializes a new instance of the <see cref="MessageCountInGuildConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public MessageCountInGuildConditionCommands(AutoroleService autoroles) { _autoroles = autoroles; }
private async Task <OperationResult> NotifyUserNeedsAffirmation ( AutoroleService autoroles, SocketGuild guild, AutoroleConfiguration autorole, IUser user ) { var getAutoroleConfirmation = await autoroles.GetOrCreateAutoroleConfirmationAsync(autorole, user); if (!getAutoroleConfirmation.IsSuccess) { return(OperationResult.FromError(getAutoroleConfirmation)); } var autoroleConfirmation = getAutoroleConfirmation.Entity; if (autoroleConfirmation.HasNotificationBeenSent) { return(OperationResult.FromSuccess()); } var getSettings = await autoroles.GetOrCreateServerSettingsAsync(guild); if (!getSettings.IsSuccess) { return(OperationResult.FromError(getSettings)); } var settings = getSettings.Entity; var notificationChannelID = settings.AffirmationRequiredNotificationChannelID; if (notificationChannelID is null) { return(OperationResult.FromError("There's no notification channel set.")); } var notificationChannel = guild.GetTextChannel((ulong)notificationChannelID.Value); if (notificationChannel is null) { return(OperationResult.FromError("The notification channel is set, but does not exist.")); } var embed = _feedback.CreateEmbedBase() .WithTitle("Confirmation Required") .WithDescription ( $"{MentionUtils.MentionUser(user.Id)} has met the requirements for the " + $"{MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} role.\n" + $"\n" + $"Use \"!at affirm {MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} " + $"{MentionUtils.MentionUser(user.Id)}\" to affirm and give the user the role." ) .WithColor(Color.Green); try { await _feedback.SendEmbedAsync(notificationChannel, embed.Build()); var setResult = await autoroles.SetHasNotificationBeenSentAsync(autoroleConfirmation, true); if (!setResult.IsSuccess) { return(OperationResult.FromError(setResult)); } } catch (HttpException hex) when(hex.WasCausedByMissingPermission()) { return(OperationResult.FromError(hex)); } return(OperationResult.FromSuccess()); }
/// <summary> /// Initializes a new instance of the <see cref="TimeSinceLastActivityConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> public TimeSinceLastActivityConditionCommands(AutoroleService autoroles, UserFeedbackService feedback) { _autoroles = autoroles; _feedback = feedback; }
/// <summary> /// Initializes a new instance of the <see cref="MessageCountInChannelConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public MessageCountInChannelConditionCommands(AutoroleService autoroles) { _autoroles = autoroles; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleConfigurationParser"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public AutoroleConfigurationParser(AutoroleService autoroles) { _autoroles = autoroles; }
/// <summary> /// Initializes a new instance of the <see cref="AutoroleSettingSetCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="feedback">The feedback service.</param> public AutoroleSettingSetCommands(AutoroleService autoroles, UserFeedbackService feedback) { _autoroles = autoroles; _feedback = feedback; }
/// <summary> /// Initializes a new instance of the <see cref="RoleConditionResponder"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> /// <param name="autoroleUpdates">The autorole update service.</param> public RoleConditionResponder(AutoroleService autoroles, AutoroleUpdateService autoroleUpdates) { _autoroles = autoroles; _autoroleUpdates = autoroleUpdates; }
/// <summary> /// Initializes a new instance of the <see cref="TimeSinceLastActivityConditionCommands"/> class. /// </summary> /// <param name="autoroles">The autorole service.</param> public TimeSinceLastActivityConditionCommands(AutoroleService autoroles) { _autoroles = autoroles; }