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 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); } }