Skip to content

Commit

Permalink
Merge pull request #33 from lenlino/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lenlino authored Dec 10, 2023
2 parents 73fad2f + cf9eb75 commit a5233a3
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 84 deletions.
38 changes: 31 additions & 7 deletions commands/CardCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ async def card_command(self, ctx, uid: discord.Option(required=False, input_type
generate_button = Button()
uid_change_button = Button()
uid_hide_button = Button()
roll_hide_button = Button()
select_number = 0
calculation_value = 0
is_uid_hide = False
is_roll_hide = False
lang = get_mihomo_lang(ctx.interaction.locale)
user_detail_dict = {}
json_parsed = {}
print(ctx.interaction.locale)

def get_view():
return View(selecter, calculation_selecter, generate_button, uid_change_button, uid_hide_button,
timeout=600)
roll_hide_button, timeout=600)

def update_uid_hide_button():
if is_uid_hide:
Expand All @@ -42,6 +44,14 @@ def update_uid_hide_button():
uid_hide_button.style = discord.ButtonStyle.gray
uid_hide_button.label = f"{i18n.t('message.hide_uid', locale=lang) + i18n.t('message.off', locale=lang)}"

def update_roll_hide_button():
if is_roll_hide:
roll_hide_button.style = discord.ButtonStyle.green
roll_hide_button.label = f"{i18n.t('message.hide_roll', locale=lang) + i18n.t('message.on', locale=lang)}"
else:
roll_hide_button.style = discord.ButtonStyle.gray
roll_hide_button.label = f"{i18n.t('message.hide_roll', locale=lang) + i18n.t('message.off', locale=lang)}"

async def selector_callback(interaction):
try:
nonlocal select_number
Expand All @@ -68,6 +78,16 @@ async def uid_hide_button_callback(interaction):
except discord.errors.HTTPException:
pass

async def roll_hide_button_callback(interaction):
try:
nonlocal is_roll_hide
is_roll_hide = not is_roll_hide
update_roll_hide_button()
await ctx.edit(view=get_view())
await interaction.response.send_message("")
except discord.errors.HTTPException:
pass

async def button_callback(interaction):
await interaction.response.defer()
if selecter.options[0].label == i18n.t("message.uid_not_set", locale=lang):
Expand All @@ -81,8 +101,9 @@ async def button_callback(interaction):
await ctx.edit(view=get_view())
nonlocal select_number
panel_img_result = await generate_panel(uid=uid, chara_id=int(select_number), template=2,
is_hideUID=is_uid_hide
, calculating_standard=calculation_value, lang=lang)
is_hideUID=is_uid_hide
, calculating_standard=calculation_value, lang=lang,
is_hide_roll=is_roll_hide)
panel_img = panel_img_result['img']

panel_img.save(image_binary, 'PNG')
Expand All @@ -103,7 +124,7 @@ async def button_callback(interaction):
if v == 0:
continue
weight_text += f"{i18n.t(f'message.{k}', locale=lang)}: {v}\n"
res_embed.add_field(name="重み", value=weight_text)
res_embed.add_field(name=i18n.t(f'message.weight', locale=lang), value=weight_text)

score_rank = generate.utils.get_score_rank(int(avatar_id), uid, panel_img_result['score'])
# 統計
Expand All @@ -112,7 +133,7 @@ async def button_callback(interaction):
rank_text += f"{i18n.t('message.high_score', locale=lang)}: {score_rank['top_score']}\n"
rank_text += f"{i18n.t('message.Mean', locale=lang)}: {score_rank['mean']}\n"
rank_text += f"{i18n.t('message.Median', locale=lang)}: {score_rank['median']}\n"
res_embed.add_field(name="統計", value=rank_text)
res_embed.add_field(name=i18n.t(f'message.stats', locale=lang), value=rank_text)

res_embed.set_image(url=f"attachment://{file.filename}")
await interaction.followup.send(embed=res_embed, file=file)
Expand Down Expand Up @@ -147,7 +168,7 @@ async def set_uid(changed_uid):
discord.SelectOption(label=i["name"], value=str(index),
default=True if index == select_number else False))
if len(selecter.options) == 0:
embed.description += "\n"+i18n.t("message.error_no_chara_set", locale=lang)
embed.description += "\n" + i18n.t("message.error_no_chara_set", locale=lang)
else:
await ctx.edit(view=get_view())
elif info["detail"] == "Queue timeout":
Expand Down Expand Up @@ -177,13 +198,16 @@ async def set_uid(changed_uid):
uid_hide_button.callback = uid_hide_button_callback
uid_hide_button.style = discord.ButtonStyle.gray
uid_hide_button.label = i18n.t('message.hide_uid', locale=lang) + i18n.t('message.off', locale=lang)
roll_hide_button.row = 4
roll_hide_button.callback = roll_hide_button_callback
roll_hide_button.style = discord.ButtonStyle.gray
roll_hide_button.label = i18n.t('message.hide_roll', locale=lang) + i18n.t('message.off', locale=lang)

embed = discord.Embed(
title="Herta Card System",
color=discord.Colour.dark_blue(),
description=i18n.t("message.loading", locale=lang),
)
embed.add_field(name="プライバシーポリシーの更新(2023-11-05)", value="スコアの統計を取るため、新たにハイスコアがサーバー上に保存されるようになりました。このデータは当ボット上でのみ使用します。")

await ctx.send_followup(embed=embed, view=get_view())
if uid is None:
Expand Down
4 changes: 2 additions & 2 deletions generate/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
font_file_path = f"{os.path.dirname(os.path.abspath(__file__))}/assets/zh-cn.ttf"


async def generate_panel(uid="805477392", chara_id=1, template=1, is_hideUID=False, calculating_standard="compatibility", lang="jp"):
async def generate_panel(uid="805477392", chara_id=1, template=1, is_hideUID=False, calculating_standard="compatibility", lang="jp", is_hide_roll=False):
if template == 1:
return await one.generate_panel(uid=uid, chara_id=chara_id, is_hideUID=is_hideUID, calculating_standard=calculating_standard)
elif template == 2:
return await two.generate_panel(uid=uid, chara_id=chara_id, is_hideUID=is_hideUID, calculating_standard=calculating_standard, lang=lang)
return await two.generate_panel(uid=uid, chara_id=chara_id, is_hideUID=is_hideUID, calculating_standard=calculating_standard, lang=lang, is_hide_roll=is_hide_roll)


62 changes: 62 additions & 0 deletions generate/rolls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"HPDelta": {
"3": [20, 23, 25],
"4": [27, 30, 33],
"5": [33, 38, 42]
},
"AttackDelta": {
"3": [10, 11, 12],
"4": [13, 15, 16],
"5": [16, 19, 21]
},
"DefenceDelta": {
"3": [10, 11, 12],
"4": [13, 15, 16],
"5": [16, 19, 21]
},
"HPAddedRatio": {
"3": [0.020, 0.023, 0.025],
"4": [0.027, 0.031, 0.034],
"5": [0.034, 0.038, 0.044]
},
"AttackAddedRatio": {
"3": [0.020, 0.023, 0.025],
"4": [0.027, 0.031, 0.034],
"5": [0.034, 0.038, 0.044]
},
"DefenceAddedRatio": {
"3": [0.025, 0.029, 0.032],
"4": [0.034, 0.038, 0.043],
"5": [0.043, 0.048, 0.054]
},
"SpeedDelta": {
"3": [1.0, 1.0, 1.0],
"4": [1.6, 1.8, 2.0],
"5": [2.0, 2.3, 2.6]
},
"CriticalChanceBase": {
"3": [0.015, 0.017, 0.019],
"4": [0.020, 0.023, 0.025],
"5": [0.025, 0.029, 0.032]
},
"CriticalDamageBase": {
"3": [0.031, 0.035, 0.038],
"4": [0.041, 0.046, 0.051],
"5": [0.051, 0.058, 0.065]
},
"StatusProbabilityBase": {
"3": [0.020, 0.023, 0.025],
"4": [0.027, 0.031, 0.034],
"5": [0.034, 0.038, 0.043]
},
"StatusResistanceBase": {
"3": [0.020, 0.023, 0.025],
"4": [0.027, 0.031, 0.034],
"5": [0.034, 0.038, 0.043]
},
"BreakDamageAddedRatioBase": {
"3": [0.031, 0.035, 0.038],
"4": [0.041, 0.046, 0.051],
"5": [0.051, 0.058, 0.065]
}
}
Loading

0 comments on commit a5233a3

Please sign in to comment.