seawolf2357 commited on
Commit
11fec5e
β€’
1 Parent(s): 262fbfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -1
app.py CHANGED
@@ -40,6 +40,71 @@ WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY1M
40
  # 전솑 μ‹€νŒ¨ μ‹œ μž¬μ‹œλ„ 횟수
41
  MAX_RETRIES = 3
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  class MyClient(discord.Client):
44
  def __init__(self, *args, **kwargs):
45
  super().__init__(*args, **kwargs)
@@ -192,7 +257,7 @@ async def create_thread_and_send_replies(message, video_id, comments, replies, s
192
  webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
193
 
194
  # 데이터λ₯Ό μ—¬λŸ¬ 번 λ‚˜λˆ„μ–΄ 전솑
195
- chunk_size = 10 # 전솑할 λ°μ΄ν„°μ˜ 개수
196
  for i in range(0, len(webhook_data["replies"]), chunk_size):
197
  chunk = webhook_data["replies"][i:i+chunk_size]
198
  chunk_data = {"video_id": video_id, "replies": chunk}
 
40
  # 전솑 μ‹€νŒ¨ μ‹œ μž¬μ‹œλ„ 횟수
41
  MAX_RETRIES = 3
42
 
43
+ class MyClient(discord.Client):
44
+ def __init__(self, *args, **kwargs):
45
+ super().__init__(*args, **kwargs)
46
+ self.is_processing = False
47
+ self.session = None
48
+
49
+ async def on_ready(self):
50
+ logging.info(f'{self.user}둜 λ‘œκ·ΈμΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€!')
51
+
52
+ # web.py 파일 μ‹€ν–‰
53
+ subprocess.Popen(["python", "web.py"])
54
+ logging.info("Web.py μ„œλ²„κ°€ μ‹œμž‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
55
+
56
+ # aiohttp ν΄λΌμ΄μ–ΈνŠΈ μ„Έμ…˜ 생성
57
+ self.session = aiohttp.ClientSession()
58
+
59
+ # 봇이 μ‹œμž‘λ  λ•Œ μ•ˆλ‚΄ λ©”μ‹œμ§€λ₯Ό 전솑
60
+ channel = self.get_channel(SPECIFIC_CHANNEL_ID)
61
+ if channel:
62
+ await channel.send("유튜브 λΉ„λ””μ˜€ URL을 μž…λ ₯ν•˜λ©΄, μžλ§‰κ³Ό λŒ“κΈ€μ„ 기반으둜 닡글을 μž‘μ„±ν•©λ‹ˆλ‹€.")
63
+
64
+ async def on_message(self, message):
65
+ if message.author == self.user:
66
+ returnimport discord
67
+ import logging
68
+ import os
69
+ import re
70
+ import asyncio
71
+ import subprocess
72
+ import aiohttp
73
+ from huggingface_hub import InferenceClient
74
+ from googleapiclient.discovery import build
75
+ from youtube_transcript_api import YouTubeTranscriptApi
76
+ from youtube_transcript_api.formatters import TextFormatter
77
+ from dotenv import load_dotenv
78
+
79
+ # ν™˜κ²½ λ³€μˆ˜ λ‘œλ“œ
80
+ load_dotenv()
81
+
82
+ # λ‘œκΉ… μ„€μ •
83
+ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
84
+
85
+ # μΈν…νŠΈ μ„€μ •
86
+ intents = discord.Intents.default()
87
+ intents.message_content = True
88
+ intents.messages = True
89
+ intents.guilds = True
90
+ intents.guild_messages = True
91
+
92
+ # μΆ”λ‘  API ν΄λΌμ΄μ–ΈνŠΈ μ„€μ •
93
+ hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
94
+
95
+ # YouTube API μ„€μ •
96
+ API_KEY = os.getenv("YOUTUBE_API_KEY")
97
+ youtube_service = build('youtube', 'v3', developerKey=API_KEY)
98
+
99
+ # νŠΉμ • 채널 ID
100
+ SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
101
+
102
+ # μ›Ήν›… URL μ„€μ •
103
+ WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY1MDYzMjA0MzA1MjY4NTUzMDUxMzUi_pc"
104
+
105
+ # 전솑 μ‹€νŒ¨ μ‹œ μž¬μ‹œλ„ 횟수
106
+ MAX_RETRIES = 3
107
+
108
  class MyClient(discord.Client):
109
  def __init__(self, *args, **kwargs):
110
  super().__init__(*args, **kwargs)
 
257
  webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
258
 
259
  # 데이터λ₯Ό μ—¬λŸ¬ 번 λ‚˜λˆ„μ–΄ 전솑
260
+ chunk_size = 1 # 전솑할 λ°μ΄ν„°μ˜ 개수λ₯Ό 1둜 μ„€μ •ν•˜μ—¬ 각 데이터λ₯Ό λ³„λ„λ‘œ 전솑
261
  for i in range(0, len(webhook_data["replies"]), chunk_size):
262
  chunk = webhook_data["replies"][i:i+chunk_size]
263
  chunk_data = {"video_id": video_id, "replies": chunk}