File size: 1,832 Bytes
78efe79
440418c
f3985af
bad7ad6
407a575
34428f1
407a575
32c38ef
f3985af
440418c
1831164
440418c
d1d0f02
440418c
08baccf
32c38ef
cb69e60
 
64f1359
8954f0b
64f1359
4509126
 
 
78efe79
08baccf
 
8954f0b
08baccf
78efe79
32c38ef
34428f1
 
 
78efe79
 
 
 
64f1359
 
 
 
8954f0b
64f1359
 
 
 
8954f0b
1831164
bad7ad6
34428f1
0926d14
34428f1
 
 
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
import discord
import logging
import os
from huggingface_hub import InferenceClient
import asyncio
import subprocess  # subprocess ๋ชจ๋“ˆ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

# ๋กœ๊น… ์„ค์ •
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])

# ์ธํ…ํŠธ ์„ค์ •
intents = discord.Intents.default()
intents.message_content = True  # ๋ฉ”์‹œ์ง€ ๋‚ด์šฉ ์ˆ˜์‹  ์ธํ…ํŠธ ํ™œ์„ฑํ™”
intents.messages = True

# ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))

# ํŠน์ • ์ฑ„๋„ ID
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))

# ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜
conversation_history = []

class MyClient(discord.Client):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.is_processing = False

    async def on_ready(self):
        logging.info(f'{self.user}๋กœ ๋กœ๊ทธ์ธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!')
        # web.py๋ฅผ ์ƒˆ๋กœ์šด ํ”„๋กœ์„ธ์Šค๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
        subprocess.Popen(["python", "web.py"])
        logging.info("Web.py server has been started.")

    async def on_message(self, message):
        if message.author == self.user:
            return
        if message.channel.id != SPECIFIC_CHANNEL_ID:
            return
        if self.is_processing:
            return
        self.is_processing = True
        try:
            response = await generate_response(message.content)
            await message.channel.send(response)
        finally:
            self.is_processing = False

async def generate_response(user_input):
    # (์ค‘๋žต: ๊ธฐ์กด์˜ generate_response ํ•จ์ˆ˜ ๋กœ์ง ์œ ์ง€)

if __name__ == "__main__":
    discord_client = MyClient(intents=intents)
    discord_client.run(os.getenv('DISCORD_TOKEN'))