public async Task ReloadCommand() { await DeleteMessageAsync(); if (!_privilegeService.IsFromSudo(FromId)) { _logger.LogInformation("This command is for Sudo only"); return; } await SendMessageTextAsync("Sedang mendaftarkan perintah."); await Bot.SetMyCommandsAsync( new List <BotCommand>() { new() { Command = "ping", Description = "Mengecek kesehatan Zizi" }, new BotCommand() { Command = "start", Description = "Memulai menggunakan Zizi" } }
public async Task Ping() { using var operation = Operation.Begin("Ping command handler"); var pingOffset = TimeSpan.FromSeconds(60); if (IsMessageOlderThan(pingOffset)) { _logger.LogDebug("Ping response is disabled because chatId is older than {PingOffset}", pingOffset); return; } var isSudo = _privilegeService.IsFromSudo(From.Id); var currProcess = Process.GetCurrentProcess(); var processStartTime = currProcess.StartTime; var processUptime = (DateTime.Now - processStartTime); var htmlMsg = new HtmlString() .Bold("🏓 Pong!"); if (isSudo) { htmlMsg.Br().Br() .Bold("🏃 Runtime: ").Code(processStartTime.ToString("yyyy-MM-dd HH:mm")).Br() .Bold("⏱ Uptime: ").Code(processUptime.ToHumanDuration()); } var keyboardMarkup = new InlineKeyboardMarkup( new[] { new[] { InlineKeyboardButton.WithCallbackData("Ping", "ping") } } ); await SendMessageTextAsync( message : htmlMsg, replyMarkup : keyboardMarkup, replyToMessageId : Message.MessageId ); operation.Complete(); }
public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args) { await _telegramService.AddUpdateContext(context); var chatTitle = _telegramService.Chat.Title; var chatId = _telegramService.ChatId; var chatType = _telegramService.Chat.Type; var userId = _telegramService.FromId; var fullName = _telegramService.From.GetFullName(); var userLang = _telegramService.From?.LanguageCode; var op = Operation.Begin("Command '/id' on ChatId '{ChatId}'", chatId); var fromSudo = _telegramService.IsFromSudo; var text = $"👥 <b>{chatTitle}</b>\n" + $"Chat ID: <code>{chatId}</code>\n" + $"Type: <code>{chatType}</code>\n\n" + $"👤 <b>{fullName}</b>\n" + $"Is Sudo: <code>{fromSudo}</code>\n" + $"User ID: <code>{userId}</code>\n" + $"Language: <code>{userLang.ToUpperCase()}</code>"; if (_telegramService.ReplyToMessage != null) { var repMsg = _telegramService.ReplyToMessage; var repToFromId = _telegramService.ReplyFromId; var repFullName = repMsg.From.GetFullName(); var repToSudo = _privilegeService.IsFromSudo(repToFromId); text += $"\n\n👤 <b>{repFullName}</b>" + $"\nIs Sudo: <code>{repToSudo}</code>" + $"\nUser ID: <code>{repToFromId}</code>" + $"\nLanguage: <code>{repMsg.From?.LanguageCode}</code>"; } await _telegramService.SendTextMessageAsync(text); op.Complete(); }
public async Task CmdBackup() { var op = Operation.Begin("Backup Command Handler"); await DeleteMessageAsync(Message.MessageId); if (!_privilegeService.IsFromSudo(FromId)) { _logger.LogInformation("Backup Data only for Sudo!"); op.Complete(); return; } await SendMessageTextAsync("Memulai mencadangkan Data.."); var dataBackupInfo = await _databaseService.BackupMySqlDatabase(); var fileName = dataBackupInfo.FileName; var fullName = dataBackupInfo.FullName.GetDirectory(); var fullNameZip = dataBackupInfo.FullNameZip; var fileSize = dataBackupInfo.FileSizeSqlZipRaw.SizeFormat(); var fileSizeRaw = dataBackupInfo.FileSizeSqlRaw.SizeFormat(); var htmlMessage = new HtmlString() .Bold("Name: ").Code(fileName).Br() .Bold("Path: ").Code(fullName).Br() .Bold("Size: ").Code(fileSize).Br() .Bold("RawSize: ").Code(fileSizeRaw); await DeleteMessageAsync(); await SendMediaDocumentAsync( fullNameZip, MediaType.LocalDocument, htmlMessage ); op.Complete(); }