/// <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.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add user", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await RunSubForm <RaidCommitUserFormData>().ConfigureAwait(false); var user = _commitData.Users .FirstOrDefault(obj => obj.DiscordUserId == data.User.Id); if (user != null) { user.Points = data.Points; } else { _commitData.Users .Add(new RaidCommitUserData { Points = data.Points, DiscordUserId = data.User.Id }); } return 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); } } } }
public EmojiButler(DiscordSocketClient client, CommandHandlerService commandHandler, DiscordEmojiService discordEmoji, EmojiButlerConfiguration configuration) { this.client = client; this.discordEmoji = discordEmoji; this.commandHandler = commandHandler; this.configuration = configuration; }
/// <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> /// 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.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddUserCommand", "{0} Add user", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var members = await RunSubElement <CalendarAddParticipantsDialogElement, List <DiscordMember> >().ConfigureAwait(false); if (members != null) { foreach (var member in members) { if (_data.Participants.Any(obj => obj.Member.Id == member.Id) == false) { _data.Participants.Add(new CalendarAppointmentParticipantData { Member = member, IsLeader = false }); } } } return true; } },
/// <summary> /// Editing the embedded message /// </summary> /// <param name="builder">Builder</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public override Task EditMessage(DiscordEmbedBuilder builder) { builder.WithTitle(LocalizationGroup.GetText("ChooseCommandTitle", "Raid template configuration")); builder.WithDescription(LocalizationGroup.GetText("ChooseCommandDescription", "With this assistant you are able to configure the raid templates. The following templates are already created:")); var templatesBuilder = new StringBuilder(); var templates = GetTemplates(); if (templates.Count > 0) { foreach (var template in templates) { templatesBuilder.AppendLine(Formatter.Bold($"{DiscordEmojiService.GetBulletEmoji(CommandContext.Client)} {template}")); } } else { templatesBuilder.Append('\u200B'); } builder.AddField(LocalizationGroup.GetText("TemplatesField", "Templates"), templatesBuilder.ToString()); return(Task.CompletedTask); }
/// <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> },
/// <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("CommitTitle", "Participants")); builder.WithDescription(LocalizationGroup.GetText("CommitText", "The following participants are recorded:")); builder.WithColor(DiscordColor.Green); builder.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64"); builder.WithTimestamp(DateTime.Now); var message = new StringBuilder(); if (_data.Participants == null) { _data.Participants = new List <CalendarAppointmentParticipantData>(); using (var dbFactory = RepositoryFactory.CreateInstance()) { foreach (var entry in dbFactory.GetRepository <CalendarAppointmentParticipantRepository>() .GetQuery() .Where(obj => obj.AppointmentId == _data.AppointmentId) .Select(obj => new { UserId = obj.User .DiscordAccounts .Select(obj2 => obj2.Id) .FirstOrDefault(), obj.IsLeader })) { _data.Participants.Add(new CalendarAppointmentParticipantData { Member = await CommandContext.Guild .GetMemberAsync(entry.UserId) .ConfigureAwait(false), IsLeader = entry.IsLeader }); } } } foreach (var entry in _data.Participants .OrderBy(obj => obj.Member.TryGetDisplayName())) { message.Append($"> {entry.Member.Mention}"); if (entry.IsLeader) { message.Append(' '); message.Append(DiscordEmojiService.GetStarEmoji(CommandContext.Client)); } message.Append('\n'); } message.AppendLine("\u200b"); builder.AddField($"{LocalizationGroup.GetText("Participants", "Participants")} ({_data.Participants.Count})", message.ToString()); }
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); }
/// <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 <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetCheckEmoji(CommandContext.Client), Func = () => Task.FromResult(true) },
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); })); }
/// <summary> /// Return the message of element /// </summary> /// <returns>Message</returns> public override DiscordEmbedBuilder GetMessage() { var builder = new DiscordEmbedBuilder(); builder.WithTitle(LocalizationGroup.GetText("ChooseLevelTitle", "Raid role selection")); builder.WithDescription(LocalizationGroup.GetText("ChooseLevelDescription", "Please choose one of the following roles:")); _roles = new Dictionary <int, long?>(); var levelsFieldsText = new StringBuilder(); using (var dbFactory = RepositoryFactory.CreateInstance()) { var mainRoles = dbFactory.GetRepository <RaidRoleRepository>() .GetQuery() .Where(obj => obj.MainRoleId == _mainRoleId && obj.IsDeleted == false) .Select(obj => new { obj.Id, obj.Description, obj.DiscordEmojiId }) .OrderBy(obj => obj.Description) .ToList(); levelsFieldsText.Append("`0` - "); levelsFieldsText.Append(LocalizationGroup.GetText("NoRole", "No additional role")); levelsFieldsText.Append('\n'); _roles[0] = null; var i = 1; var fieldCounter = 1; foreach (var role in mainRoles) { var currentLine = $"`{i}` - {DiscordEmojiService.GetGuildEmoji(CommandContext.Client, role.DiscordEmojiId)} {role.Description}{'\n'}"; _roles[i] = role.Id; i++; if (currentLine.Length + levelsFieldsText.Length > 1024) { builder.AddField(LocalizationGroup.GetText("RolesField", "Roles") + " #" + fieldCounter, levelsFieldsText.ToString()); levelsFieldsText.Clear(); fieldCounter++; } levelsFieldsText.Append(currentLine); } builder.AddField(LocalizationGroup.GetText("RolesField", "Roles") + " #" + fieldCounter, levelsFieldsText.ToString()); } return(builder); }
/// <summary> /// Editing a sub role /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <param name="mainRoleId">Id of the role</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunEditSubRoleAssistantAsync(CommandContextContainer commandContextContainer, long mainRoleId) { var roleId = await SelectRoleAsync(commandContextContainer, mainRoleId).ConfigureAwait(false); if (roleId != null) { var builder = new DiscordEmbedBuilder(); builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration")); var descriptionEmoji = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client); var emojiEmoji = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client); var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var commands = new StringBuilder(); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji)); builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString()); var message = await commandContextContainer.Channel .SendMessageAsync(builder) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(message, commandContextContainer.User); await message.CreateReactionAsync(descriptionEmoji).ConfigureAwait(false); await message.CreateReactionAsync(emojiEmoji).ConfigureAwait(false); await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == descriptionEmoji.Id) { await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == emojiEmoji.Id) { await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).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> /// 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.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditSuperiorRoleCommand", "{0} Edit superior role", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var newSuperiorLevelId = await RunSubElement <RaidExperienceLevelSuperiorLevelDialogElement, long?>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var levelId = DialogContext.GetValue <long>("ExperienceLevelId"); dbFactory.GetRepository <RaidExperienceLevelRepository>() .Refresh(obj => obj.SuperiorExperienceLevelId == levelId, obj => obj.SuperiorExperienceLevelId = obj.SuperiorRaidExperienceLevel.SuperiorExperienceLevelId); if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRange(obj => obj.Id != levelId, obj => obj.SuperiorExperienceLevelId = newSuperiorLevelId)) { if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRange(obj => obj.SuperiorExperienceLevelId == newSuperiorLevelId && obj.Id != levelId, obj => obj.SuperiorExperienceLevelId = levelId)) { dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRanks(); } } } return 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.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditInGameNameCommand", "{0} Edit in game name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var inGameName = await RunSubElement <GuildRankInGameNameDialogElement, string>().ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var rankId = DialogContext.GetValue <int>("RankId"); dbFactory.GetRepository <GuildRankRepository>() .Refresh(obj => obj.Id == rankId, obj => obj.InGameName = inGameName); } return 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.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditDescriptionCommand", "{0} Edit description", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var description = await RunSubElement <CalendarTemplateDescriptionDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("CalendarTemplateId"); dbFactory.GetRepository <CalendarAppointmentTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.Description = description); } return 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.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditAliasCommand", "{0} Edit alias name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var aliasName = await RunSubElement <RaidTemplateAliasNameDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("TemplateId"); dbFactory.GetRepository <RaidDayTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.AliasName = aliasName); } return true; } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add schedule", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateCalendarScheduleData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var level = new CalendarAppointmentScheduleEntity { DiscordServerId = CommandContext.Guild.Id, Description = data.Description, CalendarAppointmentTemplateId = data.TemplateId, Type = data.Schedule.Type, AdditionalData = data.Schedule.AdditionalData }; dbFactory.GetRepository <CalendarAppointmentScheduleRepository>() .Add(level); } return(true); } } }; if (GetSchedules().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit schedule", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <CalendarScheduleSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("CalendarScheduleId", levelId); bool repeat; do { repeat = await RunSubElement <CalendarScheduleEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete schedule", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <CalendarScheduleSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("CalendarScheduleId", levelId); return(await RunSubElement <CalendarScheduleDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <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> /// Refresh the message /// </summary> /// <param name="configurationId">Id of the configuration</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task RefreshMessageAsync(long configurationId) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var currentRaidPoints = dbFactory.GetRepository <RaidCurrentUserPointsRepository>() .GetQuery() .Select(obj => obj); var appointment = dbFactory.GetRepository <RaidAppointmentRepository>() .GetQuery() .Where(obj => obj.ConfigurationId == configurationId && obj.IsCommitted == false) .OrderByDescending(obj => obj.TimeStamp) .Select(obj => new { obj.TimeStamp, ChannelId = obj.RaidDayConfiguration.DiscordChannelId, MessageId = obj.RaidDayConfiguration.DiscordMessageId, obj.RaidDayTemplate.Thumbnail, obj.RaidDayTemplate.Title, obj.RaidDayTemplate.Description, obj.GroupCount, ExperienceLevels = obj.RaidDayTemplate .RaidExperienceAssignments .Select(obj2 => new { RaidExperienceLevelId = obj2.RaidExperienceLevel.Id, obj2.RaidExperienceLevel.DiscordEmoji, obj2.RaidExperienceLevel.Description, obj2.RaidExperienceLevel.Rank, obj2.Count }) .ToList(), Registrations = obj.RaidRegistrations .Select(obj3 => new { UserId = obj3.User .DiscordAccounts .Select(obj4 => obj4.Id) .FirstOrDefault(), Points = currentRaidPoints.Where(obj4 => obj4.UserId == obj3.UserId) .Select(obj4 => obj4.Points).FirstOrDefault(), obj3.LineupExperienceLevelId, ExperienceLevelId = (int?)obj3.User.RaidExperienceLevel.Id, ExperienceLevelDiscordEmoji = (ulong?)obj3.User.RaidExperienceLevel.DiscordEmoji, Roles = obj3.RaidRegistrationRoleAssignments .Select(obj4 => new { MainRoleEmoji = obj4.MainRaidRole.DiscordEmojiId, SubRoleEmoji = (ulong?)obj4.SubRaidRole.DiscordEmojiId }) .ToList() }) .ToList() }) .FirstOrDefault(); if (appointment != null) { var builder = new DiscordEmbedBuilder(); var channel = await _client.GetChannelAsync(appointment.ChannelId) .ConfigureAwait(false); if (channel != null) { var message = await channel.GetMessageAsync(appointment.MessageId) .ConfigureAwait(false); if (message != null) { var fieldBuilder = new StringBuilder(); int fieldCounter; // Building the message foreach (var slot in appointment.ExperienceLevels .OrderBy(obj => obj.Rank)) { fieldCounter = 1; var registrations = appointment.Registrations .Where(obj => obj.LineupExperienceLevelId == slot.RaidExperienceLevelId) .OrderByDescending(obj => obj.Points) .ToList(); foreach (var registration in registrations) { var discordUser = await _client.GetUserAsync(registration.UserId) .ConfigureAwait(false); var lineBuilder = new StringBuilder(); lineBuilder.Append(" > "); if (registration.Roles.Count > 0) { var first = true; foreach (var role in registration.Roles) { if (first == false) { lineBuilder.Append(", "); } else { first = false; } lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.MainRoleEmoji)); if (role.SubRoleEmoji != null) { lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.SubRoleEmoji.Value)); } } } else { lineBuilder.Append(DiscordEmojiService.GetQuestionMarkEmoji(_client)); } lineBuilder.Append($" {discordUser.Mention}"); if (registration.LineupExperienceLevelId != registration.ExperienceLevelId && registration.ExperienceLevelDiscordEmoji != null) { lineBuilder.Append(' '); lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, registration.ExperienceLevelDiscordEmoji.Value)); } lineBuilder.Append('\n'); if (lineBuilder.Length + fieldBuilder.Length > 1024) { builder.AddField($"{DiscordEmojiService.GetGuildEmoji(_client, slot.DiscordEmoji)} {slot.Description} ({registrations.Count}/{slot.Count * appointment.GroupCount}) #{fieldCounter}", fieldBuilder.ToString()); fieldBuilder = new StringBuilder(); fieldCounter++; } fieldBuilder.Append(lineBuilder); } fieldBuilder.Append('\u200B'); var fieldName = $"{DiscordEmojiService.GetGuildEmoji(_client, slot.DiscordEmoji)} {slot.Description} ({registrations.Count}/{slot.Count * appointment.GroupCount})"; if (fieldCounter > 1) { fieldName = $"{fieldName} #{fieldCounter}"; } builder.AddField(fieldName, fieldBuilder.ToString()); fieldBuilder.Clear(); } fieldCounter = 1; foreach (var entry in appointment.Registrations .Where(obj => obj.LineupExperienceLevelId == null) .OrderByDescending(obj => obj.Points)) { var discordUser = await _client.GetUserAsync(entry.UserId) .ConfigureAwait(false); var lineBuilder = new StringBuilder(); lineBuilder.Append(" > "); if (entry.Roles?.Count > 0) { var first = true; foreach (var role in entry.Roles) { if (first == false) { lineBuilder.Append(", "); } else { first = false; } lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.MainRoleEmoji)); if (role.SubRoleEmoji != null) { lineBuilder.Append(DiscordEmojiService.GetGuildEmoji(_client, role.SubRoleEmoji.Value)); } } } else { lineBuilder.Append(DiscordEmojiService.GetQuestionMarkEmoji(_client)); } lineBuilder.AppendLine($" {discordUser.Mention} {(entry.ExperienceLevelDiscordEmoji != null ? DiscordEmojiService.GetGuildEmoji(_client, entry.ExperienceLevelDiscordEmoji.Value) : null)}"); if (lineBuilder.Length + fieldBuilder.Length > 1024) { builder.AddField($"{LocalizationGroup.GetText("SubstitutesBench", "Substitutes bench")} #{fieldCounter}", fieldBuilder.ToString()); fieldBuilder = new StringBuilder(); fieldCounter++; } fieldBuilder.Append(lineBuilder); } fieldBuilder.Append('\u200B'); var substitutesBenchFieldName = LocalizationGroup.GetText("SubstitutesBench", "Substitutes bench"); if (fieldCounter > 1) { substitutesBenchFieldName = $"{substitutesBenchFieldName} #{fieldCounter}"; } builder.AddField(substitutesBenchFieldName, fieldBuilder.ToString()); builder.WithTitle($"{appointment.Title} - {appointment.TimeStamp.ToString("g", LocalizationGroup.CultureInfo)}"); builder.WithDescription(appointment.Description); builder.WithThumbnail(appointment.Thumbnail); builder.WithColor(DiscordColor.Green); builder.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64"); builder.WithTimestamp(DateTime.Now); await message.ModifyAsync(null, builder.Build()) .ConfigureAwait(false); } } } } }
/// <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("CommitTitle", "Raid points commit")); builder.WithDescription(LocalizationGroup.GetText("CommitText", "The following points will be committed:")); builder.WithColor(DiscordColor.Green); builder.WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64"); builder.WithTimestamp(DateTime.Now); var message = new StringBuilder(); var fieldCounter = 1; foreach (var user in _commitData.Users .OrderByDescending(obj => obj.Points)) { var discordUser = await CommandContext.Client .GetUserAsync(user.DiscordUserId) .ConfigureAwait(false); var currentLine = $"{Formatter.InlineCode(user.Points.ToString("0.0"))} - {DiscordEmojiService.GetGuildEmoji(CommandContext.Client, user.DiscordEmoji)} {discordUser.Mention}"; if (currentLine.Length + message.Length > 1024) { builder.AddField(LocalizationGroup.GetText("Users", "Users") + " #" + fieldCounter, message.ToString()); fieldCounter++; message = new StringBuilder(); } message.AppendLine(currentLine); } message.AppendLine("\u200b"); var fieldName = LocalizationGroup.GetText("Users", "Users"); if (fieldCounter > 1) { fieldName = fieldName + " #" + fieldCounter; } builder.AddField(fieldName, message.ToString()); }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add rank", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateGuildSpecialRankData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var rank = new GuildSpecialRankConfigurationEntity { GuildId = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == CommandContext.Guild.Id) .Select(obj => obj.Id) .First(), Description = data.Description, DiscordRoleId = data.DiscordRoleId, MaximumPoints = data.MaximumPoints, GrantThreshold = data.GrantThreshold, RemoveThreshold = data.RemoveThreshold }; if (dbFactory.GetRepository <GuildSpecialRankConfigurationRepository>() .Add(rank)) { DialogContext.SetValue("RankId", rank.Id); bool repeat; do { repeat = await RunSubElement <GuildSpecialRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); } } return(true); } } }; if (GetRanks().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit rank", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("RankId", levelId); bool repeat; do { repeat = await RunSubElement <GuildSpecialRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete rank", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var rankId = await RunSubElement <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("RankId", rankId); return(await RunSubElement <GuildSpecialRankDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <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> /// 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.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditApiKeyCommand", "{0} Edit api key", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var success = false; var apiKey = await RunSubElement <AccountApiKeyDialogElement, string>().ConfigureAwait(false); apiKey = apiKey?.Trim(); if (string.IsNullOrWhiteSpace(apiKey) == false) { try { var connector = new GuidWars2ApiConnector(apiKey); await using (connector.ConfigureAwait(false)) { var tokenInformation = await connector.GetTokenInformationAsync() .ConfigureAwait(false); if (tokenInformation?.Permissions != null && tokenInformation.Permissions.Contains(TokenInformation.Permission.Account) && tokenInformation.Permissions.Contains(TokenInformation.Permission.Characters) && tokenInformation.Permissions.Contains(TokenInformation.Permission.Progression)) { var accountInformation = await connector.GetAccountInformationAsync() .ConfigureAwait(false); if (accountInformation.Name == DialogContext.GetValue <string>("AccountName")) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var user = await CommandContext.GetCurrentUser() .ConfigureAwait(false); if (dbFactory.GetRepository <AccountRepository>() .Refresh(obj => obj.UserId == user.Id && obj.Name == accountInformation.Name, obj => { obj.ApiKey = apiKey; obj.Permissions = GuildWars2ApiPermissionConverter.ToPermission(tokenInformation.Permissions); })) { success = true; } } } else { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("AccountNameMismatch", "The provided api key doesn't match the current account name.")) .ConfigureAwait(false); } } else { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions.")) .ConfigureAwait(false); } } } catch (HttpRequestException ex) when(ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions.")) .ConfigureAwait(false); } } return success; } }, new () { Emoji = DiscordEmojiService.GetEdit2Emoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditDpsReportUserTokenCommand", "{0} Edit dps report user token", DiscordEmojiService.GetEdit2Emoji(CommandContext.Client)), Func = async() => { var token = await RunSubElement <AccountDpsReportUserTokenDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var accountName = DialogContext.GetValue <string>("AccountName"); var user = await CommandContext.GetCurrentUser() .ConfigureAwait(false); dbFactory.GetRepository <AccountRepository>() .Refresh(obj => obj.UserId == user.Id && obj.Name == accountName, obj => obj.DpsReportUserToken = token); } return true; } }, new () { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) } });
/// <summary> /// Post overview of experience roles /// </summary> /// <param name="commandContextContainer">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task PostExperienceLevelOverview(CommandContextContainer commandContextContainer) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var levels = await dbFactory.GetRepository <RaidExperienceLevelRepository>() .GetQuery() .OrderBy(obj => obj.Description) .Select(obj => new { obj.DiscordEmoji, obj.Description, Users = obj.Users.SelectMany(obj2 => obj2.DiscordAccounts) .OrderBy(obj2 => obj2.Id) .Select(obj2 => obj2.Id) }) .ToListAsync() .ConfigureAwait(false); var embedBuilder = new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = LocalizationGroup.GetText("ExperienceLevels", "Experience levels") }; var stringBuilder = new StringBuilder(); var fieldCounter = 1; var currentFieldTitle = string.Empty; foreach (var level in levels) { var levelFieldCounter = 1; currentFieldTitle = $"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, level.DiscordEmoji)} {level.Description} #{levelFieldCounter}"; foreach (var entry in level.Users) { var user = await commandContextContainer.Client .GetUserAsync(entry) .ConfigureAwait(false); var currentLine = $"{user.Mention}\n"; if (currentLine.Length + stringBuilder.Length > 1024) { stringBuilder.Append('\u200B'); embedBuilder.AddField(currentFieldTitle, stringBuilder.ToString()); if (fieldCounter == 6) { fieldCounter = 1; await commandContextContainer.Channel .SendMessageAsync(embedBuilder) .ConfigureAwait(false); embedBuilder = new DiscordEmbedBuilder { Color = DiscordColor.Green }; } else { fieldCounter++; } levelFieldCounter++; currentFieldTitle = $"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, level.DiscordEmoji)} {level.Description} #{levelFieldCounter}"; stringBuilder = new StringBuilder(); } stringBuilder.Append(currentLine); } stringBuilder.Append('\u200B'); embedBuilder.AddField(currentFieldTitle, stringBuilder.ToString()); stringBuilder = new StringBuilder(); } await commandContextContainer.Channel .SendMessageAsync(embedBuilder) .ConfigureAwait(false); } }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add template", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateRaidTemplateFormData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { dbFactory.GetRepository <RaidDayTemplateRepository>() .Add(new RaidDayTemplateEntity { AliasName = data.AliasName, Title = data.Title, Description = data.Description, Thumbnail = data.Thumbnail }); } return(true); } } }; if (GetTemplates().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit template", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("TemplateId", templateId); bool repeat; do { repeat = await RunSubElement <RaidTemplateEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete template", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("TemplateId", templateId); return(await RunSubElement <RaidTemplateDeletionElementBase, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }