Add /me command
This commit is contained in:
parent
35ec0d3f31
commit
6382f10dae
|
@ -29,6 +29,7 @@ namespace tgcli {
|
||||||
new CloseCommand(),
|
new CloseCommand(),
|
||||||
new EditCommand(),
|
new EditCommand(),
|
||||||
new ReplyCommand(),
|
new ReplyCommand(),
|
||||||
|
new MeCommand(),
|
||||||
new ReplyOffsetCommand(),
|
new ReplyOffsetCommand(),
|
||||||
new ReplyDirectCommand(),
|
new ReplyDirectCommand(),
|
||||||
new HistoryCommand(),
|
new HistoryCommand(),
|
||||||
|
@ -226,7 +227,7 @@ namespace tgcli {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetSecretChats().Count(p => ((TdApi.ChatType.ChatTypeSecret) p.Type).UserId == userId) > 0) {
|
if (GetSecretChats().Count(p => ((TdApi.ChatType.ChatTypeSecret)p.Type).UserId == userId) > 0) {
|
||||||
lock (@lock)
|
lock (@lock)
|
||||||
messageQueue.Add($"{Ansi.Red}[tgcli] You already have a secret chat with the specified user.");
|
messageQueue.Add($"{Ansi.Red}[tgcli] You already have a secret chat with the specified user.");
|
||||||
return;
|
return;
|
||||||
|
@ -331,7 +332,7 @@ namespace tgcli {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var chat = GetSecretChats().Find(p => ((TdApi.ChatType.ChatTypeSecret) p.Type).UserId == userId);
|
var chat = GetSecretChats().Find(p => ((TdApi.ChatType.ChatTypeSecret)p.Type).UserId == userId);
|
||||||
if (chat == null) {
|
if (chat == null) {
|
||||||
lock (@lock)
|
lock (@lock)
|
||||||
messageQueue.Add($"{Ansi.Red}[tgcli] No matching secret chat found.");
|
messageQueue.Add($"{Ansi.Red}[tgcli] No matching secret chat found.");
|
||||||
|
@ -550,7 +551,7 @@ namespace tgcli {
|
||||||
messageQueue.Add($"{Ansi.Yellow}[tgcli] Listing {chats.Count} chats.");
|
messageQueue.Add($"{Ansi.Yellow}[tgcli] Listing {chats.Count} chats.");
|
||||||
chats.ForEach(chat => {
|
chats.ForEach(chat => {
|
||||||
string line;
|
string line;
|
||||||
var type = (TdApi.ChatType.ChatTypePrivate) chat.Type;
|
var type = (TdApi.ChatType.ChatTypePrivate)chat.Type;
|
||||||
var user = GetUser(type.UserId);
|
var user = GetUser(type.UserId);
|
||||||
line = $"{Ansi.Bold}{Ansi.Yellow}@{user.Usernames.ActiveUsernames.First()} {Ansi.Magenta}{chat.Title}";
|
line = $"{Ansi.Bold}{Ansi.Yellow}@{user.Usernames.ActiveUsernames.First()} {Ansi.Magenta}{chat.Title}";
|
||||||
messageQueue.Add(line);
|
messageQueue.Add(line);
|
||||||
|
@ -589,7 +590,7 @@ namespace tgcli {
|
||||||
lock (@lock) {
|
lock (@lock) {
|
||||||
messageQueue.Add($"{Ansi.Yellow}[tgcli] Listing {secretChats.Count} secret chats:");
|
messageQueue.Add($"{Ansi.Yellow}[tgcli] Listing {secretChats.Count} secret chats:");
|
||||||
secretChats.ForEach(chat => {
|
secretChats.ForEach(chat => {
|
||||||
messageQueue.Add($"{Ansi.Bold}{Ansi.Red}[sec] {chat.Title} -> {chat.Id} ({GetSecretChat(((TdApi.ChatType.ChatTypeSecret) chat.Type).SecretChatId).State.DataType})");
|
messageQueue.Add($"{Ansi.Bold}{Ansi.Red}[sec] {chat.Title} -> {chat.Id} ({GetSecretChat(((TdApi.ChatType.ChatTypeSecret)chat.Type).SecretChatId).State.DataType})");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,7 +630,7 @@ namespace tgcli {
|
||||||
public override void Handler(List<string> inputParams) {
|
public override void Handler(List<string> inputParams) {
|
||||||
try {
|
try {
|
||||||
if (inputParams.Count == 0) {
|
if (inputParams.Count == 0) {
|
||||||
SetInputLine("/e " + ((TdApi.MessageContent.MessageText) lastMessage?.Content)?.Text?.Text);
|
SetInputLine("/e " + ((TdApi.MessageContent.MessageText)lastMessage?.Content)?.Text?.Text);
|
||||||
Emojis.ForEach(em => SetInputLine(currentInputLine.Replace(em.Item2, em.Item1)));
|
Emojis.ForEach(em => SetInputLine(currentInputLine.Replace(em.Item2, em.Item1)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -670,6 +671,43 @@ namespace tgcli {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MeCommand : Command {
|
||||||
|
public MeCommand() : base("me", "", "sends an action message", "<message>", -1) { }
|
||||||
|
|
||||||
|
public override void Handler(List<string> inputParams) {
|
||||||
|
try {
|
||||||
|
if (inputParams.Count == 0) {
|
||||||
|
lock (@lock)
|
||||||
|
messageQueue.Add($"{Ansi.Red}[tgcli] Invalid syntax, check /help for more information.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = inputParams.Aggregate((current, param) => current + " " + param).Trim();
|
||||||
|
|
||||||
|
if (currentChatId == 0) {
|
||||||
|
lock (@lock)
|
||||||
|
messageQueue.Add($"{Ansi.Red}[tgcli] No open chat, cannot continue.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(message)) {
|
||||||
|
lock (@lock)
|
||||||
|
messageQueue.Add($"{Ansi.Red}[tgcli] No message specified, cannot continue.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = client.GetMeAsync().Result;
|
||||||
|
var username = user.Usernames?.ActiveUsernames?.FirstOrDefault() ?? user.FirstName;
|
||||||
|
|
||||||
|
SendMessage($"* {username} {message}", currentChatId);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
lock (@lock)
|
||||||
|
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 ReplyCommand() : base("r", "", "matches message in history to reply to", "<message query>", -1) { }
|
||||||
|
|
||||||
|
@ -692,9 +730,7 @@ namespace tgcli {
|
||||||
var query = inputParams.Aggregate((current, param) => current + " " + param).Trim();
|
var query = inputParams.Aggregate((current, param) => current + " " + param).Trim();
|
||||||
|
|
||||||
var result = history.Where(m => m.Content is TdApi.MessageContent.MessageText)
|
var result = history.Where(m => m.Content is TdApi.MessageContent.MessageText)
|
||||||
.FirstOrDefault(m => ((TdApi.MessageContent.MessageText) m.Content)
|
.FirstOrDefault(m => ((TdApi.MessageContent.MessageText)m.Content).Text.Text.ToLowerInvariant().Contains(query.ToLower()));
|
||||||
.Text.Text.ToLowerInvariant()
|
|
||||||
.Contains(query.ToLower()));
|
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
lock (@lock)
|
lock (@lock)
|
||||||
|
|
Loading…
Reference in a new issue