64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using System.Linq;
|
|
using static tgcli.core.Util;
|
|
|
|
namespace tgcli.core
|
|
{
|
|
public class Command
|
|
{
|
|
public static void ParseCommand(string command)
|
|
{
|
|
var split = command.Split(" ");
|
|
if (split[0].Equals("open") || split[0].Equals("o"))
|
|
{
|
|
if (split.Length != 2)
|
|
return;
|
|
var chatId = searchChatId(split[1]);
|
|
if (chatId == 0)
|
|
return;
|
|
var chat = getChat(chatId);
|
|
Program.currentChatId = chat.Id;
|
|
Program.prefix = $"[{chat.Title}]";
|
|
markRead(chat.Id, getHistory(chat.Id).First().Id);
|
|
}
|
|
else if (split[0].Equals("close") || split[0].Equals("c"))
|
|
{
|
|
if (split.Length != 1)
|
|
return;
|
|
Program.currentChatId = 0;
|
|
Program.prefix = "[tgcli]";
|
|
|
|
|
|
lock (Program._lock)
|
|
{
|
|
var count = Program.missedMessages.Count;
|
|
if (count == 0)
|
|
return;
|
|
Program.messageQueue.Add($"{Ansi.Bold}{Ansi.Yellow}" +
|
|
$"[tgcli] You have {count} missed message" +
|
|
$"{(count == 1 ? "." : "s.")}");
|
|
Program.messageQueue.AddRange(Program.missedMessages);
|
|
Program.missedMessages.Clear();
|
|
}
|
|
}
|
|
else if (split[0].Equals("history") || split[0].Equals("h"))
|
|
{
|
|
if (split.Length != 1 && split.Length != 2 || Program.currentChatId == 0)
|
|
{
|
|
lock(Program._lock)
|
|
Program.messageQueue.Add($"{Ansi.Bold}{Ansi.Red}[tgcli] " +
|
|
$"No chat selected. Select a chat with /open <query>");
|
|
return;
|
|
}
|
|
var history = split.Length > 1 && int.TryParse(split[1], out var limit)
|
|
? getHistory(Program.currentChatId, limit)
|
|
: getHistory(Program.currentChatId);
|
|
history.Reverse();
|
|
|
|
foreach (var msg in history)
|
|
{
|
|
Program.AddMessageToQueue(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |