예제 #1
0
    async def weather(self, ctx: main.NewCtx, *, city: str):
        """Displays the weather at a particular location"""
        if not (embed := ctx.cached_data):

            res = await self.aioweather.fetch_weather(city)
            embed = self.aioweather.format_weather(res)
            ctx.add_to_cache(value=embed, timeout=datetime.timedelta(minutes=10))
예제 #2
0
        async def template(ctx: NewCtx, *, query: str):
            is_nsfw = ctx.channel.is_nsfw()
            ctx.cache_key += [is_nsfw]

            if not (response := ctx.cached_data):

                await self._check_api_cooldowns(ctx)

                response = await self.aiojikan.search(ctx.command.name, query)
                ctx.add_to_cache(response,
                                 timeout=datetime.timedelta(hours=24))
예제 #3
0
    async def screenshot(self, ctx: main.NewCtx, url: str):
        """Screenshots a website"""
        is_nsfw = ctx.channel.is_nsfw()
        ctx.cache_key += [is_nsfw]

        if not (embed := ctx.cached_data):

            if not is_nsfw or len(url.split(".")) < 2:
                url = await self.aioscreen.check_url(url=url, is_nsfw=is_nsfw)

            response = await self.aioscreen.fetch_snapshot(url)
            embed = self.aioscreen.format_snapshot(response=response, is_nsfw=is_nsfw)

            ctx.add_to_cache(embed, timeout=datetime.timedelta(minutes=5))
예제 #4
0
 async def do_search(self, ctx: NewCtx, *, query: str, 
                     is_nsfw: bool, image_search: bool = False) -> ListPageSource:
     """Searches stuff and returns the formatted version of it"""
     results = await self.search(query, 
                                 safesearch=not is_nsfw, 
                                 image_search=image_search)
             
     return ctx.add_to_cache(GoogleSource(results, is_nsfw), 
                             timeout=timedelta(minutes=5))
예제 #5
0
    async def saucenao(
        self,
        ctx: NewCtx,  # might be redundant
        target: Union[discord.Member, discord.User, discord.Message] = None):
        """Provides informations about an image"""
        image = await self.aiosaucenao.select_image(ctx=ctx, target=target)

        ctx.cache_key += [image]

        if not (source := ctx.cached_data):

            response = await self.aiosaucenao.search(image)
            source = ctx.add_to_cache(value=SauceNaoSource(response.results),
                                      timeout=timedelta(hours=24))
예제 #6
0
 async def r34(self, ctx: main.NewCtx, *, query: str, fuzzy: bool = False):
     """Searches a post on r34"""
     if not (source := ctx.cached_data):
         results = await self.aiorule34.getImages(query, fuzzy=fuzzy)
         ctx.add_to_cache(results, timeout=datetime.timedelta(minutes=60))