/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = () => { using (var dbFactory = RepositoryFactory.CreateInstance()) { var rankId = DialogContext.GetValue <int>("RankId"); if (dbFactory.GetRepository <GuildRankRepository>() .Remove(obj => obj.Id == rankId)) { var order = 0; foreach (var currentRankId in dbFactory.GetRepository <GuildRankRepository>() .GetQuery() .OrderBy(obj => obj.Order) .Select(obj => obj.Id)) { dbFactory.GetRepository <GuildRankRepository>() .Refresh(obj => obj.Id == currentRankId, obj => obj.Order = order); order++; } } } return Task.FromResult(true); } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = () => { using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("CalendarTemplateId"); if (dbFactory.GetRepository <CalendarAppointmentTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.IsDeleted = true)) { var now = DateTime.Now; dbFactory.GetRepository <CalendarAppointmentRepository>() .RemoveRange(obj => obj.CalendarAppointmentTemplateId == templateId && obj.TimeStamp > now); } } return Task.FromResult(true); } },
/// <summary> /// Starting the role deletion assistant /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunDeleteAssistantAsync(CommandContextContainer commandContextContainer) { var roleId = await SelectRoleAsync(commandContextContainer, null).ConfigureAwait(false); if (roleId != null) { var checkEmoji = DiscordEmojiService.GetCheckEmoji(commandContextContainer.Client); var crossEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var message = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DeleteRolePrompt", "Are you sure you want to delete the role?")) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(message, commandContextContainer.User); await message.CreateReactionAsync(checkEmoji).ConfigureAwait(false); await message.CreateReactionAsync(crossEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { using (var dbFactory = RepositoryFactory.CreateInstance()) { dbFactory.GetRepository <RaidRoleRepository>() .Refresh(obj => obj.Id == roleId.Value, obj => obj.IsDeleted = true); } } } }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = () => Task.FromResult(true) },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <CalenderTemplateGuildData> > GetReactions() { return(_reactions ??= new List <ReactionData <CalenderTemplateGuildData> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = RunSubForm <CalenderTemplateGuildData>, },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <string> > GetReactions() { return(_reactions ??= new List <ReactionData <string> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = RunSubElement <CalendarTemplateUriUriDialogElement, string> },
public async Task RefreshAppointments(CommandContext commandContext, DiscordUser discordUser) { await UserManagementService.CheckDiscordAccountAsync(discordUser.Id) .ConfigureAwait(false); await commandContext.Message .CreateReactionAsync(DiscordEmojiService.GetCheckEmoji(commandContext.Client)) .ConfigureAwait(false); }
public Task SetAdministrationRole(CommandContext commandContext, DiscordRole role) { return(InvokeAsync(commandContext, async commandContextContainer => { AdministrationPermissionsValidationService.AddOrRefresh(commandContext.Guild.Id, role.Id); await commandContext.Message.CreateReactionAsync(DiscordEmojiService.GetCheckEmoji(commandContext.Client)).ConfigureAwait(false); })); }
public async Task ImportItems(CommandContext commandContext) { if (await ItemsService.ImportItems() .ConfigureAwait(false)) { await commandContext.Message .CreateReactionAsync(DiscordEmojiService.GetCheckEmoji(commandContext.Client)) .ConfigureAwait(false); } else { await commandContext.Message .CreateReactionAsync(DiscordEmojiService.GetCrossEmoji(commandContext.Client)) .ConfigureAwait(false); } }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = () => { using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("TemplateId"); dbFactory.GetRepository <RaidDayTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.IsDeleted = true); } return Task.FromResult(true); } },
/// <summary> /// Editing the embedded message /// </summary> /// <param name="builder">Builder</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public override async Task EditMessage(DiscordEmbedBuilder builder) { builder.WithTitle(LocalizationGroup.GetText("ChooseCommandTitle", "Account configuration")); builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure your Guild Wars 2 account configuration.")); using (var dbFactory = RepositoryFactory.CreateInstance()) { var name = DialogContext.GetValue <string>("AccountName"); var data = await dbFactory.GetRepository <AccountRepository>() .GetQuery() .Where(obj => obj.User.DiscordAccounts.Any(obj2 => obj2.Id == CommandContext.User.Id) && obj.Name == name) .Select(obj => new { obj.Name, IsApiKeyAvailable = obj.ApiKey != null, obj.DpsReportUserToken, }) .FirstAsync() .ConfigureAwait(false); var stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("Name", "Name"))}: {data.Name}"); stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("IsApiKeyAvailable", "Api Key"))}: {(data.IsApiKeyAvailable ? DiscordEmojiService.GetCheckEmoji(CommandContext.Client) : DiscordEmojiService.GetCrossEmoji(CommandContext.Client))}"); stringBuilder.AppendLine($"{Formatter.InlineCode(LocalizationGroup.GetText("DpsReportUserToken", "dps.report user token"))}: {(string.IsNullOrWhiteSpace(data.DpsReportUserToken) ? DiscordEmojiService.GetCrossEmoji(CommandContext.Client) : data.DpsReportUserToken)}"); builder.AddField(LocalizationGroup.GetText("Data", "Data"), stringBuilder.ToString()); } }
/// <summary> /// Validation the guild bank /// </summary> /// <param name="commandContext">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task Check(CommandContextContainer commandContext) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var guild = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == commandContext.Guild.Id) .Select(obj => new { obj.ApiKey, obj.GuildId }) .FirstOrDefault(); if (string.IsNullOrWhiteSpace(guild?.ApiKey) == false) { var msg = new DiscordEmbedBuilder(); msg.WithTitle(LocalizationGroup.GetText("BankValidation", "Guild bank validation")); msg.WithDescription(LocalizationGroup.GetText("BankValidationResult", "In the following message you can see the results of the bank validation.")); msg.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64"); msg.WithTimestamp(DateTime.Now); var connector = new GuidWars2ApiConnector(guild.ApiKey); await using (connector.ConfigureAwait(false)) { var vault = await connector.GetGuildVault(guild.GuildId) .ConfigureAwait(false); foreach (var stash in vault) { var slots = new List <(int ItemId, int X, int Y)>(); var i = 0; foreach (var slot in stash.Slots) { if (slot != null && slot.Count < 250) { slots.Add((slot.ItemId, (i % 10) + 1, (i / 10) + 1)); } i++; } var stringBuilder = new StringBuilder(); foreach (var group in slots.ToLookup(obj => obj.ItemId, obj => (obj.X, obj.Y)) .Where(obj => obj.Count() > 1)) { var item = await connector.GetItem(group.Key) .ConfigureAwait(false); stringBuilder.AppendLine(item.Name); foreach (var(x, y) in group.OrderBy(obj => obj.X) .ThenBy(obj => obj.Y)) { stringBuilder.AppendLine($" - " + Formatter.InlineCode($"({x}/{y})")); } } if (stringBuilder.Length > 0) { stringBuilder.Insert(0, Formatter.Bold(LocalizationGroup.GetText("DuplicationCheck", "Duplication check")) + " \u200B " + DiscordEmojiService.GetCrossEmoji(commandContext.Client) + "\n"); } else { stringBuilder.AppendLine(Formatter.Bold(LocalizationGroup.GetText("DuplicationCheck", "Duplication check")) + " \u200B " + DiscordEmojiService.GetCheckEmoji(commandContext.Client)); } if (stash.Coins != 0 && stash.Coins % 10000 != 0) { var goldCoins = stash.Coins / 10000; var silverCoins = (stash.Coins - (goldCoins * 10000)) / 100; var copperCoins = stash.Coins % 100; stringBuilder.AppendLine(Formatter.Bold(LocalizationGroup.GetText("CoinCheck", "Coins check")) + " \u200B " + DiscordEmojiService.GetCrossEmoji(commandContext.Client)); stringBuilder.AppendLine($"{goldCoins} {DiscordEmojiService.GetGuildWars2GoldEmoji(commandContext.Client)} {silverCoins} {DiscordEmojiService.GetGuildWars2SilverEmoji(commandContext.Client)} {copperCoins} {DiscordEmojiService.GetGuildWars2CopperEmoji(commandContext.Client)}"); } else { stringBuilder.AppendLine(Formatter.Bold(LocalizationGroup.GetText("CoinCheck", "Coins check")) + " \u200B " + DiscordEmojiService.GetCheckEmoji(commandContext.Client)); } stringBuilder.Append("\u200B"); msg.AddField(stash.Note ?? "Stash", stringBuilder.ToString()); } } await commandContext.Channel .SendMessageAsync(msg) .ConfigureAwait(false); } else { await commandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("NoApiKey", "The guild ist not configured.")) .ConfigureAwait(false); } } }
/// <summary> /// Validation the guild bank /// </summary> /// <param name="commandContext">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task CheckUnlocksDyes(CommandContextContainer commandContext) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var guild = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == commandContext.Guild.Id) .Select(obj => new { obj.ApiKey, obj.GuildId }) .FirstOrDefault(); if (string.IsNullOrWhiteSpace(guild?.ApiKey) == false) { var user = await commandContext.GetCurrentUser() .ConfigureAwait(false); var apiKeys = dbFactory.GetRepository <AccountRepository>() .GetQuery() .Where(obj => obj.UserId == user.Id) .Select(obj => new { obj.ApiKey, obj.Name }) .ToList(); if (apiKeys.Count > 0) { var guildConnector = new GuidWars2ApiConnector(guild.ApiKey); await using (guildConnector.ConfigureAwait(false)) { var vault = await guildConnector.GetGuildVault(guild.GuildId) .ConfigureAwait(false); var itemIds = vault.SelectMany(obj => obj.Slots) .Where(obj => obj != null) .Select(obj => (int?)obj.ItemId) .Distinct() .ToList(); var items = await guildConnector.GetItems(itemIds) .ConfigureAwait(false); foreach (var apiKey in apiKeys) { var accountConnector = new GuidWars2ApiConnector(apiKey.ApiKey); await using (accountConnector.ConfigureAwait(false)) { var dyes = await accountConnector.GetDyes() .ConfigureAwait(false); var builder = new DiscordEmbedBuilder().WithTitle(LocalizationGroup.GetFormattedText("DyeUnlocksTitle", "Dye unlocks {0}", apiKey.Name)) .WithColor(DiscordColor.Green) .WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64") .WithTimestamp(DateTime.Now); var fieldBuilder = new StringBuilder(); var fieldCounter = 1; foreach (var item in items.Where(obj => obj.Type == "Consumable" && obj.Details?.Type == "Unlock" && obj.Details?.UnlockType == "Dye") .OrderBy(obj => obj.Name)) { var currentLine = dyes.Contains(item.Details.ColorId ?? 0) ? $"{DiscordEmojiService.GetCheckEmoji(commandContext.Client)} {item.Name}" : $"{DiscordEmojiService.GetCrossEmoji(commandContext.Client)} {item.Name}"; if (fieldBuilder.Length + currentLine.Length > 1024) { builder.AddField(LocalizationGroup.GetFormattedText("DyesFields", "Dyes #{0}", fieldCounter), fieldBuilder.ToString(), true); fieldBuilder = new StringBuilder(); fieldCounter++; } fieldBuilder.AppendLine(currentLine); } builder.AddField(LocalizationGroup.GetFormattedText("DyesFields", "Dyes #{0}", fieldCounter), fieldBuilder.ToString(), true); await commandContext.Message .RespondAsync(builder) .ConfigureAwait(false); } } } } else { await commandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("NoAccountApiKey", "You don't have any api keys configured.")) .ConfigureAwait(false); } } else { await commandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("NoApiKey", "The guild ist not configured.")) .ConfigureAwait(false); } } }
/// <summary> /// Starting the roles adding assistant /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunAddAssistantAsync(CommandContextContainer commandContextContainer) { var currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("ReactWithEmojiPrompt", "Please react with emoji which should be assigned to the role.")) .ConfigureAwait(false); var interactivity = commandContextContainer.Client .GetInteractivity(); var reaction = await interactivity.WaitForReactionAsync(currentBotMessage, commandContextContainer.User) .ConfigureAwait(false); if (reaction.TimedOut == false && reaction.Result.Emoji.Id > 0) { var roleData = new RaidRoleEntity { DiscordEmojiId = reaction.Result.Emoji.Id }; currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DescriptionPrompt", "Please enter the description of the role.")) .ConfigureAwait(false); var currentUserResponse = await interactivity.WaitForMessageAsync(obj => obj.Author.Id == commandContextContainer.User.Id && obj.ChannelId == commandContextContainer.Channel.Id) .ConfigureAwait(false); if (currentUserResponse.TimedOut == false) { roleData.Description = currentUserResponse.Result.Content; var continueCreation = true; var subRolesData = new List <RaidRoleEntity>(); var checkEmoji = DiscordEmojiService.GetCheckEmoji(commandContextContainer.Client); var crossEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var addSubRoles = true; while (addSubRoles) { var promptText = subRolesData.Count == 0 ? LocalizationGroup.GetText("AddSubRolesPrompt", "Do you want to add sub roles?") : LocalizationGroup.GetText("AddAdditionalSubRolesPrompt", "Do you want to add additional sub roles?"); currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(promptText) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(currentBotMessage, commandContextContainer.User); await currentBotMessage.CreateReactionAsync(checkEmoji).ConfigureAwait(false); await currentBotMessage.CreateReactionAsync(crossEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == checkEmoji.Id) { currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("ReactWithEmojiPrompt", "Please react with emoji which should be assigned to the role.")) .ConfigureAwait(false); reaction = await interactivity.WaitForReactionAsync(currentBotMessage, commandContextContainer.User) .ConfigureAwait(false); if (reaction.TimedOut == false && reaction.Result.Emoji.Id > 0) { var subRoleData = new RaidRoleEntity { DiscordEmojiId = reaction.Result.Emoji.Id }; currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DescriptionPrompt", "Please enter the description of the role.")) .ConfigureAwait(false); currentUserResponse = await interactivity.WaitForMessageAsync(obj => obj.Author.Id == commandContextContainer.User.Id && obj.ChannelId == commandContextContainer.Channel.Id) .ConfigureAwait(false); if (currentUserResponse.TimedOut == false) { subRoleData.Description = currentUserResponse.Result.Content; subRolesData.Add(subRoleData); } else { continueCreation = false; } } else { continueCreation = false; } } else { addSubRoles = false; } } else { continueCreation = false; } } if (continueCreation) { using (var dbFactory = RepositoryFactory.CreateInstance()) { if (dbFactory.GetRepository <RaidRoleRepository>() .Add(roleData)) { foreach (var subRole in subRolesData) { subRole.MainRoleId = roleData.Id; dbFactory.GetRepository <RaidRoleRepository>() .Add(subRole); } } } await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("CreationCompletedMessage", "The creation is completed.")) .ConfigureAwait(false); } } } }
/// <summary> /// Post update overview /// </summary> /// <param name="commandContext">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task PostUpdateOverview(CommandContextContainer commandContext) { var now = DateTime.Now; var builder = new DiscordEmbedBuilder() .WithThumbnail("https://cdn.discordapp.com/attachments/847555191842537552/861182143987712010/gw2.png") .WithTitle(LocalizationGroup.GetText("GuildWars2Updates", "Guild Wars 2 - Updates")) .WithColor(DiscordColor.Green) .WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64") .WithTimestamp(now); void AddField(string fieldName, NextUpdateData data) { var field = new StringBuilder(); field.Append("> "); field.Append(LocalizationGroup.GetText("Release", "Release")); field.Append(": "); field.Append(Formatter.MaskedUrl(data.When.ToLocalTime() .ToString("G", LocalizationGroup.CultureInfo), new Uri("https://thatshaman.com/tools/countdown"))); field.Append(Environment.NewLine); var timeSpan = data.When.ToLocalTime() - now; if (timeSpan > TimeSpan.Zero) { field.Append("> "); field.Append(LocalizationGroup.GetText("Timespan", "Timespan")); field.Append(": "); if (timeSpan.Days > 0) { field.Append(timeSpan.Days); field.Append(' '); field.Append(timeSpan.Days == 1 ? LocalizationGroup.GetText("Day", "Day") : LocalizationGroup.GetText("Days", "Days")); field.Append(' '); } if (timeSpan.TotalHours > 0) { field.Append(timeSpan.Hours); field.Append(' '); field.Append(timeSpan.Hours == 1 ? LocalizationGroup.GetText("Hour", "Hour") : LocalizationGroup.GetText("Hours", "Hours")); field.Append(' '); } field.Append(timeSpan.Minutes); field.Append(' '); field.Append(timeSpan.Minutes == 1 ? LocalizationGroup.GetText("Minute", "Minute") : LocalizationGroup.GetText("Minutes", "Minutes")); field.Append(' '); field.Append(timeSpan.Seconds); field.Append(' '); field.Append(timeSpan.Seconds == 1 ? LocalizationGroup.GetText("Second", "Second") : LocalizationGroup.GetText("Seconds", "Seconds")); field.Append(' '); field.Append('\n'); } field.Append("> "); field.Append(LocalizationGroup.GetText("Confirmed", "Confirmed")); field.Append(": "); field.Append(data.Confirmed ? DiscordEmojiService.GetCheckEmoji(commandContext.Client) : DiscordEmojiService.GetCrossEmoji(commandContext.Client)); if (data.Urls?.Count > 0) { var counter = 0; field.Append("\u200b ("); if (data.Urls.Count == 1) { field.Append(Formatter.MaskedUrl(LocalizationGroup.GetText("Source", "Source"), new Uri(data.Urls.First()))); } else { field.Append(LocalizationGroup.GetText("Sources", "Sources")); field.Append(": "); field.Append(string.Join(',', data.Urls.Select(obj => Formatter.MaskedUrl((++counter).ToString(), new Uri(obj))))); } field.Append(')'); } field.Append(Environment.NewLine); field.Append(''); field.Append(Environment.NewLine); builder.AddField(fieldName, field.ToString()); } AddField(LocalizationGroup.GetText("UpdateField", "General"), await _thatShamanConnector.GetNextUpdate() .ConfigureAwait(false)); AddField(LocalizationGroup.GetText("EodField", "End of Dragons"), await _thatShamanConnector.GetEODRelease() .ConfigureAwait(false)); await commandContext.Message .RespondAsync(builder) .ConfigureAwait(false); }