Exemple #1
0
    async def on_command_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            return

        if isinstance(error, commands.errors.CommandNotFound):
            return

        if isinstance(error, commands.CommandOnCooldown):
            embed = discord.Embed(
                title="⚠ 쿨타임 중!",
                description="{}초 뒤에 재시도하세요.".format(int(error.retry_after)),
                color=0xD8EF56,
            )
            return await ctx.send(embed=embed)

        if isinstance(error, commands.CommandInvokeError):
            original = error.original
            if isinstance(original, discord.Forbidden):
                embed = Embed.warn(
                    "주의",
                    "봇의 권한이 부족하여 {} 명령어를 수행할 수 없어요.".format(ctx.command.name),
                )
                return await ctx.send(embed=embed)

        if (
            isinstance(error, commands.BadArgument)
            or isinstance(error, commands.BadUnionArgument)
            or isinstance(error, commands.MissingRequiredArgument)
        ):
            name = str(ctx.command)
            try:
                embed = Embed.warn(
                    "주의",
                    "잘못된 형식으로 명령어를 사용했어요. \n올바른 사용 : `봇 {} {}`".format(
                        name, self.argument_data[name]
                    ),
                )
                return await ctx.send(embed=embed)
            except KeyError:
                embed = Embed.warn("주의", "잘못된 형식으로 명령어를 사용했어요.")
                return await ctx.send(embed=embed)
        embed = Embed.error(
            "이런!",
            "{} 명령어 수행 중 핸들링 되지 않은 오류가 발생했어요!\n```{}```\n지속적인 문제 발생 시 `봇 문의` 명령어로 문의해주세요.".format(
                ctx.command.name, error
            ),
        )
        await ctx.send(embed=embed)
        print(
            "Ignoring exception in command {}".format(ctx.command),
            file=sys.stderr,
        )
        traceback.print_exception(
            type(error), error, error.__traceback__, file=sys.stderr
        )
        self.logger.warning(
            "Error {} occured in command {}".format(
                type(error), ctx.command.name
            )
        )
    async def currencyy(self,
                        ctx,
                        origin,
                        target,
                        how: typing.Optional[int] = 1):

        origin = origin.upper()
        target = target.upper()
        async with aiohttp.ClientSession() as session:
            async with session.get(
                    "https://free.currconv.com/api/v7/convert?q={}_{}&compact=ultra&apiKey=6bc5cad1b80bf7f58aa5"
                    .format(origin, target)) as r:
                data = await r.json()

        if data == {}:
            embed = Embed.error(title="오류",
                                description="잘못된 화폐 단위를 입력하였는지 확인해주세요.")
            await ctx.send(embed=embed)
        else:
            per = data["{}_{}".format(origin, target)]
            embed = discord.Embed(
                title="💰 {} {}".format(format(how, ","), origin),
                description="= {} {}".format(format(how * per, ","), target),
                color=0x1DC73A,
            )
            await ctx.send(embed=embed)
Exemple #3
0
    async def hangang(self, ctx):
        data = await HTTP.get("http://hangang.dkserver.wo.tc/")

        assert isinstance(data, str)
        data = json.loads(data)

        if data["result"] == "true":
            temp = data["temp"]
            chk_time = data["time"]

            embed = discord.Embed(title="🌡 한강 현재수온",
                                  description=f"{temp} °C",
                                  color=0x62BF42)
            embed.set_footer(text=f"퐁당! / {chk_time}")
        else:
            embed = Embed.error(title="오류", description="API에서 정보를 받지 못했어요!")
        await ctx.send(embed=embed)
Exemple #4
0
    async def on_command_error(self, ctx, error):
        if isinstance(error, commands.CheckFailure):
            return
        elif isinstance(error, commands.CommandNotFound):
            return

        elif isinstance(error, commands.CommandOnCooldown):
            embed = Embed.warn(
                title="⚠ 쿨타임 중!",
                description=f"{int(error.retry_after)}초 뒤에 재시도하세요.",
            )
            await ctx.send(embed=embed)

        embed = Embed.error(
            "이런!",
            "{} 명령어 수행 중 핸들링 되지 않은 오류가 발생했어요!\n```{}```\n지속적인 문제 발생 시 `봇 문의` 명령어로 문의해주세요."
            .format(ctx.command.name, error),
        )
        await ctx.send(embed=embed)
    async def time_calc(self, ctx, args):
        try:
            answer = datetime.datetime.strptime(args, "%Y-%m-%d")
            now = datetimee.datetime.now()
            dap = answer - now

            days = dap.days
            hours, remainder = divmod(dap.seconds, 3600)
            minutes, seconds = divmod(remainder, 60)

            seconds += dap.microseconds / 1e6
            embed = discord.Embed(
                title="⏲ 시간 계산",
                description=str(days) + "일 " + str(hours) + "시간 " +
                str(minutes) + "분 " + str(int(round(seconds, 0))) + "초 남았어요.",
                color=0x237CCD,
            )
            await ctx.send(embed=embed)
        except:
            embed = Embed.error("오류 발생", "`yyyy-mm-dd` 형식으로 입력하셨는지 확인해주세요.")
            await ctx.send(embed=embed)
    async def repeat(self, ctx, *, args):
        if args == "":
            embed = Embed.warn(
                title="주의",
                description="봇 따라해 `할말`로 입력해주세요!\n아무 값도 받지 못했어요.",
            )
            await ctx.channel.send(embed=embed)
            return

        if "@everyone" in args or "@here" in args:
            embed = Embed.error(
                title="경고",
                description=
                "`@everyone`이나 `@here`은 다른 사용자에게 피해를 줄 수 있어요.\n사용을 제한할께요!",
            )
            embed.set_footer(text=ctx.author, icon_url=ctx.author.avatar_url)
            await ctx.channel.send(embed=embed)
        else:
            try:
                await ctx.delete()
            except:
                pass
            await ctx.channel.send(args)
Exemple #7
0
    async def time_calc(self, ctx, *, args):
        try:
            strped_time = datetime.datetime.strptime(args, "%Y-%m-%d")
        except:
            embed = Embed.error("시간 파싱 오류", "yyyy-mm-dd 형식으로 입력해주세요!")
            await ctx.send(embed=embed)
            return

        now = datetime.datetime.now()
        dap = strped_time - now

        days = dap.days
        hours, remainder = divmod(dap.seconds, 3600)
        minutes, seconds = divmod(remainder, 60)
        seconds += dap.microseconds / 1e6

        embed = discord.Embed(
            title="⏲ 시간 계산",
            description=
            f"{days}일 {hours}시간 {minutes}분 {round(seconds)}초 {'남았어요.' if days >= 0 else '전이에요.'} ",
            color=0x237CCD,
        )

        await ctx.send(embed=embed)
    async def you_lamaed(self, ctx):
        try:
            headers = {
                "X-Naver-Client-Id": TOKEN.search_id,
                "X-Naver-Client-Secret": TOKEN.search_secret,
            }
            async with aiohttp.ClientSession(headers=headers) as session:
                async with session.get(
                        "https://openapi.naver.com/v1/search/image?query={}&display=20"
                        .format("llama")) as r:
                    c = await r.text()
                    c = json.loads(c)
                embed = discord.Embed(title="🦙",
                                      description="**YOU LLAMAED**",
                                      color=0xFF0909)
                embed.set_image(url=random.choice(c["items"])["link"])

                await ctx.send(embed=embed)
        except:
            embed = Embed.error(
                "오류 발생",
                "해당 검색어에 대한 내용을 찾을 수 없어요.",
            )
            await ctx.send(embed=embed)