public void Execute(Message message) { if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic) && !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id)) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ReplyToMessageId = message.MessageId, Text = CacheData.GetTranslation("en", "error_not_auth_command") }); return; } string[] hasMessage = message.Text.Split(" "); if (hasMessage.Length > 1) { bool result = Utils.ConfigTools.UpdateRulesText(message.Chat.Id, message.Text.Remove(0, hasMessage[0].Length + 1)); if (result) { Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId); } return; } CommandMessage commandMessage = new CommandMessage() { Command = "SetRulesText", Value = "", Message = message, Timestamp = DateTime.UtcNow }; CommandQueueManager.EnqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = message.Chat, ReplyToMessageId = message.MessageId, ParseMode = ParseMode.Html, Text = $"<b>[ADMIN] [r:{message.MessageId}]</b>\n" + CacheData.GetTranslation( CacheData.Groups[message.Chat.Id].SettingsLanguage, "command_setrules_instructions"), ReplyMarkup = new ForceReplyMarkup() { Selective = true } }); }
public void Execute(CallbackQuery callbackQuery) { if (!Utils.BotTools.IsUserOperator(callbackQuery.From.Id, Models.Operator.Levels.Basic) && !Utils.ChatTools.IsUserAdmin(callbackQuery.Message.Chat.Id, callbackQuery.From.Id)) { return; } Manager.BotClient.DeleteMessageAsync(callbackQuery.Message.Chat.Id, callbackQuery.Message.MessageId); string data = callbackQuery.Data.Replace("/feedback ", ""); string type = data.Split(':')[1]; CommandMessage commandMessage = new CommandMessage() { Command = "Feedback", Value = type, Message = callbackQuery.Message, Timestamp = DateTime.UtcNow }; CommandQueueManager.EnqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = callbackQuery.Message.Chat, ReplyToMessageId = callbackQuery.Message.ReplyToMessage.MessageId, ParseMode = ParseMode.Markdown, Text = $"*[ADMIN] [r:{callbackQuery.Message.MessageId}]*\nProvide feedback text:", ReplyMarkup = new ForceReplyMarkup() { Selective = true } }); }
public void Execute(CallbackQuery callbackQuery) { if (CacheData.Operators .SingleOrDefault(x => x.TelegramUserId == callbackQuery.From.Id && x.Level == Models.Operator.Levels.Super) == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = callbackQuery.Message.Chat, ReplyToMessageId = callbackQuery.Message.MessageId, Text = CacheData.GetTranslation("en", "error_not_auth_command") }); Manager.BotClient.SendTextMessageAsync( chatId: CacheData.ControlChatId, parseMode: ParseMode.Markdown, text: String.Format( "*[Report]*\n" + "⚠️ Non operator tried to use /addtranslation\n" + "\n*Chat:* {0}" + "\n*ChatId:* {1}" + "\n*UserId:* {2}" + "\n\n*hash_code:* #UB{3}-{4}", callbackQuery.Message.Chat.Title, callbackQuery.Message.Chat.Id, callbackQuery.From.Id, callbackQuery.Message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()) ); return; } string data = callbackQuery.Data.Replace("/AddTranslation ", ""); string command = data.Split(':')[0]; string value = data.Split(':')[1]; if (command == "language") { Manager.BotClient.DeleteMessageAsync( callbackQuery.Message.Chat, callbackQuery.Message.MessageId); CommandMessage commandMessage = new CommandMessage() { Command = "AddTranslationKey", Value = value, Message = callbackQuery.Message, Timestamp = DateTime.UtcNow }; CommandQueueManager.EnqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = callbackQuery.Message.Chat, ReplyToMessageId = callbackQuery.Message.ReplyToMessage.MessageId, ParseMode = ParseMode.Markdown, Text = $"*[ADMIN] [r:{callbackQuery.Message.MessageId}]*\nDeclare KeyId:", ReplyMarkup = new ForceReplyMarkup() { Selective = true } }); } }
public static void AddTranslationEntry(CommandMessage commandMessage, Message replyMessage) { if (CacheData.Operators .SingleOrDefault(x => x.TelegramUserId == commandMessage.Message.From.Id && x.Level == Models.Operator.Levels.Super) == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, Text = CacheData.GetTranslation("en", "error_not_auth_command") }); Manager.BotClient.SendTextMessageAsync( chatId: CacheData.ControlChatId, parseMode: ParseMode.Markdown, text: String.Format( "User *{0}:{1}* tried to use command AddTranslationEntry.", replyMessage.From.Id, replyMessage.From.Username) ); return; } string[] parameters = commandMessage.Value.Split('|'); if (parameters.Length != 2) { CommandQueueManager.DenqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, Text = CacheData.GetTranslation("en", "error_invalid_parameters"), ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); } string languageId = parameters[0]; string keyId = parameters[1]; BusinessLogic.TranslationLogic translationLogic = new BusinessLogic.TranslationLogic(); Entry translationEntry = translationLogic.AddEntry( languageId, keyId, replyMessage.Text, replyMessage.From.Id); if (translationEntry == null) { CommandQueueManager.DenqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = "*Error* adding translation entry.\nCheck internal logs.", ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); return; } CommandQueueManager.DenqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = "*OK!*\nTranslation added successfully!\nRemember to reload them manually!", ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); }
public static void AddTranslationKey(CommandMessage commandMessage, Message replyMessage) { if (CacheData.Operators .SingleOrDefault(x => x.TelegramUserId == commandMessage.Message.ReplyToMessage.From.Id && x.Level == Models.Operator.Levels.Super) == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, Text = CacheData.GetTranslation("en", "error_not_auth_command") }); Manager.BotClient.SendTextMessageAsync( chatId: CacheData.ControlChatId, parseMode: ParseMode.Markdown, text: String.Format( "User *{0}:{1}* tried to use command AddTranslationKey.", replyMessage.From.Id, replyMessage.From.Username), replyMarkup: new ReplyKeyboardRemove() { Selective = true } ); return; } CommandQueueManager.DenqueueMessage(commandMessage); var regexItem = new Regex("^[a-zA-Z0-9_]*$"); if (!regexItem.IsMatch(replyMessage.Text.Trim())) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = "Error: translation key cannot contain space and/or special chars.\n" + "Start again the process.", ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); return; } BusinessLogic.TranslationLogic translationLogic = new BusinessLogic.TranslationLogic(); Key translationKey = translationLogic.GetKeyById(replyMessage.Text.Trim()); if (translationKey == null) { translationKey = translationLogic.AddKey( replyMessage.Text.Trim(), replyMessage.From.Id); } if (translationKey == null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = "*Error* adding translation key.\nCheck internal logs.", ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); return; } Entry entryExists = translationLogic.GetEntryById(commandMessage.Value, translationKey.KeyId); if (entryExists != null) { MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = $"*Error*\n {commandMessage.Value} translation for key `{translationKey.KeyId}` already exists!", ReplyMarkup = new ReplyKeyboardRemove() { Selective = true } }); return; } CommandMessage newCommandMessage = new CommandMessage() { Command = "AddTranslationEntry", Value = commandMessage.Value + "|" + translationKey.KeyId, Message = replyMessage, Timestamp = DateTime.UtcNow }; CommandQueueManager.EnqueueMessage(newCommandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = replyMessage.Chat, ReplyToMessageId = replyMessage.MessageId, ParseMode = ParseMode.Markdown, Text = $"*[ADMIN] [r:{replyMessage.MessageId}]*\nType translation for " + $"`{translationKey.KeyId}` in `{CacheData.Languages[commandMessage.Value].Name}`:", ReplyMarkup = new ForceReplyMarkup() { Selective = true } }); }
public void Execute(CallbackQuery callbackQuery) { if (!Utils.BotTools.IsUserOperator(callbackQuery.From.Id, Models.Operator.Levels.Basic)) { return; } string[] arguments = callbackQuery.Data.Split(" "); int userToBan = Convert.ToInt32(arguments[1]); Models.User.Banned.BanReasons reason = Models.User.Banned.BanReasons.Other; switch (arguments[2]) { case "spam": reason = Models.User.Banned.BanReasons.Spam; break; case "scam": reason = Models.User.Banned.BanReasons.Scam; break; case "harassment": reason = Models.User.Banned.BanReasons.Harassment; break; case "other": reason = Models.User.Banned.BanReasons.Other; break; } if (reason == Models.User.Banned.BanReasons.Other) { CommandMessage commandMessage = new CommandMessage() { Command = "AddUserToBlacklist", Value = userToBan.ToString(), Message = callbackQuery.Message, Timestamp = DateTime.UtcNow }; CommandQueueManager.EnqueueMessage(commandMessage); MessageQueueManager.EnqueueMessage( new Models.ChatMessage() { Timestamp = DateTime.UtcNow, Chat = callbackQuery.Message.Chat, ReplyToMessageId = callbackQuery.Message.ReplyToMessage.MessageId, ParseMode = ParseMode.Markdown, Text = $"*[OPERATOR] [r:{callbackQuery.Message.MessageId}]*\nProvide reason:", ReplyMarkup = new ForceReplyMarkup() { Selective = true } }); } else { Utils.UserTools.AddUserToBlacklist(callbackQuery.From.Id, callbackQuery.Message, userToBan, reason, null); } }