Esempio n. 1
0
        public static void Events(Message m, string[] args)
        {
            using (var db = new DFW.Furs.Database.DFWDbContext())
            {
                var nEvent  = db.EventDescriptions.Include("Events").FirstOrDefault();
                var caption = BuildCaption(nEvent);

                var buttons = new[]
                {
                    new InlineKeyboardButton {
                        CallbackData = $"events|{nEvent.Id}|prev", Text = "Previous"
                    },
                    new InlineKeyboardButton {
                        CallbackData = $"events|{nEvent.Id}|next", Text = "Next"
                    }
                };

                var menu = new InlineKeyboardMarkup(buttons);


                if (nEvent.Photo != null)
                {
                    using (var fs = new FileStream(Environment.CurrentDirectory + "/wwwroot/images/events/" + nEvent.Photo, FileMode.Open))
                    {
                        var file   = new InputOnlineFile(fs);
                        var result = Bot.Client.SendPhotoAsync(m.Chat.Id, file, caption, replyMarkup: menu).Result;
                    }
                }
                else
                {
                    Bot.Send(caption, m.Chat.Id, customMenu: menu);
                }
            }
        }
Esempio n. 2
0
 public static void NextEvent(Message m, string[] args)
 {
     using (var db = new DFW.Furs.Database.DFWDbContext())
     {
         var next    = db.Events.Include("Description").Where(x => x.TimeStamp > DateTime.Now).OrderBy(x => x.TimeStamp).First();
         var nEvent  = next.Description;
         var caption = BuildCaption(nEvent);
         if (nEvent.Photo != null)
         {
             using (var fs = new FileStream(Environment.CurrentDirectory + "/wwwroot/images/events/" + nEvent.Photo, FileMode.Open))
             {
                 var file   = new InputOnlineFile(fs);
                 var result = Bot.Client.SendPhotoAsync(m.Chat.Id, file, caption).Result;
             }
         }
         else
         {
             Bot.Send(caption, m.Chat.Id);
         }
     }
 }
Esempio n. 3
0
        public static void SwitchEvent(CallbackQuery query)
        {
            using (var db = new DFW.Furs.Database.DFWDbContext())
            {
                var args = query.Data.Split('|');
                var id   = int.Parse(args[1]);

                var ids = db.EventDescriptions.Select(x => x.Id);
                EventDescription nEvent = null;
                while (nEvent == null)
                {
                    if (args[2] == "next")
                    {
                        id++;
                        if (db.EventDescriptions.All(x => x.Id < id))
                        {
                            id = 1;
                        }
                    }
                    else
                    {
                        id--;
                        if (db.EventDescriptions.All(x => x.Id > id))
                        {
                            id = db.EventDescriptions.OrderByDescending(x => x.Id).FirstOrDefault().Id;
                        }
                    }



                    nEvent = db.EventDescriptions.Include("Events").FirstOrDefault(x => x.Id == id);
                }
                var caption = Commands.Commands.BuildCaption(nEvent);

                var buttons = new[]
                {
                    new InlineKeyboardButton {
                        CallbackData = $"events|{nEvent.Id}|prev", Text = "Previous"
                    },
                    new InlineKeyboardButton {
                        CallbackData = $"events|{nEvent.Id}|next", Text = "Next"
                    }
                };

                var menu = new InlineKeyboardMarkup(buttons);

                Bot.Client.DeleteMessageAsync(query.Message.Chat.Id, query.Message.MessageId);
                if (nEvent.Photo != null)
                {
                    using (var fs = new FileStream(Environment.CurrentDirectory + "/wwwroot/images/events/" + nEvent.Photo, FileMode.Open))
                    {
                        var file   = new InputOnlineFile(fs);
                        var result = Bot.Client.SendPhotoAsync(query.Message.Chat.Id, file, caption, replyMarkup: menu, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html).Result;
                    }
                }
                else
                {
                    Bot.Send(caption, query.Message.Chat.Id, customMenu: menu, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html);
                }
            }
        }