add reply command

This commit is contained in:
Laura Hausmann 2019-12-13 19:42:56 +01:00
parent 3d6d6f62d9
commit 681270d95d
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
3 changed files with 43 additions and 4 deletions

View file

@ -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", "<offset> <message>", -1)
{
}
public override void Handler(List<string> 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
}
}
}
}

View file

@ -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;
}

View file

@ -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?)