async def fireball(self, ctx): user_id, channel_id = ctx.message.author.id, ctx.message.channel.id player_hp, error_message = await battle.Battle(self.bot).into_battle( user_id, channel_id) if error_message: return await ctx.send(error_message) if not consume_an_item(user_id, 2): return await ctx.send(f"<@{user_id}>はファイアボールの書を持っていない!") player_level = status.get_player_level(user_id) boss_lv, boss_hp, boss_id = battle.get_boss(ctx) player_attack = int(player_level * (1 + random.random()) / 10) boss_hp = boss_hp - player_attack monster = monsters.get(boss_lv, boss_id)[1] monster_name = monster["name"] attack_message = "ファイアボール!<@{}>は{}に`{}`のダメージを与えた!".format( user_id, monster_name, player_attack) if boss_hp <= 0: win_message = battle.win_process(channel_id, boss_lv, monster_name) await ctx.send("{}\n{}".format(attack_message, win_message)) await battle.reset_battle(ctx, level_up=True) else: db.boss_status.update(boss_hp, channel_id) await ctx.send("{}\n{}のHP:`{}`/{}".format(attack_message, monster_name, boss_hp, boss_lv * 10 + 50)) await battle.Battle(self.bot).effect(ctx, monster)
async def _attack(self, ctx): user_id = ctx.author.id channel_id = ctx.channel.id player_hp, error_message = await battle.Battle(self.bot).into_battle( user_id, channel_id) if error_message: return await ctx.send(embed=Embed(description=error_message)) player_level = status.get_player_level(user_id) boss_level, boss_hp, boss_id = battle.get_boss(ctx) rand = random.random() player_attack = battle.get_player_attack(player_level, boss_level, boss_id, rand) boss_hp = boss_hp - player_attack from module import monsters monster_name = monsters.get(boss_level, boss_id)[1]["name"] attack_message = battle.get_attack_message(user_id, player_attack, monster_name, rand) if boss_hp <= 0: win_message = battle.win_process(channel_id, boss_level, monster_name) await ctx.send(embed=Embed( description="{}\n{}".format(attack_message, win_message))) await battle.reset_battle(ctx, level_up=True) else: db.boss_status.update(boss_hp, channel_id) boss_attack_message = battle.boss_attack_process( ctx, player_hp, player_level, monster_name) monster = monsters.get(boss_level, boss_id)[1] monster["HP"] = monster["HP"].replace("boss_level", str(boss_level)) effect = await battle.Battle(self.bot).effect(ctx, monster) await ctx.send(embed=Embed( description="{}\n - {}のHP:`{}`/{}\n\n{}".format( attack_message, monster_name, boss_hp, calc(monster["HP"]), boss_attack_message) + effect))
async def t(self, ctx): """トレーニングをする""" user = ctx.message.author if user.bot: return q_id = random.randint(0, 619) answer = training_set[q_id][1] exp = math.ceil(status.get_player_level(user.id) / 8) ischeat = [False] def cheat(m): ischeat[0] = True - (m.author.id == 574476415467257866) / 5 return False await ctx.send(embed=discord.Embed( description="「{}」の読み方をひらがなで答えなさい。".format( training_set[q_id][0])).set_author(name="四字熟語トレーニング")) try: guess = await self.bot.wait_for( 'message', timeout=15.0, check=(lambda m: answer in m.content and m.author != user and cheat(m) or m.author == user)) except asyncio.TimeoutError: await ctx.send(embed=discord.Embed( description='時間切れだ。正解は「{}」だ。'.format(answer))) return exp = int(exp / (pow(ischeat[0], 10) * 3 + 1)) if guess.content == answer: comment = status.experiment(user.id, exp) if random.random() < 0.005 / (ischeat[0] * 9 + 1): comment += "\n`エリクサー`を手に入れた!" item.obtain_an_item(user.id, 1) if random.random() < 0.1 / (ischeat[0] * 9 + 1): comment += "\n`ファイアボールの書`を手に入れた!" item.obtain_an_item(user.id, 2) if random.random() < 0.1 / (ischeat[0] * 9 + 1): comment += "\n`祈りの書`を手に入れた!" item.obtain_an_item(user.id, 3) await ctx.send(embed=discord.Embed( description='正解だ!{}の経験値を得た。\n{}'.format(exp, comment))) else: await ctx.send(embed=discord.Embed( description='残念!正解は「{}」だ。'.format(answer)))
async def into_battle(self, user_id, channel_id): error_message = "" player_level = status.get_player_level(user_id) in_battle = db.player.hp.get(user_id) if not in_battle: player_hp = player_level * 5 + 50 # player_max_hp db.player.hp.set(user_id, channel_id, player_hp) return player_hp, error_message in_battle_channel_id = in_battle[0] battle_channel = self.bot.get_channel(in_battle_channel_id) if not battle_channel: # if deleted the battle_channel player_hp = player_level * 5 + 50 db.channel.not_found(in_battle_channel_id, channel_id, user_id, player_hp) return player_hp, error_message player_hp = in_battle[1] if in_battle_channel_id != channel_id: error_message = f"<@{user_id}>は'{battle_channel.guild.name}の{battle_channel.mention}'で既に戦闘中だ。" elif player_hp == 0: error_message = "<@{}>はもうやられている!(戦いをやり直すには「{}reset」だ)".format( user_id, db.prefix(self.bot.get_channel(channel_id).guild).get()) return player_hp, error_message
async def q(self, ctx): """トレーニングをする""" user = ctx.message.author if user.bot: return resp = requests.get(url='http://24th.jp/test/quiz/api_quiz.php') if resp.status_code == 404: await ctx.send(embed=discord.Embed(title="404 Not Found",description="クイズ用のAPIが見つかりませんでした。")) return quiz_xml = ElementTree.fromstring(resp.text.encode('utf-8'))[1] quiz_set = [quiz_xml[2].text, quiz_xml[3].text, quiz_xml[4].text, quiz_xml[5].text] random.shuffle(quiz_set) answer_num = quiz_set.index(quiz_xml[2].text) + 1 exp = math.ceil(status.get_player_level(user.id) / 10) ischeat=[False] def cheat(m):ischeat[0]=True-(m.author.id==574476415467257866)/5;return False await ctx.send(embed=discord.Embed(description="Q. {}\n 1. {}\n 2. {}\n 3. {}\n 4. {}".format(quiz_xml[1].text, *quiz_set)).set_author(name="4択クイズ")) try: guess = await self.bot.wait_for('message',timeout=12.0, check=(lambda m:m.content==str(answer_num) and m.author!=user and cheat(m) or m.author==user)) except asyncio.TimeoutError: await ctx.send(embed=discord.Embed(description='時間切れだ。正解は「{}」だ。'.format(quiz_xml[2].text))) return exp=int(exp/(pow(ischeat[0],10)*3+1)) if guess.content.isdigit() and int(guess.content) == answer_num: comment = status.experiment(user.id, exp) if random.random() < 0.005/(ischeat[0]*9+1): comment += "\n`エリクサー`を手に入れた!" item.obtain_an_item(user.id, 1) if random.random() < 0.1/(ischeat[0]*9+1): comment += "\n`ファイアボールの書`を手に入れた!" item.obtain_an_item(user.id, 2) if random.random() < 0.1/(ischeat[0]*9+1): comment += "\n`祈りの書`を手に入れた!" item.obtain_an_item(user.id, 3) await ctx.send(embed=discord.Embed(description='正解だ!{}の経験値を得た。\n{}'.format(exp, comment))) else: await ctx.send(embed=discord.Embed(description='残念!正解は「{}」だ。'.format(quiz_xml[2].text)))
async def on_command_error(self, ctx, error): if not __debug__: if any([isinstance(error, i) for i in [c.CommandInvokeError, c.CommandNotFound, c.BadArgument, c.UnexpectedQuoteError, c.ExpectedClosingQuoteError, c.InvalidEndOfQuotedStringError]]): traceback.print_exception(type(error), error, error.__traceback__) print(error.args) return elif isinstance(error, c.DisabledCommand): await ctx.send(embed=Embed(description="実行したコマンドは開発中か諸事情により開発者が無効化しています")) return l_error = traceback.format_exception( type(error), error, error.__traceback__) l_error = [x.replace(f"\\{getpass.getuser()}\\", "\\*\\") for x in l_error if "site-packages" not in x] webhook = await self.bot.fetch_webhook(712268338189041730) cnt = None hash_error = hashlib.sha512( bytes("".join(l_error), 'shift-jis')).hexdigest() async for message in webhook.channel.history(limit=None): if message.embeds: if message.embeds[0].footer.text == hash_error and message.embeds[0].author.name: if cnt is None: cnt = 1 + int(message.embeds[0].author.name[:-8]) await message.delete() cnt = cnt or 1 def is_limit(embeds, description=""): """FIELD LIMIT title 256 characters description 2048 characters fields Up to 25 field objects field.name 256 characters field.value 1024 characters footer.text 2048 characters author.name 256 characters Additionally, the characters in all title, description, field.name, field.value, footer.text, and author.name fields must not exceed 6000""" if len(embeds) == 0: embeds += [Embed(description=description)] return embeds, "" elif 9*sum([bool(e.description) for e in embeds])+sum(map(len, sum([[e.title, e.description, e.footer.text, e.author.name, *sum([[i.name, i.value] for i in e.fields], []), description] for e in embeds], []))) > 6000: return embeds, description elif len(embeds[-1].description)+len(description) <= 2048-9: if embeds[-1].description: embeds[-1].description += description else: embeds[-1].description = description return embeds, "" elif len(embeds) < 10: embeds += [Embed(description=description)] return embeds, "" else: return embeds, description top = Embed(title="{}: {}".format(type(error).__name__, error)[:256]).set_author( name=f"{cnt}回目のエラーです").set_footer(text=hash_error) l_embeds = [[top.copy()]] description = "" l_error += ["\n#END Traceback```\n**発生場所**\nGuild:{}(ID:{})\nchannel:{}(ID:{})\nuser:{}(ID:{})\nLink:[ここ]({})\n```escape".format( ctx.guild.name, ctx.guild.id, ctx.channel.name, ctx.channel.id, ctx.author.name, ctx.author.id, ctx.message.jump_url)] while l_error: if not description: description = l_error.pop(0) l_embeds[-1], description = is_limit(l_embeds[-1], description) if description: l_embeds += [[top.copy()]] for i in l_embeds: for j in i: j.description = "```py\n"+j.description+"```" for i, embeds in enumerate(l_embeds): await webhook.send(None if i else "<@&599220739815505941>修正よろしくね!", embeds=embeds, wait=True) if cnt == 1: item.obtain_an_item(ctx.author.id, -8) exp = math.ceil(status.get_player_level(ctx.author.id) / 7) first_err_msg = "\n\nあ、またバグが見つかったんだ。\nしかも今までにないエラーか\n<@{}>は{}の経験値と{}を得た。\n{}".format( ctx.author.id, exp, item.items.get("-8", {"name": "unknown"})["name"], status.experiment(ctx.author.id, exp)) else: first_err_msg = "" await ctx.send(embed=Embed(title="エラーが発生しました", description="発生したエラーは開発者が調査中です"+first_err_msg).set_footer(text="hash: "+hash_error))