public static async Task Main(String[] args) { //run command line parser Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed <CommandLineOptions>(o => { CommandLineOptions = o; }); // initialize datafixers #if DEBUG DatafixerLogger.MinimalLevel = Helium.Commons.Logging.LogLevel.Debug; #else DatafixerLogger.MinimalLevel = Helium.Commons.Logging.LogLevel.Warning; #endif DataFixerLower.Initialize(0); //this can be switched out for 1 if you need to, insanitybot default is 0 RegisterDatafixers(); //load main config ConfigManager = new MainConfigurationManager(); LanguageManager = new LanguageConfigurationManager(); //read config from file Config = ConfigManager.Deserialize("./config/main.json"); if (String.IsNullOrWhiteSpace(Config.Token)) { Console.WriteLine("Invalid Token. Please provide a valid token in .\\config\\main.json" + "\nPress any key to continue..."); Console.ReadKey(); return; } LanguageConfig = LanguageManager.Deserialize("./config/lang.json"); //create discord config; increase the cache size if you want though itll take more RAM ClientConfiguration = new DiscordConfiguration { AutoReconnect = true, Token = Config.Token, TokenType = TokenType.Bot, MessageCacheSize = 4096, #if DEBUG MinimumLogLevel = LogLevel.Debug #else MinimumLogLevel = LogLevel.Information #endif }; //create and connect client Client = new DiscordClient(ClientConfiguration); await Client.ConnectAsync(); //load perms :b Client.InitializePermissionFramework(); try { //create home guild so commands can use it HomeGuild = await Client.GetGuildAsync(Convert.ToUInt64(Config.GuildId)); } #pragma warning disable CS0168 catch (UnauthorizedException e) #pragma warning restore CS0168 { Client.Logger.LogCritical(new EventId(0000, "Main"), "Your GuildId is either invalid or InsanityBot has not been invited to the server yet."); } catch { throw; } //load command configuration CommandConfiguration = new CommandsNextConfiguration { CaseSensitive = false, StringPrefixes = Config.Prefixes, DmHelp = (Boolean)Config["insanitybot.commands.help.send_dms"], IgnoreExtraArguments = true }; //create and register command client Client.UseCommandsNext(CommandConfiguration); CommandsExtension = Client.GetCommandsNext(); //start timer framework TimeHandler.Start(); //register commands and events RegisterAllCommands(); RegisterAllEvents(); //initialize various parts of InsanityBots framework InitializeAll(); Client.Logger.LogInformation(new EventId(1000, "Main"), "Startup successful!"); //start offthread TCP connection _ = HandleTCPConnections((Int64)Config["insanitybot.tcp_port"]); //start offthread XP management if ((Boolean)Config["insanitybot.modules.experience"]) { ; // not implemented yet } //start offthread console management if ((Boolean)Config["insanitybot.modules.console"]) { ; // not implemented yet } //abort main thread, who needs it anyway Thread.Sleep(-1); }
public static async Task Main(String[] args) { //run command line parser Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed(o => { CommandLineOptions = o; }); // initialize datafixers #if DEBUG DatafixerLogger.MinimalLevel = Helium.Commons.Logging.LogLevel.Debug; #else DatafixerLogger.MinimalLevel = Helium.Commons.Logging.LogLevel.Warning; #endif DataFixerLower.Initialize(0); //this can be switched out for 1 if you need to, insanitybot default is 0 RegisterDatafixers(); //load main config ConfigManager = new MainConfigurationManager(); LanguageManager = new LanguageConfigurationManager(); LoggerManager = new LoggerConfigurationManager(); //read config from file Config = ConfigManager.Deserialize("./config/main.json"); //validate token and guild id #region token if (String.IsNullOrWhiteSpace(Config.Token)) { if (!CommandLineOptions.Interactive) { System.Console.WriteLine("Invalid Token. Please provide a valid token in .\\config\\main.json" + "\nPress any key to continue..."); System.Console.ReadKey(); return; } System.Console.Write("Your config does not contain a token. To set a token now, paste your token here. " + "To abort and exit InsanityBot, type \"cancel\"\nToken: "); String token = System.Console.ReadLine(); if (token.ToLower().Trim() == "cancel") { System.Console.WriteLine("Operation aborted, exiting InsanityBot.\nPress any key to continue..."); System.Console.ReadKey(); return; } Config.Token = token; ConfigManager.Serialize(Config, "./config/main.json"); } if (Config.GuildId == 0) { if (!CommandLineOptions.Interactive) { System.Console.WriteLine("Invalid GuildId. Please provide a valid guild ID in .\\config\\main.json" + "\nPress any key to continue..."); System.Console.ReadKey(); return; } System.Console.Write("Your config does not contain a valid guild ID. To set a guild ID now, paste your guild ID here. " + "To abort and exit InsanityBot, type \"cancel\"\nGuild ID: "); String guildId = System.Console.ReadLine(); if (guildId.ToLower().Trim() == "cancel") { System.Console.WriteLine("Operation aborted, exiting InsanityBot.\nPress any key to continue..."); System.Console.ReadKey(); return; } if (UInt64.TryParse(guildId, out UInt64 id)) { Config.GuildId = id; ConfigManager.Serialize(Config, "./config/main.json"); } else { System.Console.WriteLine("The provided guild ID could not be parsed. Aborting and exiting InsanityBot.\n" + "Press any key to continue..."); System.Console.ReadKey(); return; } } #endregion LanguageConfig = LanguageManager.Deserialize("./config/lang.json"); LoggerConfig = LoggerManager.Deserialize("./config/logger.json"); LoggerFactory loggerFactory = new(); EmbedFactory = new(); //create discord config; increase the cache size if you want though itll take more RAM ClientConfiguration = new DiscordConfiguration { AutoReconnect = true, Token = Config.Token, TokenType = TokenType.Bot, MessageCacheSize = 4096, LoggerFactory = loggerFactory, HttpTimeout = new(00, 00, 30) }; //create and connect client Client = new DiscordClient(ClientConfiguration); await Client.ConnectAsync(); Client.Logger.LogInformation(new EventId(1000, "Main"), $"InsanityBot Version {Version}"); //load perms PermissionEngine = Client.InitializeEngine(new PermissionConfiguration { PrecompiledScripts = true, UpdateRolePermissions = true, UpdateUserPermissions = true }); try { //create home guild so commands can use it HomeGuild = await Client.GetGuildAsync(Convert.ToUInt64(Config.GuildId)); } catch (UnauthorizedException) { Client.Logger.LogCritical(new EventId(0000, "Main"), "Your GuildId is either invalid or InsanityBot has not been invited to the server yet."); } catch { throw; } //load command configuration CommandConfiguration = new CommandsNextConfiguration { CaseSensitive = false, StringPrefixes = Config.Prefixes, DmHelp = (Boolean)Config["insanitybot.commands.help.send_dms"], IgnoreExtraArguments = true }; //create and register command client Client.UseCommandsNext(CommandConfiguration); CommandsExtension = Client.GetCommandsNext(); PaginationEmojis InteractivityPaginationEmotes = new(); if (ToUInt64(Config["insanitybot.identifiers.interactivity.scroll_right_emote_id"]) != 0) { InteractivityPaginationEmotes.Right = HomeGuild.Emojis[ToUInt64(Config["insanitybot.identifiers.interactivity.scroll_right_emote_id"])]; } if (ToUInt64(Config["insanitybot.identifiers.interactivity.scroll_left_emote_id"]) != 0) { InteractivityPaginationEmotes.Left = HomeGuild.Emojis[ToUInt64(Config["insanitybot.identifiers.interactivity.scroll_left_emote_id"])]; } if (ToUInt64(Config["insanitybot.identifiers.interactivity.skip_right_emote_id"]) != 0) { InteractivityPaginationEmotes.SkipRight = HomeGuild.Emojis[ToUInt64(Config["insanitybot.identifiers.interactivity.skip_right_emote_id"])]; } if (ToUInt64(Config["insanitybot.identifiers.interactivity.skip_left_emote_id"]) != 0) { InteractivityPaginationEmotes.SkipLeft = HomeGuild.Emojis[ToUInt64(Config["insanitybot.identifiers.interactivity.skip_left_emote_id"])]; } if (ToUInt64(Config["insanitybot.identifiers.interactivity.stop_emote_id"]) != 0) { InteractivityPaginationEmotes.Stop = HomeGuild.Emojis[ToUInt64(Config["insanitybot.identifiers.interactivity.stop_emote_id"])]; } Interactivity = Client.UseInteractivity(new() { PaginationBehaviour = PaginationBehaviour.Ignore, PaginationDeletion = PaginationDeletion.DeleteEmojis, PaginationEmojis = InteractivityPaginationEmotes }); CommandsExtension.CommandErrored += CommandsExtension_CommandErrored; //start timer framework TimeHandler.Start(); //register commands and events RegisterAllCommands(); RegisterAllEvents(); //initialize various parts of InsanityBots framework InitializeAll(); Client.Logger.LogInformation(new EventId(1000, "Main"), $"Startup successful!"); //start offthread TCP connection _ = HandleTCPConnections((Int64)Config["insanitybot.tcp_port"]); //start offthread XP management // if ((Boolean)Config["insanitybot.modules.experience"]) ; // not implemented yet //start integrated offthread console management - cannot disable _ = Task.Run(() => { IntegratedCommandHandler.Initialize(); }); //start offthread console management // if ((Boolean)Config["insanitybot.modules.console"]) ; // not implemented yet //abort main thread, who needs it anyway Thread.Sleep(-1); }