private static void ResetBotMethod() { var lines = File.ReadAllText(Paths.Info.ConfigBotsInfo).Split(RowSeparator); var botInfos = new List <BotInfo>(); foreach (var t in lines) { var line = t; if (string.IsNullOrEmpty(line)) { continue; } line = line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } var lineInfo = line.Split(ColumnSeparator); var bot = new BotInfo(); bot.SetToken(lineInfo[0].Trim()); bot.SetWebsite(lineInfo[1].Trim()); bot.SetIsBot(BotTypeApi.REAL_BOT); bot.SetAcceptMessages(true); bot.SetOnMessages(lineInfo[2].Trim()); bot.SetContactString(lineInfo[3].Trim()); botInfos.Add(bot); } FileSerialization.WriteToBinaryFile(Paths.Bin.ConfigBot, botInfos); }
private static void ResetBotDisguisedAsUserBotMethod() { var lines = File.ReadAllText(Paths.Info.ConfigBotDisguisedAsUserBotsInfo).Split(RowSeparator); var botInfos = new List <BotDisguisedAsUserBotInfo>(); foreach (var t in lines) { var line = t; if (string.IsNullOrEmpty(line)) { continue; } line = line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } var lineInfo = line.Split(ColumnSeparator); var bot = new BotDisguisedAsUserBotInfo(); bot.SetApiId(lineInfo[0].Trim()); bot.SetApiHash(lineInfo[1].Trim()); bot.SetUserId(lineInfo[2].Trim()); bot.SetToken(lineInfo[3].Trim()); bot.SetIsBot(BotTypeApi.DISGUISED_BOT); botInfos.Add(bot); } FileSerialization.WriteToBinaryFile(Paths.Bin.ConfigBotDisguisedAsUserbot, botInfos); }
private static Dictionary <long, WebPost> GetDictionary() { var done = false; try { dictionary_webpost = FileSerialization.ReadFromBinaryFile <Dictionary <long, WebPost> >(pathwebdict); if (dictionary_webpost != null) { done = true; } } catch { ; } if (!done) { dictionary_webpost = new Dictionary <long, WebPost>(); } WriteDict(); return(dictionary_webpost); }
public TextFileForm() { _fileSelection = new FileSelection(); _fileSerialization = new FileSerialization(); _fileDbService = new FileDbService(); InitializeComponent(); DbGridDataLoading(); BrowseFileInitialize(); }
public static void WriteDict() { try { FileSerialization.WriteToBinaryFile(pathwebdict, dictionary_webpost); } catch { ; } }
private static void LoadMessagesToDelete() { var m = FileSerialization.ReadFromBinaryFile <List <MessageToDelete> >(Paths.Bin.MessagesToDelete); if (m == default || m == null) { MessagesToDelete = new List <MessageToDelete>(); return; } MessagesToDelete = m; }
public override void OnActivate() { base.OnActivate(); _world = new World(this, "World_0"); _pauseMenu = new PauseMenu(this); _worldFile = new FileSerialization <World.Serialized>(_worldFileToLoad); try { _world.Deserialize(_worldFile.LoadFile()); } catch (FileNotFoundException) { Debug.Log("The save file cannot be found, create a new save file."); _world.RequestLoadChunk(Vector2Int.zero); } }
private static ToExit LoadBotDisguisedAsUserBotConfig() { _botDisguisedAsUserBotInfos = FileSerialization.ReadFromBinaryFile <List <BotDisguisedAsUserBotInfo> >(Paths.Bin .ConfigBotDisguisedAsUserbot); if (_botDisguisedAsUserBotInfos != null && _botDisguisedAsUserBotInfos.Count != 0) { return(ToExit.STAY); } Console.WriteLine( "It seems that the bot disguised as userbot configuration isn't available. Do you want to reset it? (Y/N)"); var readChoice2 = Console.ReadLine(); if (!string.IsNullOrEmpty(readChoice2) && readChoice2.ToLower().StartsWith("y")) { NewConfig.NewConfigMethod(false, false, true, false, false); Console.WriteLine("Reset done! Do you wish to continue with the execution? (Y/N)"); var readChoice3 = Console.ReadLine(); if (!string.IsNullOrEmpty(readChoice3) && readChoice3.ToLower().StartsWith("y")) { //ok, keep going _botDisguisedAsUserBotInfos = FileSerialization.ReadFromBinaryFile <List <BotDisguisedAsUserBotInfo> >(Paths.Bin .ConfigBotDisguisedAsUserbot); } else { Console.WriteLine("Ok, bye!"); return(ToExit.SKIP); } } else { return(ToExit.SKIP); } return(ToExit.STAY); }
public static async Task <bool> GetAllGroups(long chatId, string username, TelegramBotAbstract sender, string lang) { var groups = Groups.GetAllGroups(); Stream stream = new MemoryStream(); FileSerialization.SerializeFile(groups, ref stream); TLAbsInputPeer peer2 = new TLInputPeerUser { UserId = (int)chatId }; var peer = new Tuple <TLAbsInputPeer, long>(peer2, chatId); var text2 = new Language(new Dictionary <string, string> { { "en", "Here are all groups:" }, { "it", "Ecco tutti i gruppi:" } }); return(await SendMessage.SendFileAsync(new TelegramFile(stream, "groups.bin", null, "application/octet-stream"), peer, text2, TextAsCaption.BEFORE_FILE, sender, username, lang, null, true)); }
private static void ResetUserbotMethod() { var lines = File.ReadAllText(Paths.Info.ConfigUserBotsInfo).Split(RowSeparator); var botInfos = new List <UserBotInfo>(); foreach (var t in lines) { var line = t; if (string.IsNullOrEmpty(line)) { continue; } line = line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } var lineInfo = line.Split(ColumnSeparator); var bot = new UserBotInfo(); bot.SetApiId(lineInfo[0].Trim()); bot.SetApiHash(lineInfo[1].Trim()); bot.SetUserId(lineInfo[2].Trim()); bot.SetNumberCountry(lineInfo[3].Trim()); bot.SetNumberNumber(lineInfo[4].Trim()); bot.SetPasswordToAuthenticate(lineInfo[5].Trim()); bot.SetIsBot(BotTypeApi.USER_BOT); bot.SetMethod(lineInfo[6].Trim()); botInfos.Add(bot); } FileSerialization.WriteToBinaryFile(Paths.Bin.ConfigUserbot, botInfos); }
private static async Task SendUsernameWarning(TelegramBotAbstract telegramBotClient, bool username, bool name, string lang, string usernameOfUser, long chatId, int userId, int?messageId, ChatType messageChatType, string firstName, string lastName, User[] newChatMembers) { var s1I = "Imposta un username e un nome più lungo dalle impostazioni di telegram per poter scrivere in questo gruppo\n"; if (username && !name) { s1I = "Imposta un username dalle impostazioni di telegram per poter scrivere in questo gruppo\n"; } else if (!username && name) { s1I = "Imposta un nome più lungo " + "dalle impostazioni di telegram\n"; } var s1E = "Set an username and a longer first name from telegram settings to write in this group\n"; if (username && !name) { s1E = "Set an username from telegram settings to write in this group\n"; } else if (!username && name) { s1E = "Set a longer first name from telegram settings to write in this group\n"; } var s2 = new Language(new Dictionary <string, string> { { "it", s1I }, { "en", s1E } }); var r1 = await SendMessage.SendMessageInPrivateOrAGroup(telegramBotClient, s2, lang, usernameOfUser, userId, firstName, lastName, chatId, messageChatType); const int MINUTES_WAIT = 2; if (r1.GetChatType() != ChatType.Private) { var r2 = r1.GetMessage(); if (r2 != null) { if (r2 is TLMessage r3) { lock (GlobalVariables.MessagesToDelete) { var timeUntilDelete = TimeSpan.FromMinutes(MINUTES_WAIT); var TimeToDelete = DateTime.Now + timeUntilDelete; var toDelete = new MessageToDelete(r3, chatId, TimeToDelete, telegramBotClient.GetId(), r1.GetChatType(), null); GlobalVariables.MessagesToDelete.Add(toDelete); FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete, GlobalVariables.MessagesToDelete); } } else if (r2 is Message r4) { lock (GlobalVariables.MessagesToDelete) { var timeUntilDelete = TimeSpan.FromMinutes(MINUTES_WAIT); var TimeToDelete = DateTime.Now + timeUntilDelete; var toDelete = new MessageToDelete(r4, chatId, TimeToDelete, telegramBotClient.GetId(), r1.GetChatType(), null); GlobalVariables.MessagesToDelete.Add(toDelete); FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete, GlobalVariables.MessagesToDelete); } } else { var e4 = "Attempted to add a message to be deleted in queue\n" + r2?.GetType() + " " + r2; var e3 = new Exception(e4); await NotifyUtil.NotifyOwners(e3, telegramBotClient); } } } if (newChatMembers == null || newChatMembers.Length == 0) { await RestrictUser.Mute(60 * 5, telegramBotClient, chatId, userId, messageChatType); } if (messageId != null) { await telegramBotClient.DeleteMessageAsync(chatId, messageId.Value, messageChatType, null); } }