public static bool RegisterGroup(Message message) { if (CacheData.Groups.ContainsKey(message.Chat.Id)) { return(false); } BusinessLogic.Group.TelegramGroupLogic telegramGroupLogic = new BusinessLogic.Group.TelegramGroupLogic(); TelegramGroup registered = telegramGroupLogic.Add( message.Chat.Id, message.Chat.Title, TelegramGroup.Status.Active, configuration: Newtonsoft.Json.JsonConvert.SerializeObject(CacheData.GroupDefaultConfigs), welcomeText: CacheData.GetTranslation("en", "message_welcome_default"), chatLanguage: "en", settingsLanguage: "en", reportChatId: CacheData.ControlChatId, rulesText: "No rules defined yet by the group admins. Just... be nice!", callerId: -2); if (registered == null) { return(false); } CacheData.Groups.Add(message.Chat.Id, registered); CacheData.GroupConfigs.Add(message.Chat.Id, CacheData.GroupDefaultConfigs); if (MessageQueueManager.AddGroupIfNotPresent(registered)) { Manager.BotClient.SendTextMessageAsync( chatId: message.Chat.Id, parseMode: ParseMode.Markdown, text: CacheData.GetTranslation("en", "message_group_first_join"), disableWebPagePreview: true ); Manager.BotClient.SendTextMessageAsync( chatId: CacheData.ControlChatId, parseMode: ParseMode.Markdown, text: String.Format( "*[Log]*\n" + "New group has chosen unified/ban 🥳\n" + "\nChat: {0}" + "\nChatId: {1}" + "\n\n*hash_code:* #UB{2}-{3}", message.Chat.Title, message.Chat.Id, message.Chat.Id.ToString().Replace("-", ""), Guid.NewGuid()) ); } return(true); }
public static void MigrateToChatId(Message message) { if (!CacheData.Groups.ContainsKey(message.Chat.Id)) { return; } BusinessLogic.Group.TelegramGroupLogic telegramGroupLogic = new BusinessLogic.Group.TelegramGroupLogic(); TelegramGroup updated = telegramGroupLogic.UpdateChatId(message.Chat.Id, message.MigrateToChatId, -2); // TODO - log operation if (updated == null) { return; } CacheData.Groups.Add(updated.TelegramChatId, updated); MessageQueueManager.AddGroupIfNotPresent(updated); MessageQueueManager.RemoveGroupIfNotPresent(message.Chat.Id); CacheData.Groups.Remove(message.Chat.Id); }