public FavouriteDiscordEmote AddFavouriteEmote(FavouriteDiscordEmote favouriteDiscordEmote) { try { using (ETHBotDBContext context = new ETHBotDBContext()) { context.FavouriteDiscordEmotes.Add(favouriteDiscordEmote); context.SaveChanges(); // TODO return the original object with the new id instead return(GetFavouriteEmote(favouriteDiscordEmote.DiscordUserId, favouriteDiscordEmote.Name)); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(null); } }
public async Task AddEmoteFavModalResponse(string discordEmoteId, CustomEmoteFav modal) { var emoteId = Convert.ToUInt64(discordEmoteId); string name = modal.CustomEmoteName.Replace("`", ""); // Dont allow people to escape the code blocks Context.Interaction.DeferAsync(); if (!name.All(Char.IsLetterOrDigit)) { await Context.Interaction.FollowupAsync("You are only allowed to use alphanimeric characters.", ephemeral : true); return; } var discordEmote = DatabaseManager.EmoteDatabaseManager.GetDiscordEmoteById(emoteId); if (discordEmote == null) { await Context.Interaction.FollowupAsync("This EmoteId does not exist in the database.", ephemeral : true); return; } var existingFavEmotes = DatabaseManager.EmoteDatabaseManager.GetFavouriteEmotes(Context.User.Id); if (existingFavEmotes == null) { return; // TODO error? } if (existingFavEmotes.Any(i => i.DiscordEmoteId == emoteId)) { await Context.Interaction.FollowupAsync("Emote is already in your favourites", ephemeral : true); return; } if (existingFavEmotes.Any(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase))) { await Context.Interaction.FollowupAsync("You reserved this name for some other emote already.", ephemeral : true); return; } // Clear to create a new fav mapping FavouriteDiscordEmote newFawEmote = new FavouriteDiscordEmote() { DiscordEmoteId = emoteId, DiscordUserId = Context.User.Id, Name = name }; var addedFavEmote = DatabaseManager.EmoteDatabaseManager.AddFavouriteEmote(newFawEmote); await Context.Interaction.RespondAsync($"``Successfully added {name} as a new favourite emote. You can call the emote with {Program.CurrentPrefix}{name}``"); await Context.Interaction.DeferAsync(); // Respond to the modal. //await RespondAsync(message, allowedMentions: mentions, ephemeral: true); }