Esempio n. 1
0
        public static async Task <FormattedEmbedBuilder> BuildAsync(string name)
        {
            name = name.Trim();
            ItemDataBuilder       itemBuilder = new ItemDataBuilder();
            FormattedEmbedBuilder message     = new FormattedEmbedBuilder();

            try
            {
                List <ItemDto> matches = await itemBuilder.GetMatchingItemsAsync(name);

                if (matches.Count == 0)
                {
                    message
                    .AppendTitle($"{XayahReaction.Error} This didn't work")
                    .AppendDescription($"Oops! Your bad. I couldn't find an item (fully or partially) named `{name}`.");
                }
                else if (matches.Count > 1)
                {
                    message
                    .AppendTitle($"{XayahReaction.Warning} This didn't went as expected")
                    .AppendDescription($"I found more than one item (fully or partially) named `{name}`.");
                    foreach (ItemDto item in matches)
                    {
                        message.AppendDescription(Environment.NewLine + item.Name);
                    }
                }
                else
                {
                    ItemDto item = matches.First();
                    await itemBuilder.AppendData(item, message);
                }
            }
            catch (NoApiResultException)
            {
                message = new FormattedEmbedBuilder()
                          .AppendTitle($"{XayahReaction.Error} This didn't work")
                          .AppendDescription("Apparently some random API refuses cooperation. Have some patience while I convince them again...");
            }
            return(message);
        }
Esempio n. 2
0
        private async Task ProcessItem(string name)
        {
            try
            {
                if (this.IsDisabled())
                {
                    this.NotifyDisabledCommand();
                    return;
                }
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                FormattedEmbedBuilder message = await ItemDataBuilder.BuildAsync(name);

                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }