2023-03-22 21:28:15 +09:00
|
|
|
import os
|
|
|
|
import asyncio
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
import disnake
|
2023-03-22 21:31:01 +09:00
|
|
|
from disnake.ext import commands
|
2023-03-22 21:28:15 +09:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from linked_roles import RoleMetadataType, LinkedRolesOAuth2, RoleMetadataRecord
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
bot = commands.InteractionBot(
|
2023-03-23 00:24:53 +09:00
|
|
|
status=disnake.Status.dnd,
|
|
|
|
activity=disnake.Activity(type=disnake.ActivityType.watching, name="Achievements"),
|
2023-03-22 21:28:15 +09:00
|
|
|
intents=disnake.Intents.default()
|
|
|
|
)
|
|
|
|
|
2023-03-22 22:42:48 +09:00
|
|
|
def list_chunk(lst, n):
|
|
|
|
return [lst[i:i+n] for i in range(0, len(lst), n)]
|
|
|
|
|
2023-03-22 21:28:15 +09:00
|
|
|
async def async_list(values: list) -> Any:
|
|
|
|
for value in values:
|
|
|
|
yield value
|
|
|
|
await asyncio.sleep(0)
|
|
|
|
|
|
|
|
@bot.slash_command(name="register", description="Linked Role의 기본적인 연동을 설정합니다.")
|
|
|
|
@commands.is_owner()
|
|
|
|
async def _addConnection(inter: disnake.ApplicationCommandInteraction):
|
|
|
|
await inter.response.defer(ephemeral=True)
|
|
|
|
records = [
|
2023-03-22 23:06:29 +09:00
|
|
|
RoleMetadataRecord(
|
2023-03-23 11:48:07 +09:00
|
|
|
key="honor_roll",
|
2023-03-22 23:06:29 +09:00
|
|
|
name="Honor roll",
|
2023-03-26 11:56:39 +09:00
|
|
|
description="Perfect the tutorial",
|
|
|
|
type=RoleMetadataType.boolean_equal,
|
|
|
|
name_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "우등생"
|
2023-03-26 11:56:39 +09:00
|
|
|
},
|
|
|
|
description_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "튜토리얼 스테이지를 퍼펙트로 클리어해야 합니다."
|
2023-03-26 11:56:39 +09:00
|
|
|
}
|
2023-03-22 23:06:29 +09:00
|
|
|
),
|
2023-03-23 11:43:31 +09:00
|
|
|
RoleMetadataRecord(
|
2023-03-23 11:48:07 +09:00
|
|
|
key="new_day",
|
2023-03-23 11:43:31 +09:00
|
|
|
name="New Day",
|
2023-03-26 11:56:39 +09:00
|
|
|
description="Get through the morning",
|
|
|
|
type=RoleMetadataType.boolean_equal,
|
|
|
|
name_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "밝아오는 새로운 아침"
|
2023-03-26 11:56:39 +09:00
|
|
|
},
|
|
|
|
description_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "모든 스테이지를 클리어해야 합니다."
|
2023-03-26 11:56:39 +09:00
|
|
|
}
|
2023-03-23 11:43:31 +09:00
|
|
|
),
|
2023-03-22 23:06:29 +09:00
|
|
|
RoleMetadataRecord(
|
2023-03-23 11:48:07 +09:00
|
|
|
key="go_to_bed",
|
2023-03-22 23:06:29 +09:00
|
|
|
name="Go to bed",
|
2023-03-26 11:56:39 +09:00
|
|
|
description="Get all perfect scores",
|
|
|
|
type=RoleMetadataType.boolean_equal,
|
|
|
|
name_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "자러 갈 시간"
|
2023-03-26 11:56:39 +09:00
|
|
|
},
|
|
|
|
description_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "모든 스테이지를 퍼펙트로 클리어해야 합니다."
|
2023-03-26 11:56:39 +09:00
|
|
|
}
|
2023-03-22 21:28:15 +09:00
|
|
|
),
|
|
|
|
RoleMetadataRecord(
|
|
|
|
key="percentage",
|
2023-03-26 11:56:39 +09:00
|
|
|
name="% of Achievements",
|
|
|
|
description="% of cleared achievements",
|
|
|
|
type=RoleMetadataType.interger_greater_than_or_equal,
|
|
|
|
name_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "% 도전 과제 달성률"
|
2023-03-26 11:56:39 +09:00
|
|
|
},
|
|
|
|
description_localizations={
|
2023-03-26 12:30:09 +09:00
|
|
|
"ko": "%의 도전 과제를 달성해야 합니다."
|
2023-03-26 11:56:39 +09:00
|
|
|
}
|
2023-03-23 11:43:31 +09:00
|
|
|
)
|
2023-03-22 21:28:15 +09:00
|
|
|
]
|
2023-03-22 22:00:40 +09:00
|
|
|
async with LinkedRolesOAuth2(client_id=os.getenv("CLIENT_ID"), token=os.getenv("BOT_TOKEN")) as client:
|
2023-03-22 22:54:16 +09:00
|
|
|
try:
|
2023-03-23 17:35:18 +09:00
|
|
|
result = await client.register_role_metadata(records=tuple(records), force=True)
|
2023-03-22 22:54:16 +09:00
|
|
|
except Exception as e:
|
|
|
|
await inter.edit_original_message(e)
|
|
|
|
else:
|
2023-03-23 17:35:18 +09:00
|
|
|
await inter.edit_original_message(content=f"> :star2: 역할 추가가 완료되었습니다!\n{result}")
|
2023-03-22 21:28:15 +09:00
|
|
|
|
2023-03-26 11:56:39 +09:00
|
|
|
bot.run(os.getenv("BOT_TOKEN"))
|