Beispiel #1
0
        public static ShimaConfig LoadConfig()
        {
            try
            {
                StreamReader streamReader = File.OpenText("config.json");
                string       json         = streamReader.ReadToEnd();
                if (json.Length < 1)
                {
                    return(new ShimaConfig());
                }

                ShimaConfig config = JsonConvert.DeserializeObject <ShimaConfig>(json);
                if (config.settings.isTest)
                {
                    ShimakazeBot.DefaultPrefix  = config.settings.testPrefix;
                    ShimakazeBot.guildDebugMode = config.settings.defaultTestDebugServers;
                }
                else
                {
                    ShimakazeBot.DefaultPrefix = config.settings.defaultPrefix;
                }

                return(config);
            }
            catch (FileNotFoundException e)
            {
                throw new FileNotFoundException(
                          $"Couldn't find config file at {e.FileName}");
            }
        }
Beispiel #2
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            ShimaConfig config = ShimaConfig.LoadConfig();

            optionsBuilder.UseNpgsql($"Host={config.database.host};" +
                                     $"Port={config.database.port};" +
                                     $"Database={config.database.name};" +
                                     $"Username={config.database.username};" +
                                     $"Password={config.database.password}");
        }
Beispiel #3
0
        static async Task MainAsync(string[] args)
        {
            ShimakazeBot.Config = ShimaConfig.LoadConfig();
            if (ShimakazeBot.Config.Equals(null) ||
                (ShimakazeBot.Config.settings.liveToken == null &&
                 ShimakazeBot.Config.settings.testToken == null))
            {
                throw new System.ArgumentNullException("", "Config ain't set up properly (:");
            }

            ShimaLoggerFactory loggerFactory = new ShimaLoggerFactory();

            loggerFactory.AddProvider(new ShimaLoggerProvider());

            ShimakazeBot.Client = new DiscordClient(new DiscordConfiguration
            {
                Token = ShimakazeBot.Config.settings.isTest ?
                        ShimakazeBot.Config.settings.testToken :
                        ShimakazeBot.Config.settings.liveToken,
                TokenType       = TokenType.Bot,
                MinimumLogLevel = LogLevel.Information,
                LoggerFactory   = loggerFactory
            });

            ShimakazeBot.DbCtx = new ShimaContext();

            await ShimakazeBot.DbCtx.Database.MigrateAsync();

            ShimakazeBot.FetchPrefixes();
            ShimakazeBot.FetchStreamingRoles();
            ShimakazeBot.FetchSelfAssignLimits();
            ShimakazeBot.FetchPermissionLevels();

            CommandsNextConfiguration commandConfig = new CommandsNextConfiguration
            {
                PrefixResolver = (msg) =>
                {
                    return(Task.Run(() =>
                    {
                        var guild = msg.Channel.Guild;
                        if (guild is null)
                        {
                            return msg.GetStringPrefixLength(ShimakazeBot.DefaultPrefix);
                        }
                        return msg.GetStringPrefixLength(ShimakazeBot.CustomPrefixes.ContainsKey(guild.Id)
                            ? ShimakazeBot.CustomPrefixes[guild.Id]
                            : ShimakazeBot.DefaultPrefix);
                    }));
                }
            };

            CommandsNextExtension commandsNextExtension = ShimakazeBot.Client.UseCommandsNext(commandConfig);

            commandsNextExtension.RegisterCommands <DebugCommands>();
            commandsNextExtension.RegisterCommands <InfoCommands>();
            commandsNextExtension.RegisterCommands <GeneralCommands>();
            commandsNextExtension.RegisterCommands <FunCommands>();
            commandsNextExtension.RegisterCommands <VoiceCommands>();
            commandsNextExtension.RegisterCommands <CustomizationCommands>();
            commandsNextExtension.RegisterCommands <ManagementCommands>();
            commandsNextExtension.RegisterCommands <EventCommands>();

            ShimakazeBot.Client.UseLavalink();

            ShimakazeBot.events.LoadEvents();

            await ShimakazeBot.Client.ConnectAsync();

            await Task.Delay(-1);
        }
    }