File size: 6,114 Bytes
702e854 77476e0 80a8901 b9775c8 3d232d3 34eaf74 210d2c5 a773200 504c173 73f1185 bc54071 702e854 4ac25ce 0386a8b 702e854 37930f6 77476e0 37930f6 77476e0 37930f6 42cfb0a b11285d 42cfb0a db8bc38 702e854 db8bc38 058df97 77476e0 058df97 86328fd 5c19775 bba8685 30b8f05 77476e0 42cfb0a 77476e0 42cfb0a 77476e0 b11285d 09a3630 b6b6612 b11285d 09a3630 d51f661 cf49ef3 88ef58f 1bf5d94 d613d12 233749d 4d16a9a b11285d 88ef58f b11285d 4d16a9a 88ef58f b11285d 4d16a9a b11285d 2602403 b11285d 88ef58f b11285d 4d16a9a 88ef58f b11285d 2602403 b11285d 2602403 b11285d e607384 2602403 b11285d 2602403 e607384 e1ea889 e607384 003ccc0 e607384 db8bc38 70f8e3b db8bc38 c10c55d db8bc38 55f94c4 d90d463 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
import discord
from discord.ext import commands
import gradio as gr
import os
import random
import typing
import enum
import json
import threading
from re import A
from discord import app_commands
from datetime import datetime, timedelta, timezone
# 디스코드 봇 설정
intents = discord.Intents.default()
intents.message_content = True
intents.dm_messages = True # DM 메시지 수신 허용
bot = commands.Bot(command_prefix='/', intents=intents)
TARGET_CHANNEL_ID = 1244200163682029569 # 여기에 지정된 채널 ID를 입력하세요
ALLOWED_USER_ID = 676049087300239369 # 여기에 지정된 사용자 ID를 입력하세요
MENTION_USER_ID = 676049087300239369 # 여기에 언급할 사용자 ID를 입력하세요
# hf.co 이미지 폴더 경로
TRIPLES_FIRST_IMAGE_FOLDER_PATH = "shop/tripleS/first"
TRIPLES_DOUBLE_IMAGE_FOLDER_PATH = "shop/tripleS/double"
ARTMS_FIRST_IMAGE_FOLDER_PATH = "shop/ARTMS/first"
ARTMS_DOUBLE_IMAGE_FOLDER_PATH = "shop/ARTMS/double"
# 봇의 상태를 확인하기 위한 전역 변수
bot_status = "Initializing..."
@bot.event
async def on_ready():
global bot_status
bot_status = f"Logged in as {bot.user}"
print(bot_status)
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} command(s)")
except Exception as e:
print(f"Failed to sync commands: {e}")
@bot.event
async def on_ready():
global bot_status
bot_status = f"Logged in as {bot.user}"
print(bot_status)
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} command(s)")
except Exception as e:
print(f"Failed to sync commands: {e}")
# 상태 메시지 설정
await bot.change_presence(activity=discord.CustomActivity(name="태양을 다 삼킨 죄, 이제 사해진 순간"))
@bot.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel) and message.author != bot.user:
target_channel = bot.get_channel(TARGET_CHANNEL_ID)
if target_channel is None:
print("지정된 채널을 찾을 수 없습니다.")
return
if message.author.id != ALLOWED_USER_ID:
try:
await message.author.send("이 메시지를 보낼 권한이 없습니다.")
except discord.Forbidden:
print(f"Cannot send DM to {message.author}.")
return
if message.content or message.attachments:
files = [await attachment.to_file() for attachment in message.attachments if attachment.filename.lower().endswith(('png', 'jpg', 'jpeg', 'gif', 'bmp'))]
await target_channel.send(content=f"{message.content}", files=files)
async def class_autocompletion(
interaction: discord.Interaction,
current: str
) -> typing.List[app_commands.Choice[str]]:
"""Class 자동 완성을 위한 함수"""
classes = ['first', 'double']
return [
app_commands.Choice(name=cls, value=cls)
for cls in classes if current.lower() in cls.lower()
]
async def artist_autocompletion(
interaction: discord.Interaction,
current: str
) -> typing.List[app_commands.Choice[str]]:
"""Artist 자동 완성을 위한 함수"""
artists = ['tripleS', 'ARTMS']
return [
app_commands.Choice(name=art, value=art)
for art in artists if current.lower() in art.lower()
]
async def theme_autocompletion(
interaction: discord.Interaction,
current: str
) -> typing.List[app_commands.Choice[str]]:
"""Theme 자동 완성을 위한 함수"""
themes = ['info', 'point', 'pack 10', 'pack 1']
return [
app_commands.Choice(name=theme, value=theme)
for theme in themes if current.lower() in theme.lower()
]
@bot.tree.command(name="shop")
@app_commands.autocomplete(class_=class_autocompletion, artist=artist_autocompletion)
async def shop_tree(interaction: discord.Interaction,
artist: str,
class_: str):
"""오브젝트를 구매해볼 수 있습니다. (KRW 0)"""
if artist.lower() == "triples":
if class_.lower() == "first":
folder_path = TRIPLES_FIRST_IMAGE_FOLDER_PATH
text = "# Cosmo로 불러왔어요!"
elif class_.lower() == "double":
folder_path = TRIPLES_DOUBLE_IMAGE_FOLDER_PATH
text = "# Cosmo로 불러왔어요!"
else:
await interaction.response.send_message("올바른 Class를 선택하세요.", ephemeral=True)
return
elif artist.lower() == "artms":
if class_.lower() == "first":
folder_path = ARTMS_FIRST_IMAGE_FOLDER_PATH
text = "# Cosmo로 불러왔어요!"
elif class_.lower() == "double":
folder_path = ARTMS_DOUBLE_IMAGE_FOLDER_PATH
text = "# Cosmo로 불러왔어요!"
else:
await interaction.response.send_message("올바른 Class를 선택하세요.", ephemeral=True)
return
else:
await interaction.response.send_message("올바른 Artist를 선택하세요.", ephemeral=True)
return
if not os.path.exists(folder_path) or not os.listdir(folder_path):
await interaction.response.send_message("Objekt가 준비되지 않았습니다.", ephemeral=True)
return
random_image = random.choice(os.listdir(folder_path))
with open(os.path.join(folder_path, random_image), "rb") as f:
image_data = discord.File(f)
await interaction.response.send_message(content=text, file=image_data, ephemeral=True)
# 봇의 상태를 반환하는 함수
def check_bot_status():
return bot_status
if __name__ == "__main__":
token = os.environ['token']
def run_discord_bot():
bot.run(token)
discord_thread = threading.Thread(target=run_discord_bot)
discord_thread.start()
# Gradio 인터페이스 설정
iface = gr.Interface(
fn=check_bot_status,
inputs=[],
outputs="text",
live=True,
title="Discord Bot Status",
description="Click the button to check if the bot is running."
)
iface.launch() |