seawolf2357 commited on
Commit
5e42677
Β·
verified Β·
1 Parent(s): 1c6f3d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -42,7 +42,7 @@ class MyClient(discord.Client):
42
  # 봇이 μ‹œμž‘λ  λ•Œ μ•ˆλ‚΄ λ©”μ‹œμ§€λ₯Ό 전솑
43
  channel = self.get_channel(SPECIFIC_CHANNEL_ID)
44
  if channel:
45
- await channel.send("찾고싢은 고해상도 λ™μ˜μƒμ— λŒ€ν•œ μ„€λͺ…을 ν•œ λ¬Έμž₯ λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ„Έμš”. 예) ν•˜λŠ˜μ„ λ‚ μ•„κ°€λŠ” λΉ„ν–‰κΈ°")
46
 
47
  async def on_message(self, message):
48
  if message.author == self.user:
@@ -101,7 +101,7 @@ async def search_videos(keywords):
101
  }
102
  params = {
103
  "query": keywords,
104
- "per_page": 80 # μ΅œλŒ€ 20개 λ™μ˜μƒμ„ κ°€μ Έμ˜΅λ‹ˆλ‹€
105
  }
106
  response = requests.get(PEXELS_API_VIDEO_URL, headers=headers, params=params)
107
  if response.status_code == 200:
@@ -114,11 +114,10 @@ async def search_videos(keywords):
114
  return None
115
 
116
  async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
117
- # λ©”μ‹œμ§€μ— 이미 μ“°λ ˆλ“œκ°€ μžˆλŠ”μ§€ 확인
118
- existing_thread = message.thread
119
- if existing_thread:
120
- thread = existing_thread
121
- else:
122
  # μƒˆ μ“°λ ˆλ“œ 생성
123
  thread = await message.channel.create_thread(name=f"{message.author.name}의 검색 κ²°κ³Ό", message=message)
124
 
@@ -127,6 +126,15 @@ async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
127
  for url in video_urls:
128
  await thread.send(url)
129
 
 
 
 
 
 
 
 
 
 
130
  if __name__ == "__main__":
131
  discord_client = MyClient(intents=intents)
132
  discord_client.run(os.getenv('DISCORD_TOKEN'))
 
42
  # 봇이 μ‹œμž‘λ  λ•Œ μ•ˆλ‚΄ λ©”μ‹œμ§€λ₯Ό 전솑
43
  channel = self.get_channel(SPECIFIC_CHANNEL_ID)
44
  if channel:
45
+ await channel.send("찾고싢은 λ™μ˜μƒμ— λŒ€ν•œ μ„€λͺ…을 ν•œ λ¬Έμž₯ λ‹¨μœ„λ‘œ μž…λ ₯ν•˜μ„Έμš”. 예) λˆˆλ°­μ—μ„œ λ›°μ–΄ λ…ΈλŠ” κ°•μ•„μ§€")
46
 
47
  async def on_message(self, message):
48
  if message.author == self.user:
 
101
  }
102
  params = {
103
  "query": keywords,
104
+ "per_page": 20 # μ΅œλŒ€ 20개 λ™μ˜μƒμ„ κ°€μ Έμ˜΅λ‹ˆλ‹€
105
  }
106
  response = requests.get(PEXELS_API_VIDEO_URL, headers=headers, params=params)
107
  if response.status_code == 200:
 
114
  return None
115
 
116
  async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
117
+ # λ©”μ‹œμ§€μ— λŒ€ν•΄ 이미 μƒμ„±λœ μ“°λ ˆλ“œλ₯Ό 찾음
118
+ thread = await find_existing_thread(message)
119
+
120
+ if not thread:
 
121
  # μƒˆ μ“°λ ˆλ“œ 생성
122
  thread = await message.channel.create_thread(name=f"{message.author.name}의 검색 κ²°κ³Ό", message=message)
123
 
 
126
  for url in video_urls:
127
  await thread.send(url)
128
 
129
+ async def find_existing_thread(message):
130
+ # μ±„λ„μ˜ λͺ¨λ“  μ“°λ ˆλ“œ κ°€μ Έμ˜€κΈ°
131
+ threads = await message.channel.threads()
132
+ # μ£Όμ–΄μ§„ λ©”μ‹œμ§€μ™€ μ—°κ΄€λœ μ“°λ ˆλ“œλ₯Ό μ°ΎκΈ°
133
+ for thread in threads:
134
+ if thread.id == message.id:
135
+ return thread
136
+ return None
137
+
138
  if __name__ == "__main__":
139
  discord_client = MyClient(intents=intents)
140
  discord_client.run(os.getenv('DISCORD_TOKEN'))