This commit is contained in:
Laura Hausmann 2023-01-23 17:52:01 +01:00
parent 028b838bee
commit d660339433
Signed by: zotan
GPG key ID: D044E84C5BE01605
3 changed files with 1843 additions and 1844 deletions

View file

@ -5,8 +5,9 @@ using TdLib;
using static tgcli.tgcli;
using static tgcli.Util;
namespace tgcli {
public abstract class Command {
namespace tgcli;
public abstract class Command {
public string trigger;
public string shortcut;
public string description;
@ -21,9 +22,9 @@ namespace tgcli {
this.paramCount = paramCount;
this.syntax = syntax;
}
}
}
public static class CommandManager {
public static class CommandManager {
public static readonly List<Command> Commands = new() {
new ClearCommand(),
new CloseCommand(),
@ -72,9 +73,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Invalid command syntax. Check /help for more information.");
}
}
}
}
public class OpenCommand : Command {
public class OpenCommand : Command {
public OpenCommand() : base("o", "^O", "opens a chat. queries chat list", "<query>", -1) { }
public override void Handler(List<string> inputParams) {
@ -137,9 +138,9 @@ namespace tgcli {
lastMessage = last;
currentUserRead = IsMessageRead(last.ChatId, last.Id);
}
}
}
public class NewChatCommand : Command {
public class NewChatCommand : Command {
public NewChatCommand() : base("n", "", "starts a new chat.", "<username>", 1) { }
public override void Handler(List<string> inputParams) {
@ -197,9 +198,9 @@ namespace tgcli {
lastMessage = last;
currentUserRead = IsMessageRead(last.ChatId, last.Id);
}
}
}
public class CloseSecretChatCommand : Command {
public class CloseSecretChatCommand : Command {
public CloseSecretChatCommand() : base("cs", "", "closes a secret chat (permanently)", "", 0) { }
public override void Handler(List<string> _) {
@ -213,9 +214,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] No secret chat selected, cannot continue.");
}
}
}
}
public class NewSecretChatCommand : Command {
public class NewSecretChatCommand : Command {
public NewSecretChatCommand() : base("ns", "", "creates a new secret chat.", "<username>", 1) { }
public override void Handler(List<string> inputParams) {
@ -236,9 +237,9 @@ namespace tgcli {
var chat = CreateSecretChat(userId);
CommandManager.HandleCommand("osd " + chat.Id);
}
}
}
public class OpenSecretDirectCommand : Command {
public class OpenSecretDirectCommand : Command {
public OpenSecretDirectCommand() : base("osd", "", "opens a secret chat by chat id", "<chat_id>", 1) { }
public override void Handler(List<string> inputParams) {
@ -312,9 +313,9 @@ namespace tgcli {
lastMessage = last;
currentUserRead = IsMessageRead(last.ChatId, last.Id);
}
}
}
public class OpenSecretCommand : Command {
public class OpenSecretCommand : Command {
public OpenSecretCommand() : base("os", "", "opens a secret chat. queries chat list.", "<query>", -1) { }
public override void Handler(List<string> inputParams) {
@ -395,9 +396,9 @@ namespace tgcli {
lastMessage = last;
currentUserRead = IsMessageRead(last.ChatId, last.Id);
}
}
}
public class CloseUnreadCommand : Command {
public class CloseUnreadCommand : Command {
public CloseUnreadCommand() : base("cu", "", "closes a chat, marking it as unread", "", 0) { }
public override void Handler(List<string> inputParams) {
@ -410,9 +411,9 @@ namespace tgcli {
MarkUnread(currentChatId);
CommandManager.HandleCommand("c");
}
}
}
public class CloseCommand : Command {
public class CloseCommand : Command {
public CloseCommand() : base("c", "^D", "closes a chat", "", 0) { }
public override void Handler(List<string> inputParams) {
@ -439,9 +440,9 @@ namespace tgcli {
missedMessages.Clear();
}
}
}
}
public class HistoryCommand : Command {
public class HistoryCommand : Command {
public HistoryCommand() : base("h", "", "shows chat history. default limit is 5", "[1-50]", -1) { }
public override void Handler(List<string> inputParams) {
@ -473,9 +474,9 @@ namespace tgcli {
AddMessageToQueue(msg);
}
}
}
}
public class ClearCommand : Command {
public class ClearCommand : Command {
public ClearCommand() : base("cl", "^L", "clears console", "", 0) { }
public override void Handler(List<string> inputParams) {
@ -483,9 +484,9 @@ namespace tgcli {
Console.Clear();
}
}
}
}
public class UnreadsCommand : Command {
public class UnreadsCommand : Command {
public UnreadsCommand() : base("u", "", "displays unread chat", "[all]", -1) { }
public override void Handler(List<string> inputParams) {
@ -505,9 +506,9 @@ namespace tgcli {
});
}
}
}
}
public class ListChatsCommand : Command {
public class ListChatsCommand : Command {
public ListChatsCommand() : base("lc", "", "lists all chats, optionally filtered", "[query]", -1) { }
public override void Handler(List<string> inputParams) {
@ -530,9 +531,9 @@ namespace tgcli {
});
}
}
}
}
public class SearchUserCommand : Command {
public class SearchUserCommand : Command {
public SearchUserCommand() : base("s", "", "searches for users globally", "<query>", -1) { }
public override void Handler(List<string> inputParams) {
@ -558,9 +559,9 @@ namespace tgcli {
});
}
}
}
}
public class AddContactCommand : Command {
public class AddContactCommand : Command {
public AddContactCommand() : base("ac", "", "adds user to contact list", "<username>", 1) { }
public override void Handler(List<string> inputParams) {
@ -580,9 +581,9 @@ namespace tgcli {
}
*/
}
}
}
public class ListSecretChatsCommand : Command {
public class ListSecretChatsCommand : Command {
public ListSecretChatsCommand() : base("ls", "", "displays all open secret chats", "", 0) { }
public override void Handler(List<string> inputParams) {
@ -594,9 +595,9 @@ namespace tgcli {
});
}
}
}
}
public class HelpCommand : Command {
public class HelpCommand : Command {
public HelpCommand() : base("help", "", "lists all commands", "", 0) { }
public override void Handler(List<string> inputParams) {
@ -614,17 +615,17 @@ namespace tgcli {
});
}
}
}
}
public class QuitCommand : Command {
public class QuitCommand : Command {
public QuitCommand() : base("q", "^D", "quits the program", "", 0) { }
public override void Handler(List<string> inputParams) {
quitting = true;
}
}
}
public class EditCommand : Command {
public class EditCommand : Command {
public EditCommand() : base("e", "", "edits last message. param empty adds last message to inputline", "[message]", -1) { }
public override void Handler(List<string> inputParams) {
@ -669,9 +670,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Unknown error editing message.");
}
}
}
}
public class MeCommand : Command {
public class MeCommand : Command {
public MeCommand() : base("me", "", "sends an action message", "<message>", -1) { }
public override void Handler(List<string> inputParams) {
@ -706,9 +707,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Unknown error sending action messsage.");
}
}
}
}
public class ReplyCommand : Command {
public class ReplyCommand : Command {
public ReplyCommand() : base("r", "", "matches message in history to reply to", "<message query>", -1) { }
public override void Handler(List<string> inputParams) {
@ -745,9 +746,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Unknown error searching for message.");
}
}
}
}
public class ReplyOffsetCommand : Command {
public class ReplyOffsetCommand : Command {
public ReplyOffsetCommand() : base("ro", "", "replies to message", "<offset> <message>", -1) { }
public override void Handler(List<string> inputParams) {
@ -785,9 +786,9 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Unknown error sending message.");
}
}
}
}
public class ReplyDirectCommand : Command {
public class ReplyDirectCommand : Command {
public ReplyDirectCommand() : base("rd", "", "replies to message by id", "<id> <message>", -1) { }
public override void Handler(List<string> inputParams) {
@ -821,13 +822,12 @@ namespace tgcli {
messageQueue.Add($"{Ansi.Red}[tgcli] Unknown error sending message.");
}
}
}
}
public class LogoutCommand : Command {
public class LogoutCommand : Command {
public LogoutCommand() : base("logout", "", "log out this session (destroys all local data)", "", 0) { }
public override void Handler(List<string> inputParams) {
LogOut();
}
}
}

View file

@ -6,8 +6,9 @@ using NeoSmart.Unicode;
using static TdLib.TdApi;
using static tgcli.tgcli;
namespace tgcli {
public static class Util {
namespace tgcli;
public static class Util {
public static class Ansi {
public const string ResetAll = "\x1B[0m";
public const string Red = "\x1b[31m";
@ -62,8 +63,7 @@ namespace tgcli {
}
}
public static List<Message> GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0, bool isSecret = false,
bool skipTotal = false) {
public static List<Message> GetHistory(long chatId, int limit = 5, long fromMessageId = 0, int offset = 0, bool isSecret = false, bool skipTotal = false) {
var history = new List<Message>();
var total = GetTotalMessages(chatId);
var chat = GetChat(chatId);
@ -560,5 +560,4 @@ namespace tgcli {
ConsoleKey.Pa1,
ConsoleKey.OemClear
};
}
}

View file

@ -11,8 +11,9 @@ using static tgcli.CommandManager;
// ReSharper disable SwitchStatementMissingSomeEnumCasesNoDefault
namespace tgcli {
/*
namespace tgcli;
/*
* TODO:
* fix newlines with input nav...
* unreads are unreliable in secret chats!
@ -23,8 +24,8 @@ namespace tgcli {
* When TDLib 1.6 is released: implement contacts
*/
// ReSharper disable once InconsistentNaming
public static class tgcli {
// ReSharper disable once InconsistentNaming
public static class tgcli {
public static volatile Td.TdClient client = new();
public static string dbdir = "";
public static volatile bool authorized;
@ -610,5 +611,4 @@ namespace tgcli {
messageQueue.Add(formattedMessage);
ScreenUpdate();
}
}
}