|
import os |
|
import threading |
|
import discord |
|
from discord.ext import commands |
|
from discord import app_commands |
|
import funtion |
|
import cosmo2hex |
|
from typing import Optional |
|
import typing |
|
import gradio as gr |
|
|
|
|
|
tree_guild = 1207625911709597737 |
|
|
|
|
|
|
|
class Client(commands.Bot): |
|
def __init__(self): |
|
super().__init__(command_prefix=commands.when_mentioned_or('!'), intents=discord.Intents().all()) |
|
async def on_ready(self): |
|
self.tree.copy_global_to(guild=discord.Object(id=tree_guild)) |
|
await self.tree.sync(guild=discord.Object(id=tree_guild)) |
|
|
|
client = Client() |
|
|
|
|
|
async def name_auto(interaction: discord.Interaction, current: str) -> typing.List[app_commands.Choice[str]]: |
|
acs = cosmo2hex.find(current) |
|
matching_files = acs |
|
return [app_commands.Choice(name=num, value=num) for num in matching_files] |
|
|
|
|
|
@app_commands.autocomplete(name=name_auto) |
|
@client.tree.command(name="collect", description="모음") |
|
async def collect(interaction: discord.Interaction, name: str, count: Optional[int], sort: Optional[str]): |
|
if count == None: |
|
count = 9 |
|
await interaction.response.defer(ephemeral=False) |
|
|
|
|
|
if sort: |
|
funtion.download_sort(name, count, sort) |
|
file = discord.File(f"./{name}_sort_sum/sum.jpg", filename="sum.jpg") |
|
await interaction.followup.send(f"분류: {sort}", file=file) |
|
return |
|
funtion.download(name, count) |
|
file = discord.File(f"./{name}_sum/sum.jpg", filename="sum.jpg") |
|
await interaction.followup.send("", file=file) |
|
|
|
|
|
|
|
def run(): |
|
toker = os.environ['super_cosmo'] |
|
client.run(toker) |
|
|
|
def greet(name): |
|
return "Hello " + name + "!" |
|
|
|
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") |
|
|
|
if __name__ == "__main__": |
|
t1 = threading.Thread(target=demo.launch) |
|
t2 = threading.Thread(target=run) |
|
|
|
t1.start() |
|
t2.start() |
|
|
|
t1.join() |
|
t2.join() |