Exemple #1
0
        public void AddBoldSection(string header)
        {
            var sectionBlock = new SectionBlock("mrkdwn", $"*{header}*");
            var block        = new Block(type: "section", text: sectionBlock, elements: null, fields: null);

            AddBlock(block);
        }
        public static IList <Block> BuildOrderMessage(Order order)
        {
            var blocks = new List <Block>();
            /* Summary */
            var costSummary = new SectionBlock()
            {
                BlockId = "order_costs",
            };

            var payload = order.IsOpen
                ? new Markdown($":hourglass_flowing_sand: Order in progress by {order.Owner.FriendlyName}:\n")
                : new Markdown($":checkered_flag: Order complete by {order.Owner.FriendlyName}:\n");

            if (order.Costs != null)
            {
                foreach (var cost in order.Costs.Values.Where(x => x.Value > 0))
                {
                    payload.Text += $"{cost.MarkdownDescription}\n";
                }
            }

            if (order.SharedCost > 0)
            {
                payload.Text += $"> • shared: *{order.SharedCost}*\n";
            }

            payload.Text    += $"> ---\n> Total: *{order.GetTotalCost()}*";
            costSummary.Text = payload;

            blocks.Add(costSummary);
            blocks.Add(new DividerBlock());

            var context = new ContextBlock
            {
                BlockId  = "order_context",
                Elements = new List <IContextElement>()
            };

            if (order.IsOpen)
            {
                context.Elements.Add(new Markdown($"Available `/food ` commands: " +
                                                  $"`{CommandTexts.Eat} <value> [food]`, " +
                                                  $"`{CommandTexts.Shared} <value>`,  " +
                                                  $"`{CommandTexts.Finish}`, " +
                                                  $"`{CommandTexts.Cancel}`" +
                                                  $"."));
                if (!order.IsReadyForCompletion)
                {
                    context.Elements.Add(new PlainText("\nOrder needs 2+ participants to be completed."));
                }
            }
            else // order is closed
            {
                context.Elements.Add(new PlainText("This order may be reopened only until the next order is started."));
            }

            blocks.Add(context);

            return(blocks);
        }
Exemple #3
0
        /// <summary>
        /// 在布局页中,将呈现指定部分的内容
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public static MvcHtmlString RenderSection(this HtmlHelper helper, string sectionName)
        {
            var sectionList = SectionBlock.GetSectionList(sectionName);

            if (sectionList != null && sectionList.Count > 0)
            {
                return(MvcHtmlString.Create(string.Join(Environment.NewLine, sectionList.Select(s => s.ToString()))));
            }
            return(MvcHtmlString.Create(string.Empty));
        }
Exemple #4
0
        public override object Render(XElement element, RootBlock root)
        {
            var sectionBlock = new SectionBlock()
            {
                Text = new TextObject(element.Value)
            };

            root.Layouts.Add(sectionBlock);

            return(sectionBlock);
        }
Exemple #5
0
            public Message Build(Notification notification)
            {
                var message = BlocksMessage.Create(
                    ContextBlock.Create(
                        PlainTextContextElement.Create(notification.Header)
                        ),
                    SectionBlock.Create(
                        Markdown.Create($"*{notification.Title}*\n{notification.Content}")
                        ),
                    ActionsBlock.Create(
                        Button.Create("Open in browser", notification.Url)
                        )
                    );

                message.ChannelId = _userDictionaryManager.Find(notification, _target);
                return(message);
            }
        public static IList <Block> BuildBalanceMessage(BalanceBook balanceBook)
        {
            var blocks = new List <Block>();

            var balanceBlock = new SectionBlock()
            {
                BlockId = "balance_summary",
                Text    = new Markdown("")
            };

            foreach (var pair in balanceBook.Balances.Values
                     .Where(x => x.Balance != 0)
                     .OrderBy(x => x.Key))
            {
                var balanceStr = Math.Abs(pair.Balance).ToString("0.00", CultureInfo.InvariantCulture);
                balanceStr = pair.Balance > 0
                    ? $" :arrow_left: {balanceStr} :arrow_left: "
                    : $" :arrow_right: {balanceStr} :arrow_right: ";

                balanceBlock.Text.Text += $"> {pair.PartyA.ToSlackMention()}{balanceStr}{pair.PartyB.ToSlackMention()}\n";
            }

            var(biggestDebtor, biggestDebt) = balanceBook.FindBiggestDebtor();
            if (biggestDebtor != null)
            {
                balanceBlock.Text.Text += $"{biggestDebtor.ToSlackMention()} should host the next order (total: *{biggestDebt:F2}*)";
            }

            if (string.IsNullOrWhiteSpace(balanceBlock.Text.Text))
            {
                balanceBlock.Text = new PlainText("Everyone is even.");
            }

            blocks.Add(balanceBlock);

            return(blocks);
        }
Exemple #7
0
        public SlackMessageBuilder AddSection(string?text = null, IEnumerable <string>?fields = null, string?blockId = null)
        {
            var block = new SectionBlock();

            if (text != null)
            {
                block.text = new Text()
                {
                    text = text,
                    type = "mrkdwn"
                }
            }
            ;

            var fieldsList = fields?.ToList() ?? new List <string>();

            if (fieldsList?.Any() ?? false)
            {
                block.fields = fieldsList
                               .Select(x => new Text()
                {
                    text = x,
                    type = "mrkdwn"
                })
                               .ToArray();
            }

            if (!string.IsNullOrEmpty(blockId))
            {
                block.block_id = blockId;
            }

            _blocks.Add(block);

            return(this);
        }
 /// <summary>
 /// Renders a section that was created using Html.BeginSection()
 /// </summary>
 /// <param name="helper">HTML Helper</param>
 /// <param name="key">An identifier for the section</param>
 /// <returns></returns>
 public static MvcHtmlString RenderSection(this HtmlHelper helper, string key)
 {
     return(MvcHtmlString.Create(string.Join(Environment.NewLine, SectionBlock.GetSection(key).Select(s => s.ToString()))));
 }