Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,12 +86,14 @@ class MyClient(discord.Client):
|
|
| 86 |
|
| 87 |
self.is_processing = True
|
| 88 |
try:
|
|
|
|
|
|
|
| 89 |
if self.is_math_question(message.content):
|
| 90 |
text_response = await self.handle_math_question(message.content)
|
| 91 |
-
await self.send_message_with_latex(
|
| 92 |
else:
|
| 93 |
response = await self.generate_response(message)
|
| 94 |
-
await self.send_message_with_latex(
|
| 95 |
finally:
|
| 96 |
self.is_processing = False
|
| 97 |
|
|
@@ -156,18 +158,18 @@ class MyClient(discord.Client):
|
|
| 156 |
|
| 157 |
async def send_message_with_latex(self, channel, message):
|
| 158 |
try:
|
| 159 |
-
|
| 160 |
text_parts = re.split(r'(\$\$.*?\$\$|\$.*?\$)', message, flags=re.DOTALL)
|
| 161 |
|
| 162 |
for part in text_parts:
|
| 163 |
if part.startswith('$'):
|
| 164 |
-
|
| 165 |
latex_content = part.strip('$')
|
| 166 |
image_base64 = latex_to_image(latex_content)
|
| 167 |
image_binary = base64.b64decode(image_base64)
|
| 168 |
await channel.send(file=discord.File(BytesIO(image_binary), 'equation.png'))
|
| 169 |
else:
|
| 170 |
-
|
| 171 |
if part.strip():
|
| 172 |
await self.send_long_message(channel, part.strip())
|
| 173 |
|
|
@@ -185,4 +187,4 @@ class MyClient(discord.Client):
|
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|
| 187 |
discord_client = MyClient(intents=intents)
|
| 188 |
-
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
|
| 86 |
|
| 87 |
self.is_processing = True
|
| 88 |
try:
|
| 89 |
+
# ์๋ก์ด ์ค๋ ๋ ์์ฑ
|
| 90 |
+
thread = await message.channel.create_thread(name=f"์ง๋ฌธ: {message.author.name}", message=message)
|
| 91 |
if self.is_math_question(message.content):
|
| 92 |
text_response = await self.handle_math_question(message.content)
|
| 93 |
+
await self.send_message_with_latex(thread, text_response)
|
| 94 |
else:
|
| 95 |
response = await self.generate_response(message)
|
| 96 |
+
await self.send_message_with_latex(thread, response)
|
| 97 |
finally:
|
| 98 |
self.is_processing = False
|
| 99 |
|
|
|
|
| 158 |
|
| 159 |
async def send_message_with_latex(self, channel, message):
|
| 160 |
try:
|
| 161 |
+
# ํ
์คํธ์ LaTeX ์์ ๋ถ๋ฆฌ
|
| 162 |
text_parts = re.split(r'(\$\$.*?\$\$|\$.*?\$)', message, flags=re.DOTALL)
|
| 163 |
|
| 164 |
for part in text_parts:
|
| 165 |
if part.startswith('$'):
|
| 166 |
+
# LaTeX ์์ ์ฒ๋ฆฌ ๋ฐ ์ด๋ฏธ์ง๋ก ์ถ๋ ฅ
|
| 167 |
latex_content = part.strip('$')
|
| 168 |
image_base64 = latex_to_image(latex_content)
|
| 169 |
image_binary = base64.b64decode(image_base64)
|
| 170 |
await channel.send(file=discord.File(BytesIO(image_binary), 'equation.png'))
|
| 171 |
else:
|
| 172 |
+
# ํ
์คํธ ์ถ๋ ฅ
|
| 173 |
if part.strip():
|
| 174 |
await self.send_long_message(channel, part.strip())
|
| 175 |
|
|
|
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
discord_client = MyClient(intents=intents)
|
| 190 |
+
discord_client.run(os.getenv('DISCORD_TOKEN'))
|