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}枚硬幣.")
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"看起來你的行李好像還沒準備好, 詳情請洽冒險者公會員工.")
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}'的休息狀態成功")
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)
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)
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
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"看起來招募中心已滿, 詳情請洽冒險者公會員工.")
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 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 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}生命值回復成功.")
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}申請退休成功, 辛苦你了!")
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)
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)
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)
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}")