Implement missing functionality
This commit is contained in:
parent
003f17a9d5
commit
5d8fc76e53
48
Program.cs
48
Program.cs
|
@ -1,13 +1,47 @@
|
|||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
if (args.Length != 3) {
|
||||
Console.WriteLine("Syntax: telegram-send <token> <chatId> <message>");
|
||||
Environment.Exit(1);
|
||||
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var configFile = Path.Join(homeDir, ".telegram-send.conf");
|
||||
string config;
|
||||
|
||||
if (args.Length == 0)
|
||||
PrintSyntaxAndExit();
|
||||
|
||||
if (args[0] == "--config") {
|
||||
if (args.Length != 3)
|
||||
PrintSyntaxAndExit();
|
||||
|
||||
config = $"""
|
||||
token={args[1]}
|
||||
chatId={args[2]}
|
||||
""";
|
||||
|
||||
File.WriteAllText(configFile, config);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
var token = args[0];
|
||||
var chatId = args[1];
|
||||
var message = args[2];
|
||||
if (args.Length > 2)
|
||||
PrintSyntaxAndExit();
|
||||
|
||||
config = File.ReadAllText(configFile);
|
||||
var token = config.Split("\n")[0].Replace("token=", "");
|
||||
var chatId = config.Split("\n")[1].Replace("chatId=", "");
|
||||
var message = args[0] == "-" ? Console.In.ReadToEnd() : args[0];
|
||||
var bot = new TelegramBotClient(token);
|
||||
|
||||
await bot.SendTextMessageAsync(chatId, message);
|
||||
if (args.Contains("--pre"))
|
||||
message = $"```\n{message}\n```";
|
||||
|
||||
await bot.SendTextMessageAsync(chatId, message, ParseMode.MarkdownV2);
|
||||
|
||||
void PrintSyntaxAndExit() {
|
||||
Console.WriteLine("""
|
||||
Syntax:
|
||||
telegram-send --config <token> <chatid>
|
||||
telegram-send <message> [--pre]
|
||||
|
||||
To read from stdin, pass '-' as message.
|
||||
""");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue