public static async Task AfkCheck(this RequestProvider requestProvider, Message message) { var afkService = new AfkService(); if (message.ReplyToMessage != null) { var repMsg = message.ReplyToMessage; var isAfkReply = await afkService.IsAfkAsync(repMsg); if (isAfkReply) { await requestProvider.SendTextAsync($"{repMsg.GetFromNameLink()} sedang afk"); } } var isAfk = await afkService.IsAfkAsync(message); if (isAfk) { await requestProvider.SendTextAsync($"{message.GetFromNameLink()} sudah tidak afk"); var data = new Dictionary <string, object>() { { "chat_id", message.Chat.Id }, { "user_id", message.From.Id }, { "is_afk", 0 }, { "afk_reason", "" } }; await afkService.SaveAsync(data); await afkService.UpdateCacheAsync(); } }
public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken) { _telegramService = new TelegramService(context); var msg = context.Update.Message; var data = new Dictionary <string, object>() { { "user_id", msg.From.Id }, { "chat_id", msg.Chat.Id }, { "is_afk", 1 } }; var sendText = $"{msg.GetFromNameLink()} Sedang afk."; if (msg.Text.GetTextWithoutCmd().IsNotNullOrEmpty()) { var afkReason = msg.Text.GetTextWithoutCmd(); data.Add("afk_reason", afkReason); sendText += $"\n<i>{afkReason}</i>"; } await _telegramService.SendTextAsync(sendText) .ConfigureAwait(false); await _afkService.SaveAsync(data) .ConfigureAwait(false); await _afkService.UpdateCacheAsync() .ConfigureAwait(false); }
public static async Task AfkCheckAsync(this TelegramService telegramService) { Log.Information("Starting check AFK"); var message = telegramService.MessageOrEdited; // var settingService = new SettingsService(message); var chatSettings = telegramService.CurrentSetting; if (!chatSettings.EnableAfkStat) { Log.Information("Afk Stat is disabled in this Group!"); return; } var afkService = new AfkService(); if (message.ReplyToMessage != null) { var repMsg = message.ReplyToMessage; var isAfkReply = await afkService.IsAfkAsync(repMsg) .ConfigureAwait(false); if (isAfkReply) await telegramService.SendTextAsync($"{repMsg.GetFromNameLink()} sedang afk") .ConfigureAwait(false); } var isAfk = await afkService.IsAfkAsync(message) .ConfigureAwait(false); if (isAfk) { await telegramService.SendTextAsync($"{message.GetFromNameLink()} sudah tidak afk") .ConfigureAwait(false); var data = new Dictionary<string, object> { {"chat_id", message.Chat.Id}, {"user_id", message.From.Id}, {"is_afk", 0}, {"afk_reason", ""} }; await afkService.SaveAsync(data).ConfigureAwait(false); await afkService.UpdateCacheAsync().ConfigureAwait(false); } }