Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Created by .ignore support plugin (hsz.mobi)

# Project Specific Ignores
.telegramToken

### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -153,4 +157,3 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.8.12-slim-buster

# YOUR COMMANDS HERE
# ....
# ....
WORKDIR /TelegramAI
COPY . .
RUN pip install -r requirements.txt

CMD ["python3", "app.py"]
CMD ["python3", "app.py"]
26 changes: 22 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def download_user_photo(self, quality=0):
file_info = self.bot.get_file(self.current_msg.photo[quality].file_id)
data = self.bot.download_file(file_info.file_path)

# TODO save `data` as a photo in `file_info.file_path` path
with open(file_info.file_path, 'wb') as new_file:
new_file.write(data)

def handle_message(self, message):
"""Bot Main message handler"""
Expand All @@ -61,14 +62,31 @@ def handle_message(self, message):


class YoutubeBot(Bot):
pass
def handle_message(self, message):
if self.is_current_msg_photo():
self.download_user_photo()
return

videos = search_download_youtube_video(message.text, 1)

if not videos:
text_to_send = 'Error: Could not find a youtube video matching your search.'
self.send_text_with_quote(text_to_send, message_id=message.message_id)
return

for video in videos:
self.send_text(video['url'])


if __name__ == '__main__':
with open('.telegramToken') as f:
_token = f.read()

my_bot = Bot(_token)
my_bot.start()
# my_bot = Bot(_token)
# my_bot.start()

# quote_bot = QuoteBot(_token)
# quote_bot.start()

youtube_bot = YoutubeBot(_token)
youtube_bot.start()