Skip to content

Commit

Permalink
Merge pull request #15 from t3tra-dev/patch-2
Browse files Browse the repository at this point in the history
fix ckill.py
  • Loading branch information
Syunngiku0402 authored Sep 30, 2024
2 parents 14a6751 + 673e606 commit bd4ca0a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cogs/ckill.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import discord
from discord import app_commands
from discord import Member, app_commands
from discord.ext import commands

import json
import random


def kill(name, target=None):

# jsonファイル を dict(lang_data) に変換
with open(file='ja_jp.json',mode='r',encoding='utf-8') as file:
with open(file='ja_jp.json', mode='r', encoding='utf-8') as file:
lang_data = json.load(file)

# lang_data からデスログ、エンティティ名、アイテム名を抽出
death_logs = [v for k, v in lang_data.items() if "death." in k]
entities = [v.replace("のスポーンエッグ","") for k, v in lang_data.items() if "item.minecraft." in k and "_spawn_egg" in k]
entities = [v.replace("のスポーンエッグ", "") for k, v in lang_data.items() if "item.minecraft." in k and "_spawn_egg" in k]
items = [v for k, v in lang_data.items() if "item.minecraft." in k]

# もしtargetがいなかったら、targetをエンティティの中から選出する
if target == None:
if target is None:
target = random.choice(entities)

# キルログ生成
death_log = random.choice(death_logs).replace("%1$s",name + " ").replace("%2$s",target).replace("%3$s",f"[{random.choice(items)}]")
death_log = random.choice(death_logs).replace("%1$s", name + " ").replace("%2$s", target).replace("%3$s", f"[{random.choice(items)}]")
return death_log


Expand All @@ -31,9 +32,9 @@ def __init__(self, bot: commands.Bot):

@app_commands.command(name="ckill", description="キルコマンド(ネタ)")
@app_commands.describe(target="キルするユーザー(任意)")
async def ctemperature(self, interaction: discord.Interaction, target=None):
await interaction.response.send_message(kill(f"<@{interaction.user.id}>", target))
async def ckill(self, interaction: discord.Interaction, target: Member=None):
await interaction.response.send_message(kill(interaction.user.mention, target))


async def setup(bot: commands.Bot):
await bot.add_cog(CKill(bot))
await bot.add_cog(CKill(bot))

0 comments on commit bd4ca0a

Please sign in to comment.