예제 #1
0
        public async Task <ActionResult <GenericResponse> > CatGet()
        {
            if (ASF.WebBrowser == null)
            {
                throw new InvalidOperationException(nameof(ASF.WebBrowser));
            }

            string?link = await CatAPI.GetRandomCatURL(ASF.WebBrowser).ConfigureAwait(false);

            return(!string.IsNullOrEmpty(link) ? Ok(new GenericResponse <string>(link)) : StatusCode((int)HttpStatusCode.ServiceUnavailable, new GenericResponse(false)));
        }
예제 #2
0
        // This method is called when unknown command is received (starting with CommandPrefix)
        // This allows you to recognize the command yourself and implement custom commands
        // Keep in mind that there is no guarantee what is the actual access of steamID, so you should do the appropriate access checking yourself
        // You can use either ASF's default functions for that, or implement your own logic as you please
        // Since ASF already had to do initial parsing in order to determine that the command is unknown, args[] are splitted using standard ASF delimiters
        // If by any chance you want to handle message in its raw format, you also have it available, although for usual ASF pattern you can most likely stick with args[] exclusively. The message has CommandPrefix already stripped for your convenience
        // If you do not recognize the command, just return null/empty and allow ASF to gracefully return "unknown command" to user on usual basis
        public async Task <string?> OnBotCommand(Bot bot, ulong steamID, string message, string[] args)
        {
            // In comparison with OnBotMessage(), we're using asynchronous CatAPI call here, so we declare our method as async and return the message as usual
            // Notice how we handle access here as well, it'll work only for FamilySharing+
            switch (args[0].ToUpperInvariant())
            {
            case "CAT" when bot.HasAccess(steamID, BotConfig.EAccess.FamilySharing):
                // Notice how we can decide whether to use bot's AWH WebBrowser or ASF's one. For Steam-related requests, AWH's one should always be used, for third-party requests like those it doesn't really matter
                // Still, it makes sense to pass AWH's one, so in case you get some errors or alike, you know from which bot instance they come from. It's similar to using Bot's ArchiLogger compared to ASF's one
                string?randomCatURL = await CatAPI.GetRandomCatURL(bot.ArchiWebHandler.WebBrowser).ConfigureAwait(false);

                return(!string.IsNullOrEmpty(randomCatURL) ? randomCatURL : "God damn it, we're out of cats, care to notify my master? Thanks!");

            default:
                return(null);
            }
        }
예제 #3
0
        public async Task <ActionResult <GenericResponse> > CatGet()
        {
            string link = await CatAPI.GetRandomCatURL(ASF.WebBrowser).ConfigureAwait(false);

            return(!string.IsNullOrEmpty(link) ? Ok(new GenericResponse <string>(link)) : StatusCode((int)HttpStatusCode.ServiceUnavailable, new GenericResponse(false)));
        }