Beispiel #1
0
        private static void ShowAllChatIds(BotWrapper bot)
        {
            var chatIds = bot.GetChatIds();

            foreach (var id in chatIds)
            {
                Console.WriteLine(id);
            }
        }
Beispiel #2
0
        public static async Task Main()
        {
            TelegramBotClient botClient = new TelegramBotClient(BotSettings.ApiToken);
            var bot = new BotWrapper(botClient, @"C:\My Files\chatIds.txt");

            Console.WriteLine(_helpText);
            bool cont = true;

            do
            {
                Console.WriteLine("Please Enter command");
                string command = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(command))
                {
                    continue;
                }
                (BotCommand comm, string arg) = ParseCommand(command);

                switch (comm)
                {
                case BotCommand.send:
                    SendMessage(arg, bot);
                    break;

                case BotCommand.sendAll:
                    bot.SendMessageToAll(arg);
                    Console.WriteLine("Sent!");
                    break;

                case BotCommand.quit:
                    cont = false;
                    break;

                case BotCommand.showMessages:
                    ShowMessages(arg, bot);
                    break;

                case BotCommand.showCommands:
                    Console.WriteLine(_helpText);
                    break;

                case BotCommand.showAllChatIds:
                    ShowAllChatIds(bot);
                    break;

                case BotCommand.none:
                    Console.WriteLine($"Command {command} not found");
                    break;
                }
                ;
            }while (cont);
            Console.ReadLine();
        }
Beispiel #3
0
 private static void SendMessage(string arg, BotWrapper bot)
 {
     (long chatId, string msg) = ParseArgForSend(arg);
     if (chatId != -1)
     {
         bot.SendMessage(chatId, msg);
         Console.WriteLine("Sent!");
     }
     else
     {
         Console.WriteLine("Incorrect Arguments");
     }
 }
Beispiel #4
0
 private static void ShowMessages(string arg, BotWrapper bot)
 {
     if (long.TryParse(arg.Trim(), out var id))
     {
         var msgs = bot.GetMessages(id).Select(m => new
         {
             m.Text,
             m.Date,
             m.From.Username
         });
         foreach (var msg in msgs)
         {
             Console.WriteLine($"-------\nDate: {msg.Date} From: {msg.Username} \n {msg.Text}");
         }
     }
     else
     {
         Console.WriteLine("ChatId is not provided");
     }
 }