async def test_member_talk_on_privateChannel(self):
     wrong_id = 97979797979
     ChannelUtil.setRankupChannel(self.fake_guild.id, self.fake_guild.channels[1].id)
     fake_message = FakeMessage(author= self.fake_member, content= 'anyway')
     self.fake_guild.id =wrong_id
     await self.target.profile_on_message(fake_message)
     assert self.fake_guild.messageLast == None
 async def test_member_second_talk(self):
     ChannelUtil.setRankupChannel(self.fake_guild.id, self.fake_guild.channels[1].id)
     fake_message = FakeMessage(channel= self.fake_guild.channels[0], author= self.fake_member, content= 'anyway')
     await self.target.profile_on_message(fake_message)
     self.fake_guild.messageLast = None
     await self.target.profile_on_message(fake_message)
     assert self.fake_guild.messageLast == None
Example #3
0
 def __init__(self, dbFile=r"./common/KFP_bot.db"):
     self.sqliteDb = SqliteDatabase(dbFile)
     KfpMigrator.KfpMigrate(self.sqliteDb)
     db.proxy.initialize(self.sqliteDb)
     self.sqliteDb.create_tables(MODULES)
     self.__ignoreXpChannel = ChannelUtil.getXPIgnoredChannels()
     self.__autoClearChannel = ChannelUtil.getAutoClearChannels()
Example #4
0
 def test_setChannel(self):
     ChannelUtil.setChannel(123, 321, Util.ChannelType.RANK_UP)
     result: Channel = ChannelUtil.GetChannelWithGuild(
         123, Util.ChannelType.RANK_UP)[0]
     assert result.channel_id == 321
     assert result.channel_guild_id == 123
     assert result.channel_type == Util.ChannelType.RANK_UP.value
 async def command_control_add(self, ctx: commands.Context, command: str):
     if not self.__hasCommand__(command):
         await ctx.send(f"指令{command}錯誤, 請檢查拼寫是否正確.")
         return
     commandEnum = Util.ChannelType[command.upper()]
     ChannelUtil.addChannel(ctx.guild.id, ctx.channel.id, commandEnum)
     print(
         f"Adding channel {ctx.channel.id} to type {commandEnum.name} succeed!"
     )
Example #6
0
 async def keep_clear_disable_command(self, ctx: commands.Context, *argv):
     if ctx.channel == None:
         await ctx.author.send("請在頻道中設置這個指令")
         return
     if ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                               Util.ChannelType.AUTO_DELETE):
         ChannelUtil.removeChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.AUTO_DELETE)
         await ctx.channel.send('取消這個頻道自動刪除成員留言功能')
         self.database.remove_ignore_xp_channel(ctx.guild.id,
                                                ctx.channel.id)
Example #7
0
 def getReviveMsgChannel(status: RPGStatus):
     result = []
     for status in status:
         channel = ChannelUtil.GetChannelWithGuild(
             status.guild_id, Util.ChannelType.RPG_BATTLE_GROUND)
         for ch in channel:
             # if is not test channel
             if not ChannelUtil.hasChannel(status.guild_id, ch.channel_id,
                                           Util.ChannelType.BANK):
                 if not (ch.channel_id in result):
                     result.append(ch.channel_id)
     return result
Example #8
0
async def command_restart(ctx, *attr):
    db = KfpDb()
    ChannelUtil.setRebootMessageChannel(guild_id=ctx.guild.id,
                                        channel_id=ctx.channel.id)
    await ctx.send("現在版本 {}, 檢查更新中...".format(get_version()))
    tmpFile = getTempFile()
    tmpFile.touch()
    f = open(tmpFile, "a")
    f.write(f"{ctx.guild.id}.")
    f.write(f"{os.getpid()}")
    f.close()

    Popen([os.sep.join((os.getcwd(), "update_and_restart.sh"))], shell=True)
Example #9
0
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print(' --  --  -- ')

    tmpFile = getTempFile()
    if tmpFile.exists():
        print(tmpFile)
        f = open(tmpFile, 'r')
        line = f.read().split(".")
        guild_id = int(line[0])
        pid = int(line[1])
        f.close()
        os.remove(tmpFile.absolute())
        try:
            os.kill(pid, signal.SIGKILL)
        except OSError:
            print(f"pid {pid} is not found. Ignore")
        else:
            print("restart successful, sending success message")
        db = KfpDb()
        channel: Channel = ChannelUtil.getRebootMessageChannel(guild_id)
        if channel:
            await bot.get_channel(channel.channel_id
                                  ).send("更新結束, 現在版本 {}".format(get_version()))
    refreshStatus.start()
    reviveComaStatus.start()
Example #10
0
    async def sneak_attack_character(self, ctx: commands.Context, user: User):
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                      Util.ChannelType.RPG_BATTLE_GROUND):
            return
        if not RPGCharacterUtil.hasAdventureStared(ctx.author.id):
            await ctx.send("看起來你還沒開始你的旅程呢. 請先申請成為冒險者吧")
            return
        if not RPGCharacterUtil.hasAdventureStared(user.id):
            await ctx.send("看起來對方不是冒險者呢. 請不要偷襲平民")
            return
        author: RPGCharacter = RPGCharacterUtil.getRPGCharacter(ctx.author.id)
        other: RPGCharacter = RPGCharacterUtil.getRPGCharacter(user.id)
        author_name = await NicknameUtil.get_user_name(ctx.guild, ctx.author)
        name = await NicknameUtil.get_user_name(ctx.guild, user)
        guild = self.bot.get_guild(ctx.guild.id)
        member = guild.get_member(user.id)

        if StatusUtil.isResting(ctx.author, ctx.guild.id):
            await ctx.send("你正在休息. 偷襲無效.")
            return
        if StatusUtil.isComa(user, ctx.guild.id):
            await ctx.send(f"哎不是! '{name}'都已經昏厥了你還偷襲? 偷襲無效啦!")
            return
        if StatusUtil.isComa(ctx.author, ctx.guild.id):
            await ctx.send(f"你都沒有體力了! 要怎麼偷襲! 偷襲無效.")
            return
        if author.character.member_id == user.id:
            dead = RPGCharacterUtil.changeHp(other, -1 * author.hp_max)
            if dead:
                StatusUtil.createComaStatus(ctx.guild.id, user, other.hp_max)
            await ctx.send(f"{name} 查覺到自己的行為, 但是阻止不了自己偷襲自己. 於是流血過多而昏厥過去. 攻擊成功")
            return
        if StatusUtil.isAlerted(user, ctx.guild.id):
            await ctx.send(f"由於已經被偷襲過, '{name}'現在非常警戒並擋下了你的攻擊! 攻擊失敗!")
            msg = f"注意!{author_name}企圖偷襲你但是被你識破了!"
            await member.send(msg)
            return

        # try to sneak attack
        success = random.randint(0, 1) == 0
        if success:
            multiplier = [2, 2, 2, 2, 2, 2, 8, 8, 10, 20]
            random_index = random.randrange(len(multiplier))
            atk = RPGCharacterUtil.getAttackPoint(
                author) * multiplier[random_index]
            dead = RPGCharacterUtil.changeHp(other, -1 * atk)
            if dead:
                StatusUtil.createComaStatus(ctx.guild.id, user, other.hp_max)
            RPGCharacterUtil.attackSuccess(author)
            await ctx.send(f"'{name}' 減少了 {atk}點體力. 偷襲成功!")

            if StatusUtil.isComa(user, ctx.guild.id):
                await ctx.send(f"由於你的攻擊, '{name}'生命力歸零昏厥了過去")
            # sent a message let member know is being attack
            msg = f"注意!你被{author_name}偷襲了!"
            await member.send(msg)
        else:
            await ctx.send(f"由於你的腳步聲太大, '{name}'注意到並擋下了你的攻擊! 攻擊失敗!")
        # the other person is now alerted
        StatusUtil.createOrUpdateAlertStatus(member.id, ctx.guild.id, 86400)
Example #11
0
 async def force_update(self, ctx: commands.Context):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.RPG_GUILD):
         return
     results = StatusUtil.getAllStatus(StatusType.REST)
     rest_over = []
     now = datetime.now()
     status: RPGStatus
     for status in results:
         if status.expire_time < now:
             rest_over.append(status)
     msg = f"目前休息中的人為 {len(results)}人\n"
     msg += f"可以解除休息的人數為 {len(rest_over)}人\n"
     if len(rest_over) > 0:
         msg += f"解除休息中..."
     await ctx.send(msg)
     for status in rest_over:
         character = RPGCharacterUtil.getRPGCharacter(status.member_id)
         user = self.bot.get_user(status.member_id)
         name = await NicknameUtil.get_user_name(ctx.guild, user)
         if character == None:
             msg = f"找不到人物{status.member_id}, 刪除舊狀態..."
         else:
             msg = f"刪除'{name}'的休息狀態..."
             RPGCharacterUtil.changeHp(character, status.buff.buff_value)
         await ctx.send(msg)
         status.delete_instance()
         await ctx.send(f"'{name}'的休息狀態成功")
Example #12
0
 async def profile_on_message(self, message: Message):
     if message.author.bot:
         return
     if message.channel == None or not message.channel.guild.id in whitelist or message.author.bot:
         return
     if self.populateChannels(message, self.isTest):
         return
     if not self.channelAllowed(message.channel.id, self.isTest):
         return
     member: Member = self.db.get_member(message.author.id)
     if not member:
         self.db.add_member(message.author.id)
         member = self.db.get_member(message.author.id)
     increaseNumber = randint(10, 25)
     rank = self.db.increase_exp(message.channel.guild.id,
                                 message.channel.id, message.author.id,
                                 increaseNumber)
     assert rank > 0, 'method increase_xp should not retrun less than 1 in profile_on_message'
     if member.rank != rank:
         channel = ChannelUtil.getMessageChannelId(message.guild.id)
         if channel == None:
             channelToUse = message.channel
         else:
             channelToUse = message.guild.get_channel(channel)
         RPGCharacterUtil.levelUpCharacter(message.author.id, member.rank,
                                           rank)
         await channelToUse.send('恭喜<@{}> 等級提升至{}。'.format(
             message.author.id, rank))
         await self.updateUserKfpRoles(message, rank, channelToUse)
     self.db.increase_coin(message.guild.id, message.author.id,
                           increaseNumber)
 async def test_bind_command(self):
     wrong_id = 787878787
     fakecontext = FakeContext(client= self.fake_guild, author = self.fake_member, channel= self.fake_guild.channels[0])
     await self.target.profile_group_bind_command(self.target, fakecontext)
     assert self.fake_guild.messageLast.content == '<@!{}> 設定升級訊息將會於此。'.format(self.fake_member.id)
     assert self.fake_guild.messageLast.channel.id == self.fake_guild.channels[0].id , 'check message chennal'
     assert ChannelUtil.getMessageChannelId(self.fake_guild.id) != None , 'check database'
Example #14
0
 async def bank_group(self, ctx: commands.Context):
     if ctx.author.bot:
         return
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id, Util.ChannelType.BANK):
         return
     member = MemberUtil.get_or_add_member(self.bot.user.id)
     await ctx.send(f"目前銀行有 {member.coin}枚硬幣.")
Example #15
0
    async def init_rpg_character(self, ctx: commands.Context):
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                      Util.ChannelType.RPG_GUILD):
            return
        if RPGCharacterUtil.hasAdventureStared(ctx.author.id):
            await ctx.send("你的冒險已經啟程")
            return

        member: Member = MemberUtil.get_or_add_member(ctx.author.id)
        if member.coin < 5000:
            await ctx.send(f"看來你的硬幣不足呢, 先在群裡說說話賺取經驗吧.")
            return

        isNew = True
        if RPGCharacterUtil.getRPGCharacter(ctx.author.id) != None:
            isNew = False
        if RPGCharacterUtil.createNewRPGCharacter(ctx.author.id) != None:
            user = self.bot.get_user(ctx.author.id)
            name = await NicknameUtil.get_user_name(ctx.guild, user)
            MemberUtil.add_coin(ctx.author.id, -5000)
            MemberUtil.add_coin(ctx.bot.user.id, 5000)
            if isNew:
                await ctx.send(f"歡迎冒險者'{name}'的加入, 從現在開始你的冒險之旅吧!")
            else:
                await ctx.send(f"歡迎回來'{name}', 已恢復您冒險者的身分!")
            return

        await ctx.send(f"看起來你的行李好像還沒準備好, 詳情請洽冒險者公會員工.")
Example #16
0
 async def keep_clear_list_command(self, ctx: commands.Context, *argv):
     if ctx.guild == None:
         await ctx.author.send("請在伺服器中呼叫這個指令")
         return
     result = ''
     autoDeleteList = ChannelUtil.GetChannelWithGuild(
         ctx.guild.id, Util.ChannelType.AUTO_DELETE)
     channel: Channel
     for channel in autoDeleteList:
         if ctx.uild.get_channel(channel.channel_id) != None:
             result += '<#{}>'.format(channel.channel_id)
     await ctx.channel.send(result)
Example #17
0
 async def draft_character(self, ctx: commands.Context, user: User):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.RPG_GUILD):
         return
     name = await NicknameUtil.get_user_name(ctx.guild, user)
     if RPGCharacterUtil.hasAdventureStared(user.id):
         await ctx.send(f"'{name}'已經是冒險者了, 不需要再招募.")
         return
     if RPGCharacterUtil.createNewRPGCharacter(user.id) != None:
         await ctx.send(f"非常感謝, '{name}'現在已經在冒險者公會登記為冒險者了!")
         return
     await ctx.send(f"看起來招募中心已滿, 詳情請洽冒險者公會員工.")
Example #18
0
    async def attack_character(self, ctx: commands.Context, user: User):
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                      Util.ChannelType.RPG_BATTLE_GROUND):
            return
        if not RPGCharacterUtil.hasAdventureStared(ctx.author.id):
            await ctx.send("看起來你還沒開始你的旅程呢. 請先申請成為冒險者吧")
            return
        if not RPGCharacterUtil.hasAdventureStared(user.id):
            await ctx.send("看起來對方不是冒險者呢. 請不要攻擊平民")
            return
        author: RPGCharacter = RPGCharacterUtil.getRPGCharacter(ctx.author.id)
        other: RPGCharacter = RPGCharacterUtil.getRPGCharacter(user.id)
        author_name = await NicknameUtil.get_user_name(ctx.guild, ctx.author)
        name = await NicknameUtil.get_user_name(ctx.guild, user)
        guild = self.bot.get_guild(ctx.guild.id)
        member = guild.get_member(user.id)

        if StatusUtil.isResting(ctx.author, ctx.guild.id):
            await ctx.send("你正在休息. 攻擊無效.")
            return
        if StatusUtil.isComa(user, ctx.guild.id) or StatusUtil.isResting(
                user, ctx.guild.id):
            await ctx.send(f"哎不是! '{name}'都已經昏厥了你還攻擊? 攻擊無效啦!")
            return
        if StatusUtil.isResting(user, ctx.guild.id):
            await ctx.send(f"卑鄙源之助! '{name}'正在休息你還攻擊? 攻擊無效啦!")
            return
        if StatusUtil.isComa(ctx.author, ctx.guild.id):
            await ctx.send(f"你都沒有體力了! 先去休息啦! 攻擊無效.")
            return
        if author.character.member_id == user.id:
            dead = RPGCharacterUtil.changeHp(other, -1 * author.hp_max)
            if dead:
                StatusUtil.createComaStatus(guild_id=ctx.guild.id,
                                            user=user,
                                            hp_max=other.hp_max)
            await ctx.send(f"{name} 決定朝自己的腹部捅一刀, 因為流血過多而昏厥過去了. 攻擊成功")
            return
        if RPGCharacterUtil.tryToAttack(author, other):
            atk = RPGCharacterUtil.getAttackPoint(author)
            dead = RPGCharacterUtil.changeHp(other, -1 * atk)
            if dead:
                StatusUtil.createComaStatus(ctx.guild.id, user, other.hp_max)
            RPGCharacterUtil.attackSuccess(author)
            await ctx.send(f"'{name}' 減少了 {atk}點體力. 攻擊成功!")

            if StatusUtil.isComa(user, ctx.guild.id):
                await ctx.send(f"由於你的攻擊, '{name}'生命力歸零昏厥了過去")
            # sent a message let member know is being attack
            msg = f"注意!你被{author_name}攻擊了!"
            await member.send(msg)
        else:
            await ctx.send(f"'{name}'成功的擋下了你的攻擊! 攻擊失敗!")
 async def command_control_remove(self, ctx: commands.Context,
                                  command: str):
     if not self.__hasCommand__(command):
         await ctx.send(f"指令{command}錯誤, 請檢查拼寫是否正確.")
     commandEnum = Util.ChannelType[command.upper()]
     result = ChannelUtil.removeChannel(ctx.guild.id, ctx.channel.id,
                                        commandEnum)
     if result:
         print(
             f"Success!: remove channel {ctx.channel.name} for '{commandEnum.name}'."
         )
     else:
         print(
             f"FAILED!!: cannot remove channel {ctx.channel.name} for command '{commandEnum.name}'."
         )
Example #20
0
 async def revive_rpg_character(self, ctx: commands.Command, user: User):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.BANK):
         return
     if not RPGCharacterUtil.hasAdventureStared(user.id):
         await ctx.send("看起來對方不是冒險者呢. 無法回血")
         return
     other: RPGCharacter = RPGCharacterUtil.getRPGCharacter(user.id)
     author: RPGCharacter = RPGCharacterUtil.getRPGCharacter(ctx.author.id)
     name = await NicknameUtil.get_user_name(ctx.guild, user)
     if author.character.member_id == user.id:
         await ctx.send(f"此功能不是拿來幫你自己加血的, 請不要濫用職權.")
         return
     RPGCharacterUtil.changeHp(other, other.hp_max)
     await ctx.send(f"{name}生命值回復成功.")
Example #21
0
 async def revive_all(self, ctx: commands.Command):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.BANK):
         return
     statusUpdates = StatusUtil.reviveComaStatus(reviveMemberCount=0)
     if statusUpdates != []:
         channelIdList = ReviveUtil.getReviveMsgChannel(statusUpdates)
         msg = "某冥界死神跑來跟店長抱怨公會死傷慘重, 害她最近工作變忙"
         img = ReviveUtil.getPic()
         for channel_id in channelIdList:
             await self.bot.get_channel(channel_id).send(file=img)
             await self.bot.get_channel(channel_id).send(msg)
         update: StatusUpdate
         for update in statusUpdates:
             await update.sendMessage(self.bot)
 async def command_control_list(self, ctx: commands.Context, command: str):
     if not self.__hasCommand__(command):
         await ctx.send(f"指令{command}錯誤, 請檢查拼寫是否正確.")
     commandEnum = Util.ChannelType[command.upper()]
     channels = ChannelUtil.GetChannelWithGuild(ctx.guild.id, commandEnum)
     if len(channels) < 1:
         await ctx.send(f"指令'{command}'沒有設定任何的可執行頻道.")
     else:
         channel: Channel
         result = f"目前指令'{command}'可以在以下頻道執行:\n"
         result += "```"
         for channel in channels:
             c = self.bot.get_channel(channel.channel_id)
             result += f"{c.name}\n"
         result += "```"
         await ctx.send(result)
Example #23
0
 async def betting_keep_clear_group(self, ctx: commands.Context, *argv):
     if ctx.channel == None:
         await ctx.author.send("請在頻道中設置這個指令")
         return
     if not self.database.has_channel(ctx.guild.id, ctx.channel.id,
                                      Util.ChannelType.AUTO_DELETE):
         result = ChannelUtil.setChannel(ctx.guild.id, ctx.channel.id,
                                         Util.ChannelType.AUTO_DELETE)
         if result:
             await ctx.channel.send('這個頻道將開始自動刪除接下來的所有成員留言')
             self.database.set_ignore_xp_channel(ctx.guild.id,
                                                 ctx.channel.id)
         else:
             await ctx.channel.send('這個頻道已經開啟自動刪除')
     else:
         await ctx.channel.send('這個頻道已經開啟自動刪除')
Example #24
0
 async def retire_rpg_character(self, ctx: commands.Context):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                   Util.ChannelType.RPG_GUILD):
         return
     if not RPGCharacterUtil.hasAdventureStared(ctx.author.id):
         await ctx.send("看起來你還沒開始你的旅程呢. 在開始前就放棄的概念?")
         return
     if StatusUtil.isResting(ctx.author, ctx.guild.id):
         await ctx.send("你正在休息. 休息的人是不會申請退休的(~~除非你在夢遊~~).")
         return
     author: RPGCharacter = RPGCharacterUtil.getRPGCharacter(ctx.author.id)
     if StatusUtil.isComa(ctx.author, ctx.guild.id):
         await ctx.send(f"你都沒有體力了! 先去休息啦!")
         return
     if author.last_attack + timedelta(hours=12) > datetime.now():
         await ctx.send(f"由於你在過去12個小時內攻擊過其他人, 所以不能退休哦")
         return
     RPGCharacterUtil.retireRPGCharacter(ctx.author.id)
     await ctx.send(f"冒險者{ctx.author.display_name}申請退休成功, 辛苦你了!")
Example #25
0
    async def profile_group(self, ctx: commands.Context, *attr):
        if not isWhiteList(ctx):
            if ctx.guild:
                print(
                    "{} is not on white list, if you are a developer, add your server to the white list"
                    .format(ctx.guild.id))
            return
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id,
                                      Util.ChannelType.PROFILE):
            print(
                "WARNING: cannot run on this channel, if you are a developer, try to use '!commandControll add profile'"
            )
            return
        memberRow: Member = self.db.get_member(ctx.author.id)
        if memberRow == None:
            self.db.add_member(ctx.author.id)
            memberRow = self.db.get_member(ctx.author.id)

        profileByte = None
        iconData = None
        bgData = None
        avatar_url = ctx.author.avatar_url_as(format='jpg', size=1024)
        if avatar_url._url != None:
            iconData = await avatar_url.read()
        banner_url = ctx.guild.banner_url
        if banner_url._url != None:
            bgData = await banner_url.read()
        with ProfileImage() as pf:
            if iconData:
                pf.setIcon(iconData)
            if bgData:
                pf.setBackGround(bgData)
            pf.setCoin(memberRow.coin)
            pf.setXp(memberRow.exp)
            pf.setLevelNumber(memberRow.rank)
            pf.setRankNumber(self.db.get_member_rank_order(ctx.author.id))
            pf.setMemberName(ctx.author.display_name, ctx.author.name)
            profileByte = pf.generateProfileImage()

        discordFile = discord.File(io.BytesIO(profileByte),
                                   filename='profile.png')
        await ctx.channel.send(file=discordFile)
Example #26
0
    async def bank_remove(self, ctx: commands.Context, coins: int, user: User):
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id, Util.ChannelType.BANK):
            return
        if coins < 1:
            await ctx.send("請不要來亂的好嗎?")
            return
        member = MemberUtil.get_or_add_member(self.bot.user.id)
        nick = await NicknameUtil.get_user_nickname_or_default(ctx.guild, user)
        if member.coin < coins:
            await ctx.send(f"'{nick}'擁有餘額: {member.coin}. 不足以扣除 {coins}")
            return
        MemberUtil.add_coin(self.bot.user.id, coins)
        MemberUtil.add_coin(user.id, -1 * coins)
        bank = MemberUtil.get_or_add_member(self.bot.user.id)
        message = f"扣除'{nick}'的硬幣 '{coins}'並充公成功! 目前餘額為\n"
        message += "```"
        message += f"銀行: {bank.coin}\n"
        message += f"{nick}: {member.coin}\n"
        message += "```"

        await ctx.send(message)
Example #27
0
    async def bank_pay(self, ctx: commands.Context, coins: int, user: User):
        if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id, Util.ChannelType.BANK):
            return
        bank = MemberUtil.get_or_add_member(self.bot.user.id)
        if coins < 1:
            await ctx.send("請不要來亂的好嗎?")
            return
        nick = await NicknameUtil.get_user_nickname_or_default(ctx.guild, user)
        if bank.coin < coins:
            await ctx.send(f"銀行餘額: {bank.coin} 不足以支付 {coins} 給 {nick}")
            return
        MemberUtil.add_coin(self.bot.user.id, -1 * coins)
        MemberUtil.add_coin(user.id, coins)
        member = MemberUtil.get_member(user.id)
        message = f"金額 {coins} 付款給 {nick}成功! 雙方餘額為\n"
        message += "```"
        message += f"銀行: {bank.coin}\n"
        message += f"{nick}: {member.coin}\n"
        message += "```"

        await ctx.send(message)
Example #28
0
 def test_setRankupChannel_notExist(self):
     assert not ChannelUtil.getMessageChannelId(123)
Example #29
0
 async def bank_add(self, ctx: commands.Context, coins: int):
     if not ChannelUtil.hasChannel(ctx.guild.id, ctx.channel.id, Util.ChannelType.BANK):
         return
     MemberUtil.add_coin(self.bot.user.id, coins)
     bank = MemberUtil.get_member(self.bot.user.id)
     await ctx.send(f"新增 {coins}枚硬幣至銀行: 成功!\n銀行餘額: {bank.coin}")        
Example #30
0
    def test_setRankupChannel(self):
        ChannelUtil.setRankupChannel(0, 123)
        assert ChannelUtil.getMessageChannelId(0) == 123

        ChannelUtil.setRankupChannel(0, 456)
        assert ChannelUtil.getMessageChannelId(0) == 456