Skip to content

Commit

Permalink
address変更
Browse files Browse the repository at this point in the history
  • Loading branch information
lenlino committed Jun 1, 2024
1 parent e355da1 commit 6e9920d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 32 deletions.
1 change: 1 addition & 0 deletions .env_sub
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DB_PASS="password"
DB_PORT=5432
BE_ADDRESS="https://hcs.lenlino.com"
2 changes: 1 addition & 1 deletion backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask import Flask
from flask import send_file

import generate.generate
import generate.generator

app = Flask(__name__)
app.debug = True
Expand Down
11 changes: 6 additions & 5 deletions commands/CardCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from discord.ui import Select, Button, Modal, View

import generate.utils
import main
import utils.DataBase
from generate.generate import generate_panel
from generate.generator import generate_panel
from generate.utils import get_json_from_url, get_mihomo_lang


Expand Down Expand Up @@ -60,7 +61,7 @@ async def update_calc_selector():
chara_types = []
chara_id = json_parsed["characters"][select_number]["id"]
async with aiohttp.ClientSession() as session:
async with session.get(f"https://hcs.lenlino.com/weight_list/"
async with session.get(f"{main.be_address}/weight_list/"
f"{chara_id}") as response:
chara_type_json = await response.json()

Expand Down Expand Up @@ -138,9 +139,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_hide_roll=is_roll_hide)
is_hideUID=is_uid_hide
, calculating_standard=calculation_value, lang=lang,
is_hide_roll=is_roll_hide)
if "detail" in panel_img_result:
res_embed = discord.Embed(
title=f"Error",
Expand Down
5 changes: 2 additions & 3 deletions commands/ChangeWeightCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import main
import utils.Weight
from generate.generate import generate_panel
from generate.utils import get_json_from_url, get_mihomo_lang


Expand All @@ -21,7 +20,7 @@ async def get_chara_types(ctx: discord.AutocompleteContext):
if chara_id is not None:
chara_types = []
async with aiohttp.ClientSession() as session:
async with session.get(f"https://hcs.lenlino.com/weight_list/"
async with session.get(f"{main.be_address}/weight_list/"
f"{chara_id}") as response:
chara_type_json = await response.json()
for k, v in chara_type_json.items():
Expand Down Expand Up @@ -52,7 +51,7 @@ async def change_weight_command(self, ctx,
else:
weight_id = f"{chara_id}_{type_id}"
async with aiohttp.ClientSession() as session:
async with session.get(f"https://hcs.lenlino.com/weight_list/{weight_id}"
async with session.get(f"{main.be_address}/weight_list/{weight_id}"
) as response:
chara_type_json = await response.json()
weight = weight.model_validate(chara_type_json[weight_id])
Expand Down
5 changes: 1 addition & 4 deletions commands/CreateWeightCommand.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import datetime
import io

import discord
import i18n
from discord.ext import commands
from discord.ui import Select, Button, Modal, View

import main
import utils.Weight
from generate.generate import generate_panel
from generate.utils import get_json_from_url, get_mihomo_lang
from generate.utils import get_mihomo_lang


class CreateWeightCommand(commands.Cog):
Expand Down
8 changes: 2 additions & 6 deletions generate/generate.py → generate/generator.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import io
import json
import math
import os
import pathlib

import aiohttp
from PIL import ImageDraw, Image, ImageFont

from generate.templates import one, two
from generate.utils import conn

font_file_path = f"{os.path.dirname(os.path.abspath(__file__))}/assets/zh-cn.ttf"
be_address = os.environ.get("BE_ADDRESS", "https://hcs.lenlino.com")


async def generate_panel(uid="805477392", chara_id=1, template=1, is_hideUID=False, calculating_standard="compatibility", lang="jp", is_hide_roll=False):
result_json = {}
async with aiohttp.ClientSession(connector_owner=False, connector=conn) as session:
async with session.get(f"https://hcs.lenlino.com/gen_card/{uid}?lang={lang}&select_number={chara_id}&calculation_value={calculating_standard}"
async with session.get(f"{be_address}/gen_card/{uid}?lang={lang}&select_number={chara_id}&calculation_value={calculating_standard}"
f"&is_uid_hide={is_hideUID}&is_hide_roll={is_hide_roll}") as response:

if response.status == 200:
Expand Down
6 changes: 4 additions & 2 deletions generate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from starrailres import Index
from starrailres.models.info import CharacterBasicInfo, LevelInfo, LightConeBasicInfo, SubAffixBasicInfo, RelicBasicInfo


conn = aiohttp.TCPConnector(limit_per_host=1)
be_address = os.environ.get('BE_ADDRESS', "https://hcs.lenlino.com")


async def get_image_from_url(url: str):
Expand All @@ -28,7 +30,7 @@ async def get_image_from_url(url: str):

async def get_json_from_urlpath(path: str):
async with aiohttp.ClientSession(connector_owner=False, connector=conn) as session:
async with session.get(f"https://hcs.lenlino.com{path}") as response:
async with session.get(f"{be_address}{path}") as response:
if response.status == 200:
result_json = await response.json()
return result_json
Expand All @@ -38,7 +40,7 @@ async def get_json_from_urlpath(path: str):
async def get_json_from_url(uid: str, lang: str):
result_json = {}
async with aiohttp.ClientSession(connector_owner=False, connector=conn) as session:
async with session.get(f"https://hcs.lenlino.com/sr_info_parsed/{uid}?lang={lang}") as response:
async with session.get(f"{be_address}/sr_info_parsed/{uid}?lang={lang}") as response:
if response.status == 200:
result_json = await response.json()
if len(result_json.keys()) == 0 or "detail" in result_json:
Expand Down
18 changes: 7 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import datetime
import io
import json
import os

import aiohttp
import asyncpg as asyncpg
import discord
import discord.ext.commands.cog
from discord.ext import tasks
from dotenv import load_dotenv

import backend.backend
import generate.utils
import i18n

Expand All @@ -23,6 +20,7 @@

bot = discord.AutoShardedBot()
token = os.environ.get('HONKAI_TOKEN')
be_address = os.environ.get('BE_ADDRESS', "https://hcs.lenlino.com")
characters = []
characters_name = {}

Expand All @@ -39,8 +37,6 @@ async def init_bot():
os.system("git pull")




@bot.event
async def on_ready():
await init_bot()
Expand Down Expand Up @@ -94,15 +90,15 @@ async def regi_weight_task():
if embed_title.endswith("(投票中)"):
if reactions[0].count >= reactions[1].count:
async with aiohttp.ClientSession() as session:
async with session.post(f"https://hcs.lenlino.com/weight/"
async with session.post(f"/weight/"
f"{chara_id}"
, json=weight_json) as response:
print(response)
pass
if chara_id.startswith("8"):
async with aiohttp.ClientSession() as session:
async with session.post(f"https://hcs.lenlino.com/weight/"
f"{chara_id.replace(mes.attachments[0].filename.replace('.json', ''), str(int(chara_id)+1))}"
async with session.post(f"{be_address}/weight/"
f"{chara_id.replace(mes.attachments[0].filename.replace('.json', ''), str(int(chara_id) + 1))}"
, json=weight_json) as response:
print(response)
pass
Expand All @@ -116,14 +112,14 @@ async def regi_weight_task():
if embed_title.endswith("(投票中)"):
if reactions[0].count >= reactions[1].count:
async with aiohttp.ClientSession() as session:
async with session.put(f"https://hcs.lenlino.com/weight/{chara_id}"
async with session.put(f"{be_address}/weight/{chara_id}"
, json=weight_json) as response:
print(await response.text())
pass
if chara_id.startswith("8"):
async with aiohttp.ClientSession() as session:
async with session.put(f"https://hcs.lenlino.com/weight/"
f"{chara_id.replace(mes.attachments[0].filename.replace('.json', ''), str(int(chara_id)+1))}"
async with session.put(f"{be_address}/weight/"
f"{chara_id.replace(mes.attachments[0].filename.replace('.json', ''), str(int(chara_id) + 1))}"
, json=weight_json) as response:
print(await response.text())
pass
Expand Down

0 comments on commit 6e9920d

Please sign in to comment.