Пример #1
0
    def createEmbededLs(ls, timestamp, author: str):
        status = ls["status"]
        title = KujiEmbed.getTitle(timestamp)
        imageUri = 'attachment://{}'.format(KujiUtil.getImageNameLs(status))
        title += "\n台北龍山寺觀音籤· {}\n".format(status)
        if len(ls["image"]) > 0:
            title += "{} · {}".format(ls["title"], ls["image"])
        else:
            title += "{}".format(ls["title"])
        payload = ls["payload"]
        description = "**{}**\n".format(ls["poem_line1"])
        description += "**{}**\n".format(ls["poem_line2"])
        description += "**{}**\n".format(ls["poem_line3"])
        description += "**{}**\n".format(ls["poem_line4"])
        description += "\n詩意:\n{}\n".format(ls["meaning"])
        description += "\n解曰:\n{}\n".format(ls["explain"])
        if len(payload) > 0:
            description += "\n聖意:\n"

        embedMsg = Embed(title=title,
                         description=description,
                         color=KujiUtil.getColorLs(status))
        embedMsg.set_author(name=author)
        embedMsg.set_thumbnail(url=imageUri)
        embedMsg.set_image(url=ls["url"])
        for key in payload:
            embedMsg.add_field(name=key, value=payload[key], inline=True)
        return embedMsg
Пример #2
0
 async def draw_cn(self, ctx: commands.Command, *argv):
     if not KujiUtil.canDrawCn(ctx.author.id):
         await ctx.reply("親愛的員工, 你今天已經抽過易經了哦! 每人一天只限一次.")
         return
     if not await self.checkToken(ctx):
         return
     random.seed(random.random())
     yiIndex = KujiUtil.getYi()
     yi = KujiUtil.getTargetedYi(yiIndex[0], yiIndex[1])
     await ctx.reply(embed=KujiEmbed.createEmbededCn(
         yi, datetime.now(), f"{self.bot.user.name} - 抽籤遊戲"))
     KujiUtil.updateMemberCn(ctx.author.id, yiIndex[0], yiIndex[1])
Пример #3
0
    def test_clearData(self):
        KujiUtil.updateMemberJp(1, 1)
        KujiUtil.clearData()
        assert KujiUtil.canDrawJp(1)

        KujiUtil.updateMemberCn(1, 1, 2)
        assert not KujiUtil.canDrawCn(1)
Пример #4
0
    async def get_history(self, ctx: commands.Command, *argv):
        historyJp = KujiUtil.getHistoryJp(ctx.author.id)
        historyCn = KujiUtil.getHistoryCn(ctx.author.id)
        historyLs = KujiUtil.getHistoryLs(ctx.author.id)
        if (-1, None) == historyJp and (-1, None) == historyLs and (
                -1, -1, None) == historyCn:
            await ctx.reply("親愛的員工, 你還沒抽過籤呢! 先試著抽一個看看?.")
        if not (-1, None) == historyLs:
            ls = LUNGSHAN[historyLs[0]]
            status = ls["status"]
            img = File(KujiUtil.getImageUrlLs(status),
                       filename=KujiUtil.getImageNameLs(status))
            await ctx.reply(file=img,
                            embed=KujiEmbed.createEmbededLs(
                                ls, datetime.now(),
                                f"{self.bot.user.name} - 抽籤遊戲"))

        if not (-1, None) == historyJp:
            kuji = OMIKUJI[historyJp[0]]
            imagePath = KujiUtil.generageImageForJp(KujiObj(kuji))
            img = File(imagePath, filename=KujiUtil.getKujiImageName())
            await ctx.reply(file=img,
                            embed=KujiEmbed.createEmbededJp(
                                kuji, historyJp[1],
                                f"{self.bot.user.name} - 抽籤遊戲"))

        if not (-1, -1, None) == historyCn:
            yi = KujiUtil.getTargetedYi(historyCn[0], historyCn[1])
            await ctx.reply(embed=KujiEmbed.createEmbededCn(
                yi, historyCn[2], f"{self.bot.user.name} - 抽籤遊戲"))
Пример #5
0
 async def draw_jp(self, ctx: commands.Command, *argv):
     if not KujiUtil.canDrawJp(ctx.author.id):
         await ctx.reply("親愛的員工, 你今天已經抽過清水寺籤了哦! 每人一天只限一次.")
         return
     if not await self.checkToken(ctx):
         return
     random.seed(random.random())
     index = random.randint(0, 98)
     kuji = OMIKUJI[index]
     imagePath = KujiUtil.generageImageForJp(KujiObj(kuji))
     img = File(imagePath, filename=KujiUtil.getKujiImageName())
     await ctx.reply(file=img,
                     embed=KujiEmbed.createEmbededJp(
                         kuji, datetime.now(),
                         f"{self.bot.user.name} - 抽籤遊戲"))
     KujiUtil.updateMemberJp(ctx.author.id, index)
Пример #6
0
 async def draw_ls(self, ctx: commands.Command, *argv):
     if not KujiUtil.canDrawLs(ctx.author.id):
         await ctx.reply("親愛的員工, 你今天已經抽過龍山寺籤了哦! 每人一天只限一次.")
         return
     if not await self.checkToken(ctx):
         return
     random.seed(random.random())
     index = random.randint(0, 98)
     ls = LUNGSHAN[index]
     status = ls["status"]
     img = File(KujiUtil.getImageUrlLs(status),
                filename=KujiUtil.getImageNameLs(status))
     await ctx.reply(file=img,
                     embed=KujiEmbed.createEmbededLs(
                         ls, datetime.now(),
                         f"{self.bot.user.name} - 抽籤遊戲"))
     KujiUtil.updateMemberLs(ctx.author.id, index)
Пример #7
0
 def createEmbededCn(yi, timestamp, author: str):
     title = KujiEmbed.getTitle(timestamp)
     title += "\n易經 · {} · {} {}".format(yi["name"], yi["shape"],
                                         yi["symbol"])
     embedMsg = Embed(title=title,
                      description=yi["description"],
                      color=KujiUtil.getYiColor(yi["name"]))
     embedMsg.set_author(name=author)
     payload = yi["payload"]
     for key in payload:
         embedMsg.add_field(name=key, value=payload[key], inline=True)
     return embedMsg
Пример #8
0
 def createEmbededJp(kuji, timestamp, author: str):
     status = kuji["status"]
     title = KujiEmbed.getTitle(timestamp)
     imageUri = 'attachment://{}'.format(KujiUtil.getKujiImageName())
     title += "\n東京淺草觀音寺御神籤· {}籤 · {}".format(kuji["title"], status)
     description = "{}\n".format(kuji["poem_line1"])
     description += "`{}`\n".format(kuji["poem_line1_explain"])
     description += "{}\n".format(kuji["poem_line2"])
     description += "`{}`\n".format(kuji["poem_line2_explain"])
     description += "{}\n".format(kuji["poem_line3"])
     description += "`{}`\n".format(kuji["poem_line3_explain"])
     description += "{}\n".format(kuji["poem_line4"])
     description += "`{}`\n".format(kuji["poem_line4_explain"])
     embedMsg = Embed(title=title,
                      description=description,
                      color=KujiUtil.getColor(status))
     embedMsg.set_author(name=author)
     embedMsg.set_image(url=imageUri)
     payload = kuji["payload"]
     for key in payload:
         embedMsg.add_field(name=key, value=payload[key], inline=True)
     return embedMsg
Пример #9
0
    def test_getHistoryCn(self):
        KujiUtil.updateMemberCn(1, 1, 2)
        history = KujiUtil.getHistoryCn(1)

        assert history[0] == 1
        assert history[1] == 2
Пример #10
0
    def test_getHistoryLs(self):
        KujiUtil.updateMemberLs(1, 1)
        history = KujiUtil.getHistoryLs(1)

        assert history[0] == 1
Пример #11
0
 def test_canDraw_false(self):
     KujiUtil.updateMemberJp(1, 1)
     KujiUtil.updateMemberCn(1, 0, 0)
     KujiUtil.updateMemberLs(1, 1)
     assert not KujiUtil.canDrawLs(1)
Пример #12
0
 def test_canDrawLs_false(self):
     KujiUtil.updateMemberLs(1, 1)
     assert not KujiUtil.canDrawLs(1)
Пример #13
0
 def test_canDrawCn_false(self):
     KujiUtil.updateMemberCn(1, 0, 0)
     assert not KujiUtil.canDrawCn(1)
Пример #14
0
 def test_canDrawJp_false(self):
     KujiUtil.updateMemberJp(1, 1)
     assert not KujiUtil.canDrawJp(1)
Пример #15
0
 def test_canDraw_true(self):
     assert KujiUtil.canDrawJp(1)
     assert KujiUtil.canDrawCn(1)
     assert KujiUtil.canDrawLs(1)
Пример #16
0
 async def clear_db(self, ctx: commands.Command, *argv):
     KujiUtil.clearData()