コード例 #1
0
        public async Task <bool> Init(string[] args)
        {
            var opts = new OptionSet()
            {
                { "d|dir=", "Set server storage dir (default: ./)", b => ServerDir = b },
                { "s|secret=", "Set client secret (osu!) (required)", s => OsuSecret = s },
                { "k|key=", "osu! api v1 key (required)", k => OsuApiKey = k },
                { "id=", "osu! client id (default: mine)", id => OsuId = id },
                { "t|token=", "discord bot token (required)", t => DiscordToken = t },
                { "h|help", "displays help", a => Help = a != null },
                { "l|link", "displays bot link and exits", l => Link = l != null },
                { "apiRequest=", "does api request", a => Apiv2Req = a },
                { "test", "test server only", t => Test = t != null },
                { "w|webhook=", "webhook for output", w => WebHook = w },
                { "reload", "reload databases", r => Reload = r != null },
            };

            opts.Parse(args);
            string botLink = $"https://discordapp.com/oauth2/authorize?client_id={DiscordId}&scope=bot&permissions={DiscordPermissions}";

            if (Link)
            {
                Console.WriteLine(botLink);
                return(false);
            }

            if (Help || (OsuSecret.Length * OsuApiKey.Length * DiscordToken.Length) == 0)
            {
                Console.WriteLine(
                    $@"osu! Miss Analyzer, Discord Bot Edition
Bot link: https://discordapp.com/oauth2/authorize?client_id={DiscordId}&scope=bot&permissions={DiscordPermissions}");
                opts.WriteOptionDescriptions(Console.Out);
                return(false);
            }
            if (Apiv2Req != null)
            {
                OsuApi api2 = new OsuApi(ServerContext.webClient, OsuId, OsuSecret, OsuApiKey);
                Console.WriteLine(await api2.GetApiv2(Apiv2Req));
                return(false);
            }

            try
            {
                using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream("OsuMissAnalyzer.Server.Resources.GitCommit.txt"))
                    using (var streamReader = new StreamReader(stream, Encoding.UTF8))
                    {
                        GitCommit = streamReader.ReadToEnd();
                    }
            }
            catch (Exception) { return(false); }

            return(true);
        }