This commit is contained in:
Laura Hausmann 2019-12-13 18:10:08 +01:00
parent d5bcd885dd
commit 493aa46ee4
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
3 changed files with 40 additions and 26 deletions

View file

@ -13,15 +13,17 @@ namespace telegram
public string Trigger;
public string Shortcut;
public string Description;
public string Syntax;
public int ParamCount;
public abstract void Handler(List<string> inputParams);
protected Command(string trigger, string shortcut, string description, int paramCount)
protected Command(string trigger, string shortcut, string description, string syntax, int paramCount)
{
Trigger = trigger;
Shortcut = shortcut;
Description = description;
ParamCount = paramCount;
Syntax = syntax;
}
}
@ -73,7 +75,7 @@ namespace telegram
public class OpenCommand : Command
{
public OpenCommand() : base("o", "^O", "opens a chat", -1)
public OpenCommand() : base("o", "^O", "opens a chat", "<query> ", -1)
{
}
@ -94,6 +96,9 @@ namespace telegram
}
currentChatId = chat.Id;
chat.Title = TruncateString(chat.Title, 20);
prefix = $"[{chat.Title}";
lock (@lock)
{
@ -141,7 +146,7 @@ namespace telegram
public class CloseSecretChatCommand : Command
{
public CloseSecretChatCommand() : base("cs", "", "closes a secret chat (permanently)", 0)
public CloseSecretChatCommand() : base("cs", "", "closes a secret chat (permanently)", "", 0)
{
}
@ -164,7 +169,7 @@ namespace telegram
public class NewSecretChatCommand : Command
{
public NewSecretChatCommand() : base("ns", "", "creates a new secret chat", -1)
public NewSecretChatCommand() : base("ns", "", "creates a new secret chat", "", -1)
{
}
@ -183,7 +188,7 @@ namespace telegram
public class OpenSecretCommand : Command
{
public OpenSecretCommand() : base("os", "", "opens a secret chat", 1)
public OpenSecretCommand() : base("os", "", "opens a secret chat", "", 1)
{
}
@ -211,6 +216,8 @@ namespace telegram
{
return; //TODO do something
}
chat.Title = TruncateString(chat.Title, 20);
prefix = $"[{Ansi.Red}sec {Ansi.ResetAll}{chat.Title}]";
lock (@lock)
@ -266,7 +273,7 @@ namespace telegram
public class CloseUnreadCommand : Command
{
public CloseUnreadCommand() : base("cu", "", "closes a chat, marking it as unread", 0)
public CloseUnreadCommand() : base("cu", "", "closes a chat, marking it as unread", "", 0)
{
}
@ -280,7 +287,7 @@ namespace telegram
public class CloseCommand : Command
{
public CloseCommand() : base("c", "^E", "closes a chat", 0)
public CloseCommand() : base("c", "^E", "closes a chat", "", 0)
{
}
@ -309,7 +316,7 @@ namespace telegram
public class HistoryCommand : Command
{
public HistoryCommand() : base("h", "", "shows chat history", -1)
public HistoryCommand() : base("h", "", "shows chat history", "[1-50; default = 5] ", -1)
{
}
@ -336,7 +343,7 @@ namespace telegram
public class ClearCommand : Command
{
public ClearCommand() : base("cl", "^L", "clears console", 0)
public ClearCommand() : base("cl", "^L", "clears console", "", 0)
{
}
@ -351,7 +358,7 @@ namespace telegram
public class UnreadsCommand : Command
{
public UnreadsCommand() : base("u", "^U", "displays unread chat", -1)
public UnreadsCommand() : base("u", "^U", "displays unread chat", "[all] ", -1)
{
}
@ -379,7 +386,7 @@ namespace telegram
public class ListSecretChatsCommand : Command
{
public ListSecretChatsCommand() : base("ls", "", "displays all open secret chats", 0)
public ListSecretChatsCommand() : base("ls", "", "displays all open secret chats", "", 0)
{
}
@ -399,7 +406,7 @@ namespace telegram
public class HelpCommand : Command
{
public HelpCommand() : base("help", "", "lists all commands", 0)
public HelpCommand() : base("help", "", "lists all commands", "", 0)
{
}
@ -412,12 +419,12 @@ namespace telegram
{
if (string.IsNullOrWhiteSpace(command.Shortcut))
{
messageQueue.Add($"{Ansi.Yellow}/{command.Trigger}: {command.Description}");
messageQueue.Add($"{Ansi.Yellow}/{command.Trigger} {command.Syntax}: {command.Description}");
return;
}
messageQueue.Add(
$"{Ansi.Yellow}/{command.Trigger} [{command.Shortcut}]: {command.Description}");
$"{Ansi.Yellow}/{command.Trigger} {command.Syntax}[{command.Shortcut}]: {command.Description}");
});
}
}
@ -425,7 +432,7 @@ namespace telegram
public class QuitCommand : Command
{
public QuitCommand() : base("q", "^D", "quits the program", 0)
public QuitCommand() : base("q", "^D", "quits the program", "", 0)
{
}
@ -437,7 +444,7 @@ namespace telegram
public class EditCommand : Command
{
public EditCommand() : base("e", "", "edits last message", -1)
public EditCommand() : base("e", "", "edits last message", "[message; if empty adds last message to input]", -1)
{
}

View file

@ -332,7 +332,7 @@ namespace telegram
}
}
public static object GetFormattedUsername(User sender)
public static string GetFormattedUsername(User sender)
{
var username = sender.Username;
if (string.IsNullOrWhiteSpace(username))
@ -378,6 +378,13 @@ namespace telegram
return output + $"{Ansi.ResetAll}]";
}
public static string TruncateString(string input, int maxLen)
{
if (maxLen < 2)
maxLen = 2;
return input.Length <= maxLen ? input : input.Substring(0, maxLen - 1) + "~";
}
public static readonly List<ConsoleKey> SpecialKeys = new List<ConsoleKey>
{
ConsoleKey.Backspace,

View file

@ -14,25 +14,22 @@ namespace telegram
{
/*
* TODO:
* commands: usage!
* improve secret chat open: open by username, allow just one sec chat per userId
* global search: add contacts.
* commands: more shortcuts?
* make commands & keybinds more consistent (maybe configurable?)
* reply to x messages ago
* cap length & truncate extremely long chat names!
* replace emoji on send & un-replace on edit, two-way dictionary!!
* replace more emojis on send (is there a lib for that)
* make typing newlines actually good (inputline as list?)
* waaay more error messages instead of just doing nothing
* make Util.getActualStringWidth better
* waaay more error messages instead of just doing nothing or crashing
* refactor everything
* add option to disable terminal bell
* command /s /search -> list matching chats, archived, muted indicator
* for commands with query, if query starting with @ only match where username matches *exactly*
* command /sg -> search globally, some way to add contacts?
* command /sc -> search in chat list & list matching chats, archived, muted indicator
* mute,unmute chats
* split with newline if received message enters next line
* fix issues when current_input message is longer than term width (only show as much as fits?)
* photo download & show externally
* photo & document download & show externally
* publish AUR package
* maybe cursor input nav (cmd+del, left/right, up for last inputs, etc)
*/
@ -390,12 +387,15 @@ namespace telegram
text = $"[unsupported {msg.Content.DataType}]";
var sender = GetUser(msg.SenderUserId);
var chat = GetChat(msg.ChatId);
var username = GetFormattedUsername(sender);
var username = TruncateString(GetFormattedUsername(sender), 10);
var time = FormatTime(msg.Date);
var isChannel = msg.IsChannelPost;
var isPrivate = chat.Type is Td.TdApi.ChatType.ChatTypePrivate || chat.Type is Td.TdApi.ChatType.ChatTypeSecret;
var isSecret = chat.Type is Td.TdApi.ChatType.ChatTypeSecret;
var isReply = msg.ReplyToMessageId != 0;
chat.Title = TruncateString(chat.Title, 20);
Td.TdApi.Message replyMessage;
var msgPrefix = $"{Ansi.Bold}{Ansi.Green}[{time}] {(isSecret ? $"{Ansi.Red}[sec] " : "")}{Ansi.Cyan}{chat.Title} " +