seawolf2357 commited on
Commit
4e04dd7
โ€ข
1 Parent(s): 1423a35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -192,26 +192,44 @@ async def send_webhook_data(session, chunk_data, chunk_number):
192
 
193
  return False # ์žฌ์‹œ๋„ ํšŸ์ˆ˜ ์ดˆ๊ณผ ์‹œ ์‹คํŒจ๋กœ ๊ฐ„์ฃผ
194
 
 
195
  async def create_thread_and_send_replies(message, video_id, comments, replies, session):
196
  thread = await message.channel.create_thread(name=f"{message.author.name}์˜ ๋Œ“๊ธ€ ๋‹ต๊ธ€", message=message)
197
- webhook_data = {"video_id": video_id, "replies": []}
198
-
199
  for (comment, comment_id), reply in zip(comments, replies):
200
  embed = discord.Embed(description=f"**๋Œ“๊ธ€**: {comment}\n**๋‹ต๊ธ€**: {reply}")
201
  await thread.send(embed=embed)
202
 
203
- # ์›นํ›… ๋ฐ์ดํ„ฐ ์ค€๋น„ (comment id ํฌํ•จ)
204
- webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
 
 
 
 
 
 
 
 
205
 
206
- # ๋ฐ์ดํ„ฐ๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ๋‚˜๋ˆ„์–ด ์ „์†ก
207
- chunk_size = 1 # ์ „์†กํ•  ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ 1๋กœ ์„ค์ •ํ•˜์—ฌ ๊ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ„๋„๋กœ ์ „์†ก
208
- for i in range(0, len(webhook_data["replies"]), chunk_size):
209
- chunk = webhook_data["replies"][i:i+chunk_size]
210
- chunk_data = {"video_id": video_id, "replies": chunk}
211
 
212
- success = await send_webhook_data(session, chunk_data, i // chunk_size + 1)
213
- if not success:
214
- logging.error(f"๋ฐ์ดํ„ฐ ์ „์†ก ์‹คํŒจ: {i // chunk_size + 1} ๋ฒˆ์งธ ์ฒญํฌ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  if __name__ == "__main__":
217
  discord_client = MyClient(intents=intents)
 
192
 
193
  return False # ์žฌ์‹œ๋„ ํšŸ์ˆ˜ ์ดˆ๊ณผ ์‹œ ์‹คํŒจ๋กœ ๊ฐ„์ฃผ
194
 
195
+
196
  async def create_thread_and_send_replies(message, video_id, comments, replies, session):
197
  thread = await message.channel.create_thread(name=f"{message.author.name}์˜ ๋Œ“๊ธ€ ๋‹ต๊ธ€", message=message)
198
+
 
199
  for (comment, comment_id), reply in zip(comments, replies):
200
  embed = discord.Embed(description=f"**๋Œ“๊ธ€**: {comment}\n**๋‹ต๊ธ€**: {reply}")
201
  await thread.send(embed=embed)
202
 
203
+ # ์›นํ›… ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐœ๋ณ„์ ์œผ๋กœ ์ „์†ก
204
+ webhook_data = {
205
+ "video_id": video_id,
206
+ "replies": [{"comment": comment, "reply": reply, "comment_id": comment_id}]
207
+ }
208
+
209
+ # ์›นํ›… ๋ฐ์ดํ„ฐ ์ „์†ก
210
+ success = await send_webhook_data(session, webhook_data, 1) # ์ฒญํฌ ๋ฒˆํ˜ธ๋Š” ์—ฌ๊ธฐ์„œ๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , 1์„ ๊ณ ์ •๊ฐ’์œผ๋กœ ์‚ฌ์šฉ
211
+ if not success:
212
+ logging.error("์›นํ›…์„ ํ†ตํ•œ ๋ฐ์ดํ„ฐ ์ „์†ก ์‹คํŒจ")
213
 
214
+ await asyncio.sleep(1) # ๋‹ค์Œ ๋‹ต๊ธ€ ์ „์†ก ์ „์— ์ž ์‹œ ๋Œ€๊ธฐ (ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋Œ€๊ธฐ ์‹œ๊ฐ„ ์กฐ์ ˆ)
 
 
 
 
215
 
216
+
217
+ #async def create_thread_and_send_replies(message, video_id, comments, replies, session):
218
+ # thread = await message.channel.create_thread(name=f"{message.author.name}์˜ ๋Œ“๊ธ€ ๋‹ต๊ธ€", message=message)
219
+ # webhook_data = {"video_id": video_id, "replies": []}
220
+ # for (comment, comment_id), reply in zip(comments, replies):
221
+ # embed = discord.Embed(description=f"**๋Œ“๊ธ€**: {comment}\n**๋‹ต๊ธ€**: {reply}")
222
+ # await thread.send(embed=embed)
223
+ # ์›นํ›… ๋ฐ์ดํ„ฐ ์ค€๋น„ (comment id ํฌํ•จ)
224
+ # webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
225
+ # ๋ฐ์ดํ„ฐ๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ๋‚˜๋ˆ„์–ด ์ „์†ก
226
+ # chunk_size = 1 # ์ „์†กํ•  ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ 1๋กœ ์„ค์ •ํ•˜์—ฌ ๊ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ„๋„๋กœ ์ „์†ก
227
+ # for i in range(0, len(webhook_data["replies"]), chunk_size):
228
+ # chunk = webhook_data["replies"][i:i+chunk_size]
229
+ # chunk_data = {"video_id": video_id, "replies": chunk}
230
+ # success = await send_webhook_data(session, chunk_data, i // chunk_size + 1)
231
+ # if not success:
232
+ # logging.error(f"๋ฐ์ดํ„ฐ ์ „์†ก ์‹คํŒจ: {i // chunk_size + 1} ๋ฒˆ์งธ ์ฒญํฌ")
233
 
234
  if __name__ == "__main__":
235
  discord_client = MyClient(intents=intents)