diff --git a/telegram/Command.cs b/telegram/Command.cs index 9c374fa..9fc9419 100644 --- a/telegram/Command.cs +++ b/telegram/Command.cs @@ -34,6 +34,7 @@ namespace telegram new ClearCommand(), new CloseCommand(), new EditCommand(), + new ReplyCommand(), new HistoryCommand(), new OpenCommand(), new UnreadsCommand(), @@ -481,4 +482,43 @@ namespace telegram } } } + + public class ReplyCommand : Command + { + public ReplyCommand() : base("r", "", "replies to message", " ", -1) + { + } + + public override void Handler(List inputParams) + { + try + { + if (inputParams.Count < 2) + { + return; //TODO do something + } + + var history = GetHistory(currentChatId, 50); + var parsed = int.TryParse(inputParams[0], out var offset); + inputParams.RemoveAt(0); + history.Reverse(); + var message = inputParams.Aggregate((current, param) => current + " " + param).Trim(); + + if (!parsed || string.IsNullOrWhiteSpace(message) || history.Count < offset) + { + return; //TODO do something + } + + var replyMessage = history[offset - 1]; + + if (currentChatId == 0) return; //TODO do something + + SendMessage(message, currentChatId, replyMessage.Id); + } + catch + { + //TODO do something + } + } + } } \ No newline at end of file diff --git a/telegram/Util.cs b/telegram/Util.cs index c89025f..d17d61e 100644 --- a/telegram/Util.cs +++ b/telegram/Util.cs @@ -228,7 +228,7 @@ namespace telegram return pass; } - public static void SendMessage(string message, long chatId) + public static void SendMessage(string message, long chatId, long replyTo = 0) { if (string.IsNullOrWhiteSpace(message)) return; @@ -247,7 +247,8 @@ namespace telegram { Text = message } - } + }, + ReplyToMessageId = replyTo, }); currentUserRead = false; } diff --git a/telegram/tgcli.cs b/telegram/tgcli.cs index 7e2447c..cd74679 100644 --- a/telegram/tgcli.cs +++ b/telegram/tgcli.cs @@ -15,9 +15,7 @@ namespace telegram /* * TODO: * improve secret chat open: open by username, allow just one sec chat per userId - * commands: more shortcuts? * make commands & keybinds more consistent (maybe configurable?) - * reply to x messages ago * 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?)