diff --git a/.idea/.idea.TelegramRemindMe/.idea/contentModel.xml b/.idea/.idea.TelegramRemindMe/.idea/contentModel.xml
new file mode 100644
index 0000000..371a99c
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/.idea/contentModel.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TelegramRemindMe/.idea/indexLayout.xml b/.idea/.idea.TelegramRemindMe/.idea/indexLayout.xml
new file mode 100644
index 0000000..f1feadf
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/.idea/indexLayout.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TelegramRemindMe/.idea/modules.xml b/.idea/.idea.TelegramRemindMe/.idea/modules.xml
new file mode 100644
index 0000000..2326cb0
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TelegramRemindMe/.idea/vcs.xml b/.idea/.idea.TelegramRemindMe/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TelegramRemindMe/.idea/workspace.xml b/.idea/.idea.TelegramRemindMe/.idea/workspace.xml
new file mode 100644
index 0000000..bfd1d55
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/.idea/workspace.xml
@@ -0,0 +1,398 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ received action
+ successfi
+ list task
+ reminders
+ delete
+ success
+ task added succ
+ Set a task as completed
+ foreach
+ isworkingm
+ complete
+ invalid inp
+ == 0
+ set a task
+ 5000
+ doo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1518017570500
+
+
+ 1518017570500
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TelegramRemindMe/riderModule.iml b/.idea/.idea.TelegramRemindMe/riderModule.iml
new file mode 100644
index 0000000..1a4e0d9
--- /dev/null
+++ b/.idea/.idea.TelegramRemindMe/riderModule.iml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ChatEntry.cs b/ChatEntry.cs
new file mode 100644
index 0000000..49648b8
--- /dev/null
+++ b/ChatEntry.cs
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+
+namespace TelegramRemindMe
+{
+ public class ChatEntry
+ {
+ public long ChatId { get; }
+ public List _tasklist { get; set; } = new List();
+ public ChatStatusEnum status { get; set; } = ChatStatusEnum.Idle;
+ public bool IsWorkingMessage { get; set; } = false;
+ public int WorkingMsg { get; set; } = 0;
+ public bool AllTasksShown { get; set; } = false;
+
+ public ChatEntry(long chatId)
+ {
+ ChatId = chatId;
+ }
+ }
+
+ public enum ChatStatusEnum
+ {
+ Idle,
+ WaitingTaskTitle,
+ WaitingTaskComplete
+ }
+
+ public class TaskEntry
+ {
+ public bool Completed { get; set; } = false;
+ public string Title { get; }
+
+ public TaskEntry(string title)
+ {
+ Title = title;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
deleted file mode 100644
index 428b829..0000000
--- a/Program.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Telegram.Bot;
-using Telegram.Bot.Args;
-using Telegram.Bot.Types;
-using Telegram.Bot.Types.Enums;
-using Telegram.Bot.Types.InlineQueryResults;
-using Telegram.Bot.Types.ReplyMarkups;
-
-namespace TelegramRemindMe
-{
- public static class Program
- {
- //TODO: multiuser uwu
- private static bool isAddingTask = false;
- private static List tasks = new List();
- private static readonly TelegramBotClient Bot = new TelegramBotClient("511835815:AAHewCgiXep58wF6tDWIW133LhfqjCbb8c4");
-
- public static void Main(string[] args)
- {
- Bot.OnMessage += BotOnMessageReceived;
- Bot.OnMessageEdited += BotOnMessageReceived;
- Bot.OnCallbackQuery += BotOnCallbackQueryReceived;
- Bot.OnInlineQuery += BotOnInlineQueryReceived;
- Bot.OnInlineResultChosen += BotOnChosenInlineResultReceived;
- Bot.OnReceiveError += BotOnReceiveError;
-
- var me = Bot.GetMeAsync().Result;
-
- Console.Title = me.Username;
-
- Bot.StartReceiving();
- Console.WriteLine($"Start listening for @{me.Username}");
- Console.ReadLine();
- Bot.StopReceiving();
- }
-
- private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
- {
- var message = messageEventArgs.Message;
-
- if (message == null || message.Type != MessageType.Text) return;
-
- //IReplyMarkup keyboard = new ReplyKeyboardRemove();
-
- var actionKeyboard = new InlineKeyboardMarkup(new[]
- {
- new []
- {
- InlineKeyboardButton.WithCallbackData("Add a new task"),
- InlineKeyboardButton.WithCallbackData("List tasks"),
- },
- new []
- {
- InlineKeyboardButton.WithCallbackData("Add a new reminder"),
- InlineKeyboardButton.WithCallbackData("List reminders"),
- }
- });
-
- switch (message.Text.Split(' ').First())
- {
- case "/start":
- case "/do":
- case "/actions":
- case "/help":
- await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
- //await Task.Delay(500);
- await Bot.SendTextMessageAsync(
- message.Chat.Id,
- "What do you want me to do?",
- replyMarkup: actionKeyboard);
- break;
-
- case "/echo":
- await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.RecordVideoNote);
- await Task.Delay(500);
- await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadDocument);
- await Task.Delay(500);
- await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.RecordAudio);
- await Task.Delay(500);
- await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
- await Task.Delay(500);
- await Bot.SendTextMessageAsync(
- message.Chat.Id,
- "MEOW" + message.Text.Substring(5));
- break;
- default:
- if (isAddingTask)
- {
- tasks.Add(message.Text);
- await Bot.SendTextMessageAsync(
- message.Chat.Id,
- "Added. Anything else?",
- replyMarkup: actionKeyboard);
- }
-
- break;
- }
- }
-
- private static async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
- {
- Console.WriteLine($"Received action request: {callbackQueryEventArgs.CallbackQuery.Data}");
-
- switch (callbackQueryEventArgs.CallbackQuery.Data)
- {
- case "Add a new task":
- await Bot.EditMessageTextAsync(
- new ChatId(callbackQueryEventArgs.CallbackQuery.Message.Chat.Id),
- callbackQueryEventArgs.CallbackQuery.Message.MessageId,
- "Which task should I add?"
- );
- isAddingTask = true;
- break;
- case "List tasks":
- var sb = new StringBuilder();
- sb.AppendLine("Your tasks:");
- foreach (var task in tasks)
- {
- sb.Append("[ ] ");
- sb.AppendLine(task);
- }
-
- await Bot.EditMessageTextAsync(
- new ChatId(callbackQueryEventArgs.CallbackQuery.Message.Chat.Id),
- callbackQueryEventArgs.CallbackQuery.Message.MessageId,
- sb.ToString()
- );
- break;
- default:
- Console.WriteLine("Wat (Unknown callback action)");
- await Bot.AnswerCallbackQueryAsync(
- callbackQueryEventArgs.CallbackQuery.Id,
- "Wat");
- break;
- }
-
-
-
- //await Bot.AnswerCallbackQueryAsync(
- // callbackQueryEventArgs.CallbackQuery.Id,
- // $"Received {callbackQueryEventArgs.CallbackQuery.Data}");
- }
-
- private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
- {
- Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");
-
- InlineQueryResultBase[] results = {
- new InlineQueryResultLocation
- {
- Id = "1",
- Latitude = 40.7058316f, // displayed result
- Longitude = -74.2581888f,
- Title = "New York",
- InputMessageContent = new InputLocationMessageContent // message if result is selected
- {
- Latitude = 40.7058316f,
- Longitude = -74.2581888f,
- }
- },
-
- new InlineQueryResultLocation
- {
- Id = "2",
- Longitude = 52.507629f, // displayed result
- Latitude = 13.1449577f,
- Title = "Berlin",
- InputMessageContent = new InputLocationMessageContent // message if result is selected
- {
- Longitude = 52.507629f,
- Latitude = 13.1449577f
- }
- }
- };
-
- await Bot.AnswerInlineQueryAsync(
- inlineQueryEventArgs.InlineQuery.Id,
- results,
- isPersonal: true,
- cacheTime: 0);
- }
-
- private static void BotOnChosenInlineResultReceived(object sender, ChosenInlineResultEventArgs chosenInlineResultEventArgs)
- {
- Console.WriteLine($"Received inline result: {chosenInlineResultEventArgs.ChosenInlineResult.ResultId}");
- }
-
- private static void BotOnReceiveError(object sender, ReceiveErrorEventArgs receiveErrorEventArgs)
- {
- Console.WriteLine("Received error: {0} — {1}",
- receiveErrorEventArgs.ApiRequestException.ErrorCode,
- receiveErrorEventArgs.ApiRequestException.Message);
- }
- }
-}
diff --git a/ReminderBot.cs b/ReminderBot.cs
new file mode 100644
index 0000000..6fd672e
--- /dev/null
+++ b/ReminderBot.cs
@@ -0,0 +1,232 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Telegram.Bot;
+using Telegram.Bot.Args;
+using Telegram.Bot.Types;
+using Telegram.Bot.Types.Enums;
+using Telegram.Bot.Types.ReplyMarkups;
+
+namespace TelegramRemindMe
+{
+ public static class ReminderBot
+ {
+ private static readonly List Chats = new List();
+
+ private static readonly TelegramBotClient Bot =
+ new TelegramBotClient("511835815:AAHewCgiXep58wF6tDWIW133LhfqjCbb8c4");
+
+ public static void Main()
+ {
+ Bot.OnMessage += BotOnMessageReceived;
+ Bot.OnMessageEdited += BotOnMessageReceived;
+ Bot.OnCallbackQuery += BotOnCallbackQueryReceived;
+ //Bot.OnInlineQuery += BotOnInlineQueryReceived;
+ //Bot.OnInlineResultChosen += BotOnChosenInlineResultReceived;
+ Bot.OnReceiveError += BotOnReceiveError;
+
+ var me = Bot.GetMeAsync().Result;
+
+ Console.Title = me.Username;
+
+ Bot.StartReceiving();
+ Console.WriteLine($"Start listening for @{me.Username}");
+ Console.ReadLine();
+ Bot.StopReceiving();
+ }
+
+ private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
+ {
+ var message = messageEventArgs.Message;
+
+ if (message == null || message.Type != MessageType.Text) return;
+
+ if (Chats.Find(e => e.ChatId == messageEventArgs.Message.Chat.Id) == null)
+ Chats.Add(new ChatEntry(messageEventArgs.Message.Chat.Id));
+
+ var currentChat = Chats.Find(e => e.ChatId == messageEventArgs.Message.Chat.Id);
+
+ switch (currentChat.status)
+ {
+ case ChatStatusEnum.WaitingTaskTitle:
+ currentChat._tasklist.Add(new TaskEntry(message.Text));
+ await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
+ SendOverview(currentChat, "Task added successfully!");
+ return;
+ case ChatStatusEnum.WaitingTaskComplete:
+ try
+ {
+ var completedItem = int.Parse(message.Text);
+ if (completedItem < 1 || completedItem > currentChat._tasklist.Count(p => !p.Completed))
+ throw new ArgumentOutOfRangeException();
+
+ currentChat._tasklist.FindAll(p => !p.Completed)[completedItem - 1].Completed = true;
+ SendOverview(currentChat, "Task has been set as completed.");
+ }
+ catch (Exception e)
+ {
+ SendOverview(currentChat, $"🛑 Invalid input! [{e.Message}]");
+ }
+
+ return;
+ case ChatStatusEnum.Idle:
+ break;
+ }
+
+ switch (message.Text.Split(' ').First())
+ {
+ default:
+ SendOverview(currentChat);
+ break;
+
+ case "/echo":
+ await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.RecordVideoNote);
+ await Task.Delay(500);
+ await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadDocument);
+ await Task.Delay(500);
+ await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.RecordAudio);
+ await Task.Delay(500);
+ await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
+ await Task.Delay(500);
+ await Bot.SendTextMessageAsync(
+ message.Chat.Id,
+ "MEOW, you woke me up!" + message.Text.Substring(5));
+ break;
+ }
+ }
+
+ private static async void BotOnCallbackQueryReceived(object sender,
+ CallbackQueryEventArgs callbackQueryEventArgs)
+ {
+ Console.WriteLine(
+ $"Received action request from @{callbackQueryEventArgs.CallbackQuery.Message.Chat.Username}: {callbackQueryEventArgs.CallbackQuery.Data}");
+
+ if (Chats.Find(e => e.ChatId == callbackQueryEventArgs.CallbackQuery.Message.Chat.Id) == null)
+ Chats.Add(new ChatEntry(callbackQueryEventArgs.CallbackQuery.Message.Chat.Id));
+
+ var currentChat = Chats.Find(e => e.ChatId == callbackQueryEventArgs.CallbackQuery.Message.Chat.Id);
+
+ switch (callbackQueryEventArgs.CallbackQuery.Data)
+ {
+ case "Add a new task":
+ currentChat.IsWorkingMessage = true;
+ currentChat.WorkingMsg = Bot.EditMessageTextAsync(
+ new ChatId(currentChat.ChatId), callbackQueryEventArgs.CallbackQuery.Message.MessageId,
+ "How should your new task be called?"
+ ).Result.MessageId;
+ currentChat.status = ChatStatusEnum.WaitingTaskTitle;
+ break;
+ case "Set a task as completed":
+ var sb = new StringBuilder();
+ var i = 0;
+ foreach (var entry in currentChat._tasklist.Where(p => !p.Completed))
+ {
+ sb.AppendLine($"{++i}) {entry.Title}");
+ }
+
+ sb.AppendLine();
+ sb.AppendLine("Send me the number of the task you want to complete.");
+
+ currentChat.IsWorkingMessage = true;
+ currentChat.WorkingMsg =
+ Bot.EditMessageTextAsync(currentChat.ChatId,
+ callbackQueryEventArgs.CallbackQuery.Message.MessageId, sb.ToString()).Result.MessageId;
+ currentChat.status = ChatStatusEnum.WaitingTaskComplete;
+ break;
+ case "Show all tasks":
+ currentChat.AllTasksShown = true;
+ currentChat.IsWorkingMessage = true;
+ currentChat.WorkingMsg = callbackQueryEventArgs.CallbackQuery.Message.MessageId;
+ SendOverview(currentChat);
+ currentChat.WorkingMsg = callbackQueryEventArgs.CallbackQuery.Message.MessageId;Bot.AnswerCallbackQueryAsync(callbackQueryEventArgs.CallbackQuery.Id, "Showing all tasks");
+ break;
+ case "Hide completed tasks":
+ currentChat.AllTasksShown = false;
+ currentChat.IsWorkingMessage = true;
+ currentChat.WorkingMsg = callbackQueryEventArgs.CallbackQuery.Message.MessageId;
+ SendOverview(currentChat);
+ await Bot.AnswerCallbackQueryAsync(callbackQueryEventArgs.CallbackQuery.Id, "Showing only uncompleted tasks");
+ break;
+ default:
+ Console.WriteLine("Wat (Unknown callback action)");
+ await Bot.AnswerCallbackQueryAsync(
+ callbackQueryEventArgs.CallbackQuery.Id,
+ "Wat");
+ break;
+ }
+ }
+
+ private static async void SendOverview(ChatEntry chat, string prefixLine = "")
+ {
+ var actionKeyboard = new InlineKeyboardMarkup(new[]
+ {
+ new[]
+ {
+ InlineKeyboardButton.WithCallbackData("Add a new task"),
+ InlineKeyboardButton.WithCallbackData("Set a task as completed"),
+ },
+ new[]
+ {
+ InlineKeyboardButton.WithCallbackData(chat.AllTasksShown ? "Hide completed tasks" : "Show all tasks")
+ }
+ });
+
+ await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing);
+
+ if (chat.IsWorkingMessage)
+ await Bot.DeleteMessageAsync(chat.ChatId, chat.WorkingMsg);
+
+ chat.IsWorkingMessage = false;
+ chat.status = ChatStatusEnum.Idle;
+
+ var sb = new StringBuilder();
+ sb.AppendLine("Your tasks:");
+
+ if (chat.AllTasksShown)
+ {
+ foreach (var task in chat._tasklist)
+ {
+ sb.Append(task.Completed ? "✅ " : "🔶 ");
+ sb.AppendLine(task.Title);
+ }
+ }
+ else
+ {
+ foreach (var task in chat._tasklist.Where(p => !p.Completed))
+ {
+ sb.Append("🔶 ");
+ sb.AppendLine(task.Title);
+ }
+ }
+
+ sb.AppendLine();
+ sb.AppendLine("What do you want me to do?");
+
+ if (prefixLine != "")
+ {
+ var msgid = Bot.SendTextMessageAsync(
+ chat.ChatId,
+ prefixLine)
+ .Result.MessageId;
+
+ await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing);
+ await Task.Delay(1500);
+ await Bot.EditMessageTextAsync(chat.ChatId, msgid, sb.ToString(), replyMarkup: actionKeyboard);
+ }
+ else
+ {
+ await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing);
+ await Bot.SendTextMessageAsync(chat.ChatId, sb.ToString(), replyMarkup: actionKeyboard);
+ }
+ }
+
+ private static void BotOnReceiveError(object sender, ReceiveErrorEventArgs receiveErrorEventArgs)
+ {
+ Console.WriteLine("Received error: {0} — {1}",
+ receiveErrorEventArgs.ApiRequestException.ErrorCode,
+ receiveErrorEventArgs.ApiRequestException.Message);
+ }
+ }
+}
\ No newline at end of file
diff --git a/TelegramRemindMe.csproj b/TelegramRemindMe.csproj
index 3a4a181..8e2a464 100644
--- a/TelegramRemindMe.csproj
+++ b/TelegramRemindMe.csproj
@@ -4,6 +4,7 @@
netcoreapp2.0
+
\ No newline at end of file