add reply command
This commit is contained in:
parent
3d6d6f62d9
commit
681270d95d
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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?)
|
||||
|
|
Loading…
Reference in a new issue