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 override async Task HandleAsync( IUpdateContext context, UpdateDelegate next, string[] args ) { await _telegramService.AddUpdateContext(context); var fromNameLink = _telegramService.FromNameLink; var fromId = _telegramService.FromId; var chatId = _telegramService.ChatId; var afkReason = _telegramService.MessageOrEditedText.GetTextWithoutCmd(); if (_telegramService.CheckFromAnonymous() || _telegramService.CheckSenderChannel()) { await _telegramService.SendTextMessageAsync("Mode AFK dimatikan untuk Pengguna Anonymous"); return; } var settings = await _settingsService.GetSettingsByGroup(chatId); if (!settings.EnableAfkStatus) { await _telegramService.DeleteSenderMessageAsync(); return; } var data = new Dictionary <string, object>() { { "user_id", fromId }, { "chat_id", chatId }, { "is_afk", 1 }, { "afk_start", DateTime.Now }, { "afk_end", DateTime.Now } }; var sendText = $"{fromNameLink} Sedang afk."; if (afkReason.IsNotNullOrEmpty()) { data.Add("afk_reason", afkReason); sendText += $"\n<i>{afkReason}</i>"; } await _telegramService.SendTextMessageAsync(sendText); await _afkService.SaveAsync(data); await _afkService.UpdateAfkByIdCacheAsync(fromId); }
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); } }