public async Task IdentifyPasta(EventContext e) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); if (string.IsNullOrWhiteSpace(e.arguments)) { await Utils.ErrorEmbed(locale, e.GetResource("infopasta_error_no_arg")) .SendToChannel(e.Channel.Id); return; } using (var context = MikiContext.CreateNoCache()) { context.Set <GlobalPasta>().AsNoTracking(); try { GlobalPasta pasta = await context.Pastas.FindAsync(e.arguments); if (pasta == null) { await Utils.ErrorEmbed(locale, e.GetResource("miki_module_pasta_error_null")).SendToChannel(e.Channel); return; } User creator = await context.Users.FindAsync(pasta.creator_id); IDiscordEmbed b = Utils.Embed; b.SetAuthor(pasta.Id.ToUpper(), "", ""); b.Color = new IA.SDK.Color(47, 208, 192); if (creator != null) { b.AddInlineField(e.GetResource("miki_module_pasta_identify_created_by"), $"{ creator.Name} [{creator.Id}]"); } b.AddInlineField(e.GetResource("miki_module_pasta_identify_date_created"), pasta.date_created.ToShortDateString()); b.AddInlineField(e.GetResource("miki_module_pasta_identify_times_used"), pasta.TimesUsed.ToString()); VoteCount v = pasta.GetVotes(context); b.AddInlineField(e.GetResource("infopasta_rating"), $"⬆️ { v.Upvotes} ⬇️ {v.Downvotes}"); await b.SendToChannel(e.Channel); } catch (Exception ex) { Log.ErrorAt("IdentifyPasta", ex.Message); } } }
public async Task IdentifyPasta(EventContext e) { Locale locale = Locale.GetEntity(e.Guild.Id.ToDbLong()); if (string.IsNullOrWhiteSpace(e.arguments)) { await Utils.ErrorEmbed(locale, "Please state which pasta you'd like to identify.") .SendToChannel(e.Channel.Id); return; } using (var context = MikiContext.CreateNoCache()) { context.Set <GlobalPasta>().AsNoTracking(); try { GlobalPasta pasta = await context.Pastas.FindAsync(e.arguments); if (pasta == null) { await e.Channel.SendMessage(Utils.ErrorEmbed(locale, "This pasta doesn't exist!")); return; } User creator = await context.Users.FindAsync(pasta.creator_id); EmbedBuilder b = new EmbedBuilder(); b.Author = new EmbedAuthorBuilder(); b.Author.Name = pasta.Id.ToUpper(); b.Color = new Discord.Color(47, 208, 192); if (creator != null) { b.AddField(x => { x.Name = "Created by"; x.Value = $"{creator.Name} [{creator.Id}]"; x.IsInline = true; }); } b.AddField(x => { x.Name = "Date Created"; x.Value = pasta.date_created.ToShortDateString(); x.IsInline = true; }); b.AddInlineField("Times Used", pasta.TimesUsed); b.AddField(x => { x.Name = "Rating"; VoteCount v = pasta.GetVotes(context); x.Value = $"⬆️ {v.Upvotes} ⬇️ {v.Downvotes}"; x.IsInline = true; }); await e.Channel.SendMessage(new RuntimeEmbed(b)); } catch (Exception ex) { Log.ErrorAt("IdentifyPasta", ex.Message); } } }