Пример #1
0
        public override async Task Render(MessageResult message)
        {
            if (this.MessageId == null)
            {
                var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled).Select(a => new ButtonBase(a.Title, a.ID.ToString()));

                ButtonForm bf = new ButtonForm();
                bf.AddSplitted(buttons, 1);
                await this.Device.Send("Deine Optionen", bf);

                return;
            }
        }
Пример #2
0
        public override async Task Render(MessageResult result)
        {
            ButtonForm bf = new ButtonForm();

            switch (this.PickerMode)
            {
            case eMonthPickerMode.day:

                var month = this.VisibleMonth;

                string[] dayNamesNormal  = this.Culture.DateTimeFormat.ShortestDayNames;
                string[] dayNamesShifted = Shift(dayNamesNormal, (int)this.FirstDayOfWeek);

                bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase(this.Culture.DateTimeFormat.MonthNames[month.Month - 1] + " " + month.Year.ToString(), "monthtitle"), new ButtonBase(">>", "next"));

                bf.AddButtonRow(dayNamesShifted.Select(a => new ButtonBase(a, a)).ToList());

                //First Day of month
                var firstDay = new DateTime(month.Year, month.Month, 1);

                //Last Day of month
                var lastDay = firstDay.LastDayOfMonth();

                //Start of Week where first day of month is (left border)
                var start = firstDay.StartOfWeek(this.FirstDayOfWeek);

                //End of week where last day of month is (right border)
                var end = lastDay.EndOfWeek(this.FirstDayOfWeek);

                for (int i = 0; i <= ((end - start).Days / 7); i++)
                {
                    var lst = new List <ButtonBase>();
                    for (int id = 0; id < 7; id++)
                    {
                        var d = start.AddDays((i * 7) + id);
                        if (d <firstDay | d> lastDay)
                        {
                            lst.Add(new ButtonBase("-", "m-" + d.Day.ToString()));
                            continue;
                        }

                        var day = d.Day.ToString();

                        if (d == DateTime.Today)
                        {
                            day = "(" + day + ")";
                        }

                        lst.Add(new ButtonBase((this.SelectedDate == d ? "[" + day + "]" : day), "d-" + d.Day.ToString()));
                    }
                    bf.AddButtonRow(lst);
                }

                break;

            case eMonthPickerMode.month:

                bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase(this.VisibleMonth.Year.ToString("0000"), "yeartitle"), new ButtonBase(">>", "next"));

                var months = this.Culture.DateTimeFormat.MonthNames;

                var buttons = months.Select((a, b) => new ButtonBase((b == this.SelectedDate.Month - 1 && this.SelectedDate.Year == this.VisibleMonth.Year ? "[ " + a + " ]" : a), "m-" + (b + 1).ToString()));

                bf.AddSplitted(buttons, 2);

                break;

            case eMonthPickerMode.year:

                bf.AddButtonRow(new ButtonBase("<<", "prev"), new ButtonBase("Year", "yearstitle"), new ButtonBase(">>", "next"));

                var starti = Math.Floor(this.VisibleMonth.Year / 10f) * 10;

                for (int i = 0; i < 10; i++)
                {
                    var m = starti + (i * 2);
                    bf.AddButtonRow(new ButtonBase((this.SelectedDate.Year == m ? "[ " + m.ToString() + " ]" : m.ToString()), "y-" + m.ToString()), new ButtonBase((this.SelectedDate.Year == (m + 1) ? "[ " + (m + 1).ToString() + " ]" : (m + 1).ToString()), "y-" + (m + 1).ToString()));
                }

                break;
            }


            if (this.MessageId != null)
            {
                var m = await this.Device.Edit(this.MessageId.Value, this.Title, bf);
            }
            else
            {
                var m = await this.Device.Send(this.Title, bf);

                this.MessageId = m.MessageId;
            }
        }