public async Task AddRoleAsync(IChannel channel, IRole role, IEmote emote, [Remainder] String shortDescription) { if (this.IsPrivate) { var builder = new KuuhakuEmbedBuilder() .WithTitle("No no") .WithDescription("This command is only for servers. Sorry.") .WithFooter(this.Client.CurrentUser) .WithCurrentTimestamp(); await this.ReplyAsync(builder); return; } if (!(channel is IMessageChannel messageChannel)) { var builder = new KuuhakuEmbedBuilder() .WithTitle("Woopsies") .WithDescription("Channel provided does not appear to be a text channel.") .WithFooter(this.Context) .WithCurrentTimestamp(); await this.ReplyAsync(builder); return; } await this._userRoleService.AddRoleAsync(this.Guild, messageChannel, role, emote, shortDescription); await this.Message.AddReactionAsync(new Emoji(NeoSmart.Unicode.Emoji.ThumbsUp.ToString())); }
public async Task ViewBlacklistedUsers() { var blacklistedUsers = await this._repository.GetBlacklistedUsers(this.Guild); var embed = new KuuhakuEmbedBuilder() .WithColor() .WithFooter(this.Context); const String prefixMessage = "The following users are blacklisted from using my commands: "; var messageLength = prefixMessage.Length; var blacklistedMentions = new List <String>(); foreach (var blacklistedUser in blacklistedUsers.Where(v => v > 0)) { var mention = MentionUtils.MentionUser(blacklistedUser); messageLength += mention.Length + 2; if (messageLength > EmbedBuilder.MaxDescriptionLength - 20) { blacklistedMentions.Add("More…"); } blacklistedMentions.Add(mention); } if (blacklistedMentions.Count == 0) { await this.ReplyAsync( embed.WithDescription("There are no users who are blacklisted from using my commands")); return; } await this.ReplyAsync(embed.WithDescription(prefixMessage + blacklistedMentions.Humanize())); }
private KuuhakuEmbedBuilder CreateEmbed(IGuild guild, params UserRoleDto[] userRoles) { IUser currentUser; if (guild is SocketGuild socketGuild) { currentUser = socketGuild.CurrentUser; } else { currentUser = this._client.CurrentUser; } var builder = new KuuhakuEmbedBuilder() .WithColor() .WithFooter(currentUser); for (var i = 0; i < userRoles.Length; i++) { var userRole = userRoles[i]; var role = guild.GetRole(userRole.RoleId); builder.AddField(role.Name, userRole.ShortDescription, true); } return(builder); }
public async Task GetPrefixAsync() { var embed = new KuuhakuEmbedBuilder() .WithColor() .WithDescription($"The prefix for this server is {this.Context.Config.Prefix.MdBold()}") .WithFooter(this.Context); await this.ReplyAsync(embed); }
public async Task GetInfoAsync() { var embed = new KuuhakuEmbedBuilder() .WithColor() .WithDescription("The current settings for this server is...") .WithField("Prefix", this.Config.Prefix) .WithField("Command Seperator", this.Config.CommandSeperator) .WithFooter(this.Context); await this.ReplyAsync(embed); }
public async Task BlacklistModule(String moduleName) { var input = moduleName; moduleName = moduleName.Dehumanize(); if (!moduleName.EndsWith("Module", StringComparison.OrdinalIgnoreCase)) { moduleName += "Module"; } var embed = new KuuhakuEmbedBuilder() .WithColor() .WithFooter(this.Context); var modules = this._commandService.Modules.Select(m => m.Name); if (!modules.Contains(moduleName, StringComparer.OrdinalIgnoreCase)) { await this.ReplyAsync( embed.WithDescription($"There is no such module as {input.MdBold().Quote()}")); return; } var friendlyName = moduleName.Replace("Module", "").Humanize(LetterCasing.Title); if (this.PermanentModules.Contains(moduleName)) { await this.ReplyAsync(embed.WithDescription($"You cannot disable {friendlyName.MdBold().Quote()}")); return; } var isBlacklisted = await this._repository.IsModuleBlacklisted(this.Guild, moduleName); if (!isBlacklisted) { await this._repository.AddBlacklistedModule(this.Guild, moduleName); await this.ReplyAsync(embed.WithDescription( $"{friendlyName.MdBold().Quote()} has now been blacklisted.\n" + $"Users in this server will no longer be able to use it.")); } else { await this._repository.RemoveBlacklistModule(this.Guild, moduleName); await this.ReplyAsync(embed.WithDescription( $"{friendlyName.MdBold().Quote()} has is no longer blacklisted.\n" + $"Users in this server will now be able to use it.")); } }
public async Task BlacklistModule() { var availableModules = this._commandService.Modules.Select(m => m.Name.Replace("Module", "")); var blacklistedModules = await this._repository.GetBlacklistedModules(this.Guild); var embed = new KuuhakuEmbedBuilder() .WithColor() .WithDescription( $"The available Modules are: \n{availableModules.Humanize(m => m.Humanize(LetterCasing.Title).MdBold())}\n\n" + $"The currently Blacklisted Modules are: \n{blacklistedModules.Humanize(m => m.MdBold())}") .WithFooter(this.Context); await this.ReplyAsync(embed); }
public async Task SetPrefixAsync(String newPrefix) { var config = await this._repository.GetAsync(this.Guild); var oldPrefix = config.Prefix; config.Prefix = newPrefix; await this._repository.UpdateAsync(this.Guild, config); var embed = new KuuhakuEmbedBuilder() .WithColor() .WithDescription($"The prefix for this server is now {config.Prefix.MdBold()} (Was previously {oldPrefix.MdBold()})") .WithFooter(this.Context); await this.ReplyAsync(embed); }
public async Task RemoveRoleAsync(IMessageChannel channel, IRole role) { if (this.IsPrivate) { var builder = new KuuhakuEmbedBuilder() .WithColor() .WithTitle("No no") .WithDescription("This command is only for servers. Sorry.") .WithFooter(this.Context); await this.ReplyAsync(builder); return; } await this._userRoleService.RemoveRoleAsync(this.Guild, channel, role); await this.Message.AddReactionAsync(new Emoji(NeoSmart.Unicode.Emoji.ThumbsUp.ToString())); }
public async Task BlacklistUser(IUser user) { var isBlacklisted = await this._repository.IsUserBlacklisted(this.Guild, user); var embed = new KuuhakuEmbedBuilder() .WithColor() .WithFooter(this.Context); if (isBlacklisted) { await this._repository.RemoveBlacklistUser(this.Guild, user); await this.ReplyAsync(embed.WithDescription($"{user.Mention} is no longer blacklisted from using commands.")); } else { await this._repository.AddBlacklistedUser(this.Guild, user); await this.ReplyAsync(embed.WithDescription($"{user.Mention} is now blacklisted from using commands.")); } }
public async Task ToggleAdminAsync(IRole role) { var isMod = await this._repository.ExistsAsync(this.Guild, CommandPermissions.Admin.ToString(), role); var embed = new KuuhakuEmbedBuilder() .WithColor() .WithFooter(this.Context); if (isMod) { await this._repository.RemoveRoleAsync(this.Guild, CommandPermissions.Admin.ToString(), role); await this.ReplyAsync(embed.WithDescription($"{role.Mention} is no longer classified as an admin")); } else { await this._repository.AddRoleAsync(this.Guild, CommandPermissions.Admin.ToString(), role); await this.ReplyAsync(embed.WithDescription($"{role.Mention} is now classified as an admin")); } }
private async Task CheckReminders(CancellationToken ct) { if (this._client.ConnectionState != ConnectionState.Connected) { return; // Don't try to process. } var remindersToRemind = this.GetExpiredReminders().ToImmutableList(); if (remindersToRemind.Count == 0) { return; } this._logger.Info("Found {expiredRemindersCount} reminders that have expired. Attempting to send reminders.", remindersToRemind.Count); foreach (var reminder in remindersToRemind) { var reminderChannel = await this.GetChannelAsync(reminder); var reminderMessage = new KuuhakuEmbedBuilder() .WithColor(EmbedColorType.Success) .WithTitle("Reminder!") .WithDescription(reminder.Contents) .WithFooter(this.GetCurrentUser(reminder)) .WithTimestamp(reminder.CreatedAt); var(isLate, howLate) = this.CheckIfLate(reminder); if (isLate) { reminderMessage.AddField("Late!", $"Sorry about this, your reminder has arrived about {howLate.ToDuration()} late :s"); } await reminderChannel.SendMessageAsync(MentionUtils.MentionUser(reminder.UserId), reminderMessage, ct); reminder.IsActive = false; await this._repository.UpdateAsync(reminder); this._reminders.Remove(reminder); } }
private KuuhakuEmbedBuilder CreatePostEmbed(Post post, SourceBooru sauce) { var embed = new KuuhakuEmbedBuilder() .WithColor() .WithAuthor($"Id - {post.Id}", $"{sauce.BaseUri}favicon.ico", $"{sauce.BaseUri}{this.PostUrl(sauce.Identifier)}{post.Id}") .WithTimestamp(post.UploadedAt) .WithFooter(this.Context); var preview = $"{post.Files.Preview}"; var original = $"{post.Files.Original}"; var fileSizeValue = ""; try { var fileSizeAsInt = (Int32)post.Files.FileSize; fileSizeValue = fileSizeAsInt.Bytes().ToString("0.##"); } catch { fileSizeValue = "Too big to count!"; } return(embed .WithField("Hash", post.Hash) .WithField("Size", fileSizeValue) .WithFieldIf("Download", () => $"[Full Image]({original})", includeIf: original != preview) .WithFieldIf("Source", () => post.Source.Href.IsEmpty() ? post.Source.FriendlyName : $"[{post.Source.FriendlyName}]({post.Source.Href})", includeIf: post.Source != null) .WithField("Rating", post.Rating.ToString()) .AddField(this.CreateTagsField(post.Tags, sauce)) .WithImageUrl(preview)); }
public static Task <IUserMessage> SendMessageAsync(this IMessageChannel channel, String message, KuuhakuEmbedBuilder embedBuilder, CancellationToken ct = default) => channel.SendMessageAsync(message, embed: embedBuilder.Build(), options: new RequestOptions { CancelToken = ct });
public Task <IUserMessage> ReplyAsync(KuuhakuEmbedBuilder embed, CancellationToken ct = default) => this.ReplyAsync("", embed, ct);
public Task <IUserMessage> ReplyAsync(String message, KuuhakuEmbedBuilder embed, CancellationToken ct = default) => this.Channel.SendMessageAsync(message, embed, ct);
public static KuuhakuEmbedBuilder WithField(this KuuhakuEmbedBuilder embed, String title, in Object value)
public static KuuhakuEmbedBuilder WithField(this KuuhakuEmbedBuilder embed, String title, Object value, Boolean isInline = true) => embed.AddField(title, value, isInline);
public static KuuhakuEmbedBuilder WithAuthor(this KuuhakuEmbedBuilder embed, IUser user) => embed.WithAuthor(user.GetName(), user.GetAvatar(32));
public static KuuhakuEmbedBuilder WithColor(this KuuhakuEmbedBuilder embed, EmbedColorType type = EmbedColorType.Default) => embed.WithColor(EmbedColorTypeMap[type]);
public static Task <IUserMessage> SendMessageAsync(this IMessageChannel channel, KuuhakuEmbedBuilder embedBuilder, CancellationToken ct = default) => channel.SendMessageAsync("", embedBuilder, ct);