public async Task <RuntimeResult> ListGrantedPermissionsAsync(IUser discordUser) { var userPermissions = await _permissions.GetApplicableUserPermissionsAsync(this.Context.Guild, discordUser); var permissions = _permissionRegistry.RegisteredPermissions .Where(r => userPermissions.Any(u => u.Permission == r.UniqueIdentifier)) .ToDictionary(p => p.UniqueIdentifier); var permissionInfos = new List <(string Title, string Description)>(); foreach (var permissionGroup in userPermissions.GroupBy(p => p.Permission)) { var permission = permissions[permissionGroup.Key]; var titleBuilder = new StringBuilder(); titleBuilder.Append(permission.FriendlyName); titleBuilder.Append(" ("); var grants = permissionGroup.Select ( up => $"{(up.IsGranted ? ":white_check_mark:" : ":no_entry_sign: ")} {up.Target.Humanize()}" ); titleBuilder.Append(grants.Humanize(",").Transform(To.SentenceCase)); titleBuilder.Append(")"); permissionInfos.Add((titleBuilder.ToString(), permission.Description)); } var appearance = PaginatedAppearanceOptions.Default; appearance.Author = discordUser; appearance.HelpText = "These are the permissions granted to the given user. Scroll through the pages by using the reactions."; var paginatedEmbed = PaginatedEmbedFactory.SimpleFieldsFromCollection ( _feedback, _interactivity, this.Context.User, permissionInfos, p => p.Title, p => p.Description, "No permissions set.", appearance ); await _interactivity.SendPrivateInteractiveMessageAndDeleteAsync ( this.Context, _feedback, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> IncludePreviousMessagesAsync ( [RequireEntityOwnerOrPermission(typeof(EditRoleplay), PermissionTarget.Other)] Roleplay roleplay, [OverrideTypeReader(typeof(UncachedMessageTypeReader <IMessage>))] IMessage startMessage, [OverrideTypeReader(typeof(UncachedMessageTypeReader <IMessage>))] IMessage?finalMessage = null ) { finalMessage ??= this.Context.Message; if (startMessage.Channel != finalMessage.Channel) { return(RuntimeCommandResult.FromError("The messages are not in the same channel.")); } var addedOrUpdatedMessageCount = 0; var latestMessage = startMessage; while (latestMessage.Timestamp < finalMessage.Timestamp) { var messages = (await this.Context.Channel.GetMessagesAsync ( latestMessage, Direction.After ).FlattenAsync()).OrderBy(m => m.Timestamp).ToList(); latestMessage = messages.Last(); foreach (var message in messages) { // Jump out if we've passed the final message if (message.Timestamp > finalMessage.Timestamp) { break; } if (!(message is IUserMessage userMessage)) { continue; } var modifyResult = await _discordRoleplays.ConsumeMessageAsync(userMessage); if (modifyResult.IsSuccess) { ++addedOrUpdatedMessageCount; } } } return(RuntimeCommandResult.FromSuccess ( $"{addedOrUpdatedMessageCount} messages added to \"{roleplay.Name}\"." )); }
public async Task <RuntimeResult> BwehAsync() { var eb = _feedback.CreateEmbedBase(); eb.WithImageUrl(_portraits.BwehUri.ToString()); await _feedback.SendEmbedAsync(this.Context.Channel, eb.Build()); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ShowServerStatsAsync() { var guild = this.Context.Guild; var eb = CreateGuildInfoEmbed(guild); await _feedback.SendEmbedAsync(this.Context.Channel, eb.Build()); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> OptOutOfTransformationsAsync() { var optOutResult = await _transformation.OptOutUserAsync(this.Context.User, this.Context.Guild); if (!optOutResult.IsSuccess) { return(optOutResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Opted out of transformations.")); }
public async Task <RuntimeResult> OptInToTransformationsAsync() { var optInResult = await _transformation.OptInUserAsync(this.Context.User, this.Context.Guild); if (!optInResult.IsSuccess) { return(optInResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Opted into transformations. Have fun!")); }
public async Task <RuntimeResult> CreateAutoroleAsync(IRole discordRole) { var create = await _autoroles.CreateAutoroleAsync(discordRole); if (!create.IsSuccess) { return(create.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Autorole configuration created.")); }
public async Task <RuntimeResult> AffirmAutoroleForAllAsync(AutoroleConfiguration autorole) { var affirmResult = await _autoroles.AffirmAutoroleForAllAsync(autorole); if (!affirmResult.IsSuccess) { return(affirmResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Qualifications affirmed.")); }
public async Task <RuntimeResult> BlacklistUserAsync(IUser user) { var blacklistUserResult = await _transformation.BlacklistUserAsync(this.Context.User, user); if (!blacklistUserResult.IsSuccess) { return(blacklistUserResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("User whitelisted.")); }
public async Task <RuntimeResult> ResetKinksAsync() { var resetResult = await _kinks.ResetUserKinksAsync(this.Context.User); if (!resetResult.IsSuccess) { return(resetResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Preferences reset.")); }
public async Task <RuntimeResult> SetMonitoringChannelAsync(ITextChannel channel) { var setChannel = await _moderation.SetMonitoringChannelAsync(this.Context.Guild, channel); if (!setChannel.IsSuccess) { return(setChannel.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Channel set.")); }
public async Task <RuntimeResult> ListAvailableRolesAsync() { var getServerRolesResult = await _characterRoles.GetCharacterRolesAsync(this.Context.Guild); if (!getServerRolesResult.IsSuccess) { return(getServerRolesResult.ToRuntimeResult()); } var serverRoles = getServerRolesResult.Entity.ToList(); var eb = _feedback.CreateEmbedBase(); eb.WithTitle("Available character roles"); eb.WithDescription ( "These are the roles you can apply to your characters to automatically switch you to that role " + "when you assume the character.\n" + "\n" + "In order to avoid mentioning everyone that has the role, use the numerical ID or role name" + " instead of the actual mention. The ID is listed below along with the role name." ); if (!serverRoles.Any()) { eb.WithFooter("There aren't any character roles available in this server."); } else { foreach (var characterRole in serverRoles) { var discordRole = this.Context.Guild.GetRole((ulong)characterRole.DiscordID); if (discordRole is null) { continue; } var ef = new EmbedFieldBuilder(); ef.WithName($"{discordRole.Name} ({discordRole.Id})"); var roleStatus = characterRole.Access == RoleAccess.Open ? "open to everyone" : "restricted"; ef.WithValue($"*This role is {roleStatus}.*"); eb.AddField(ef); } } await _feedback.SendEmbedAsync(this.Context.Channel, eb.Build()); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> GrantConsentAsync() { var grantResult = await _privacy.GrantUserConsentAsync(this.Context.User); if (!grantResult.IsSuccess) { return(grantResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Thank you! Enjoy using the bot :smiley:")); }
public async Task <RuntimeResult> UpdateKinkDatabaseAsync() { await _feedback.SendConfirmationAsync(this.Context, "Updating kinks..."); var updatedKinkCount = 0; // Get the latest JSON from F-list string json; using (var web = new HttpClient()) { web.Timeout = TimeSpan.FromSeconds(3); var cts = new CancellationTokenSource(); cts.CancelAfter(web.Timeout); try { using var response = await web.GetAsync ( new Uri ("https://www.f-list.net/json/api/kink-list.php"), cts.Token ); json = await response.Content.ReadAsStringAsync(); } catch (OperationCanceledException) { return(RuntimeCommandResult.FromError("Could not connect to F-list: Operation timed out.")); } } var kinkCollection = JsonConvert.DeserializeObject <KinkCollection>(json); if (kinkCollection.KinkCategories is null) { return(RuntimeCommandResult.FromError($"Received an error from F-List: {kinkCollection.Error}")); } foreach (var kinkSection in kinkCollection.KinkCategories) { if (!Enum.TryParse <KinkCategory>(kinkSection.Key, out var kinkCategory)) { return(RuntimeCommandResult.FromError("Failed to parse kink category.")); } updatedKinkCount += await _kinks.UpdateKinksAsync(kinkSection.Value.Kinks.Select ( k => new Kink(k.Name, k.Description, k.KinkId, kinkCategory) )); } return(RuntimeCommandResult.FromSuccess($"Done. {updatedKinkCount} kinks updated.")); }
public async Task <RuntimeResult> BapAsync(IUser target) { if (!target.IsMe(this.Context.Client)) { return(RuntimeCommandResult.FromSuccess($"**baps {target.Mention}**")); } await _feedback.SendConfirmationAsync(this.Context, "...seriously?"); return(RuntimeCommandResult.FromSuccess($"**baps {this.Context.User.Mention}**")); }
public async Task <RuntimeResult> SetWarningThresholdAsync(int threshold) { var setChannel = await _moderation.SetWarningThresholdAsync(this.Context.Guild, threshold); if (!setChannel.IsSuccess) { return(setChannel.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Threshold set.")); }
public async Task <RuntimeResult> DisableAutoroleAsync(AutoroleConfiguration autorole) { var disableAutorole = await _autoroles.DisableAutoroleAsync(autorole); if (!disableAutorole.IsSuccess) { return(disableAutorole.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Autorole disabled.")); }
public async Task <RuntimeResult> ShowAvailablePronounFamiliesAsync() { EmbedFieldBuilder CreatePronounField(IPronounProvider pronounProvider) { var ef = new EmbedFieldBuilder(); ef.WithName(pronounProvider.Family); var value = $"{pronounProvider.GetSubjectForm()} ate {pronounProvider.GetPossessiveAdjectiveForm()} " + $"pie that {pronounProvider.GetSubjectForm()} brought with " + $"{pronounProvider.GetReflexiveForm()}."; value = value.Transform(To.SentenceCase); ef.WithValue($"*{value}*"); return(ef); } var pronounProviders = _pronouns.GetAvailablePronounProviders().ToList(); if (!pronounProviders.Any()) { return(RuntimeCommandResult.FromError("There doesn't seem to be any pronouns available.")); } var fields = pronounProviders.Select(CreatePronounField); var description = "Each field below represents a pronoun that can be used with a character. The title of " + "each field is the pronoun family that you use when selecting the pronoun, and below it" + "is a short example of how it might be used."; var paginatedEmbedPages = PageFactory.FromFields ( fields, description: description ); var paginatedEmbed = new PaginatedEmbed(_feedback, _interactivity, this.Context.User).WithPages ( paginatedEmbedPages.Select ( p => p.WithColor(Color.DarkPurple).WithTitle("Available pronouns") ) ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5.0) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> ListWarningsAsync(IGuildUser user) { var warnings = await _warnings.GetWarningsAsync(user); var appearance = PaginatedAppearanceOptions.Default; appearance.Title = "Warnings"; appearance.Color = Color.Orange; var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync ( _feedback, _interactivity, this.Context.User, warnings, async (eb, warning) => { eb.WithTitle($"Warning #{warning.ID} for {user.Username}:{user.Discriminator}"); var author = await this.Context.Guild.GetUserAsync((ulong)warning.Author.DiscordID); eb.WithAuthor(author); eb.WithDescription(warning.Reason); eb.AddField("Created", warning.CreatedAt); if (warning.CreatedAt != warning.UpdatedAt) { eb.AddField("Last Updated", warning.UpdatedAt); } if (warning.IsTemporary) { eb.AddField("Expires On", warning.ExpiresOn); } if (!(warning.MessageID is null)) { // TODO } }, appearance : appearance ); await _interactivity.SendInteractiveMessageAndDeleteAsync ( this.Context.Channel, paginatedEmbed, TimeSpan.FromMinutes(5) ); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> AddWarningAsync ( IGuildUser user, string reason, TimeSpan?expiresAfter = null ) { DateTime?expiresOn = null; if (!(expiresAfter is null)) { expiresOn = DateTime.Now.Add(expiresAfter.Value); } var addWarning = await _warnings.CreateWarningAsync(this.Context.User, user, reason, expiresOn : expiresOn); if (!addWarning.IsSuccess) { return(addWarning.ToRuntimeResult()); } var warning = addWarning.Entity; var getSettings = await _moderation.GetOrCreateServerSettingsAsync(this.Context.Guild); if (!getSettings.IsSuccess) { return(getSettings.ToRuntimeResult()); } var settings = getSettings.Entity; var notifyResult = await _logging.NotifyUserWarningAddedAsync(warning); if (!notifyResult.IsSuccess) { return(notifyResult.ToRuntimeResult()); } var warnings = await _warnings.GetWarningsAsync(user); if (warnings.Count >= settings.WarningThreshold) { await _feedback.SendWarningAsync ( this.Context, $"The warned user now has {warnings.Count} warnings. Consider further action." ); } return(RuntimeCommandResult.FromSuccess($"Warning added (ID {warning.ID}).")); }
public async Task <RuntimeResult> SassAsync() { var isNsfwChannel = this.Context.Channel is ITextChannel textChannel && textChannel.IsNsfw; var getSassResult = await _sass.GetSassAsync(isNsfwChannel); if (!getSassResult.IsSuccess) { return(getSassResult.ToRuntimeResult()); } var sass = getSassResult.Entity; return(RuntimeCommandResult.FromSuccess(sass)); }
public async Task <RuntimeResult> SetDefaultOptInOrOutOfTransformationsAsync(bool shouldOptIn = true) { var setDefaultOptInResult = await _transformation.SetDefaultOptInAsync(this.Context.User, shouldOptIn); if (!setDefaultOptInResult.IsSuccess) { return(setDefaultOptInResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess ( $"You're now opted {(shouldOptIn ? "in" : "out")} by default on new servers." )); }
public async Task <RuntimeResult> ClearAffirmationNotificationChannel() { var clearResult = await _autoroles.ClearAffirmationNotificationChannelAsync ( this.Context.Guild ); if (!clearResult.IsSuccess) { return(clearResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Channel cleared.")); }
public async Task <RuntimeResult> SetProtectionTypeAsync(ProtectionType protectionType) { var setProtectionTypeResult = await _transformation.SetServerProtectionTypeAsync(this.Context.User, this.Context.Guild, protectionType); if (!setProtectionTypeResult.IsSuccess) { return(setProtectionTypeResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess ( $"Protection type set to \"{protectionType.Humanize()}\"" )); }
public async Task <RuntimeResult> RunKinkWizardAsync() { var wizard = new KinkWizard ( _feedback, _interactivity, _kinks, this.Context.User ); await _interactivity.SendPrivateInteractiveMessageAsync(this.Context, _feedback, wizard); return(RuntimeCommandResult.FromSuccess()); }
public async Task <RuntimeResult> AddNoteAsync(IGuildUser user, string content) { var addNote = await _notes.CreateNoteAsync(this.Context.User, user, content); if (!addNote.IsSuccess) { return(addNote.ToRuntimeResult()); } var note = addNote.Entity; await _logging.NotifyUserNoteAddedAsync(note); return(RuntimeCommandResult.FromSuccess($"Note added (ID {note.ID}).")); }
public async Task <RuntimeResult> SetDefaultCharacterAsync ( [RequireEntityOwner] Character character ) { var result = await _characters.SetDefaultCharacterAsync((IGuildUser)this.Context.User, character); if (!result.IsSuccess) { return(result.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Default character set.")); }
public async Task <RuntimeResult> StopRoleplayAsync ( [RequireEntityOwnerOrPermission(typeof(StartStopRoleplay), PermissionTarget.Other)] Roleplay roleplay ) { var stopRoleplayAsync = await _discordRoleplays.StopRoleplayAsync(roleplay); if (!stopRoleplayAsync.IsSuccess) { return(stopRoleplayAsync.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess($"The roleplay \"{roleplay.Name}\" has been stopped.")); }
public async Task <RuntimeResult> RemoveConditionAsync ( AutoroleConfiguration autorole, long conditionID ) { var removeCondition = await _autoroles.RemoveConditionAsync(autorole, conditionID); if (!removeCondition.IsSuccess) { return(removeCondition.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Condition removed.")); }
public async Task <RuntimeResult> HelpAsync() { var modules = _commands.Modules.Where(m => !m.IsSubmodule).ToList(); var helpWizard = new HelpWizard(modules, _interactive, _feedback, _help, this.Context.User); await _interactive.SendPrivateInteractiveMessageAndDeleteAsync ( this.Context, _feedback, helpWizard, TimeSpan.FromMinutes(30) ); return(RuntimeCommandResult.FromSuccess()); }