private void AddToRepostQueue(Telegram.Bot.Types.Message msg) { using (var context = BotDbContextFactory.Create(Settings.Instance().connectionString)) { var shitpost = new Shitpost(msg); ShitpostQueue.posts.Add(shitpost); context.Add(shitpost); context.SaveChanges(); } Bot.SendTextMessageAsync(msg.Chat, "Message queued"); if (!timer.Enabled) { timer.Enabled = true; } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { var shitpost = ShitpostQueue.posts[0]; Bot.ForwardMessageAsync(Settings.Instance().chatId, shitpost.senderId, shitpost.messageId); using (var context = BotDbContextFactory.Create(Settings.Instance().connectionString)) { context.Shitposts.Remove(shitpost); context.SaveChanges(); } ShitpostQueue.posts.RemoveAt(0); if (ShitpostQueue.posts.Count == 0) { timer.Enabled = false; } }
static void Main(string[] args) { try { var settings = Settings.Instance(); using (var context = BotDbContextFactory.Create(Settings.Instance().connectionString)) { var listFromDb = (from all in context.Shitposts select all).ToList(); ShitpostQueue.posts = listFromDb; } var api = new TelegramAPIClass(settings.token); } catch (Exception ex) { GarbageFunctionality.Log("Shutting down"); } }