Toggle navigation
Toggle navigation
This project
Loading...
Sign in
wlstp8473
/
telegram_Messenger_Chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
wlstp8473
2021-06-09 05:58:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d5e3fdea7b20de699dc73161b6d9bdd268435c76
d5e3fdea
1 parent
30a7954f
respond
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
respond.py
respond.py
0 → 100644
View file @
d5e3fde
#pip install python-telegram-bot
import
telegram
from
telegram.ext
import
Updater
from
telegram.ext
import
MessageHandler
,
Filters
import
os
#텔레그램 관련 코드
token
=
"1721885449:AAHDGMbjSJfhXxML6nfSCpfiU7SghpL_vOE"
id
=
"1657858421"
bot
=
telegram
.
Bot
(
token
)
updater
=
Updater
(
token
=
token
,
use_context
=
True
)
dispatcher
=
updater
.
dispatcher
updater
.
start_polling
()
#가능한 응답 리스트 목록
menual_message
=
'''진세 모해? #(모해?) '''
bot
.
sendMessage
(
chat_id
=
id
,
text
=
menual_message
)
#특정 단어 시 호출되는 메세지들
mohae_message
=
'''나 내일 입을 옷 고민 중 #(어떤 옷?)'''
#옷 가져오는 거 크롤링 코드,,, 실패
#def cloth_image_crawling(image_num=3):
# if not os.path.exists("./clothimage"):
# os.mkdir("./clothimage")
#
# browser = webdriver.Chrome(r"C:\Users\user\Downloads\chromedriver.exe") ############################경로주의
# browser.implicitly_wait(3)
# wait = WebDriverWait(browser, 10)
#
# browser.get("https://www.google.com/search?q=%EC%97%AC%EC%9E%90+%EC%98%B7+%EC%9D%B4%EB%AF%B8%EC%A7%80&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjenIH-gvrwAhVgUPUHHQIXCrEQ_AUoAXoECAEQAw&biw=1675&bih=836")
# wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.photo_group._listGrid div.thumb img")))
# img = browser.find_elements_by_css_selector("div.photo_group._listGrid div.thumb img")
# for i in img:
# img_url = i.get_attribute("src")
# req.urlretrieve(img_url, "./clothimage/{}.png".format(img.index(i)))
# if img.index(i) == image_num-1:
# break
# browser.close()
### 챗봇 답장 코드
def
handler
(
update
,
context
):
user_text
=
update
.
message
.
text
# 사용자가 보낸 메세지를 user_text 변수에 저장합니다.
# 모해?
if
(
"모해?"
in
user_text
):
bot
.
sendMessage
(
chat_id
=
id
,
text
=
mohae_message
)
elif
(
user_text
==
"어떤 옷?"
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"잠깐만 옷 좀.."
)
#이미지를 디렉토리에서 한장씩 보냄
bot
.
send_photo
(
chat_id
=
id
,
photo
=
open
(
r'C:\Users\user\Documents\project_opensw-chatbot\telegram_Messenger_Chatbot\img\cloth1.jpg'
,
'rb'
))
###절대 경로니까 수정하세요!!!!!!
bot
.
send_photo
(
chat_id
=
id
,
photo
=
open
(
r'C:\Users\user\Documents\project_opensw-chatbot\telegram_Messenger_Chatbot\img\cloth2.jpg'
,
'rb'
))
bot
.
send_photo
(
chat_id
=
id
,
photo
=
open
(
r'C:\Users\user\Documents\project_opensw-chatbot\telegram_Messenger_Chatbot\img\cloth3.jpg'
,
'rb'
))
bot
.
send_message
(
chat_id
=
id
,
text
=
"1~3 번 중에서 어떤게 더 남? (#1~3번)"
)
elif
(
"1번"
in
user_text
)
or
(
"2번"
in
user_text
)
or
(
"3번"
in
user_text
):
###1~3번이 들어오면 오케이
bot
.
send_message
(
chat_id
=
id
,
text
=
"👌"
)
bot
.
send_message
(
chat_id
=
id
,
text
=
"낼 이거 입고 나가야지"
)
bot
.
send_message
(
chat_id
=
id
,
text
=
"진세 밥 먹었어?? #(응응 먹었어, 아직 안 먹었어)"
)
elif
(
user_text
==
"응응 먹었어"
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"우왕 뭐 먹었어? #(닭갈비 먹었어)"
)
elif
(
user_text
==
"닭갈비 먹었어"
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"오,, 대박 이 근처에 대박 유명한 닭갈비 집 있다던데 가봤어?"
)
#################네이버 지도 연결해서 위치 뜨게 하기!! 혹은 크롤링해서 정보 수집 ㄱ
bot
.
send_message
(
chat_id
=
id
,
text
=
"요기인데 - (네이버 지도 연결!!해서 창 띄우기!)"
)
############################################################################################## 이어서 작업 ㄱㄱ
elif
(
user_text
==
"아직 안 먹었어"
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"헐헐 어쩌다?, 같이 뭐라도 먹을래? #(그래 같이 먹자)"
)
elif
(
user_text
==
"그래 같이 먹자"
):
bot
.
send_message
(
chat_id
=
id
,
text
=
"웅웅 집앞으로 나와"
)
########################################################################### 이어서 작업 ㄱㄱㄱ
else
:
update
.
message
.
reply_text
(
"ㅎㅎ"
)
#옷 이미지 크롤릴 코드,,, 실패
# elif (user_text == "어떤 옷?"):
# bot.send_message(chat_id=id, text="잠깐만 옷 좀... (현재 크롤링 중) ...")
# cloth_image_crawling(image_num=3)
#
# # 이미지 한장만 보내기###############################################################################################
# bot.send_photo(chat_id=id, photo=open("./clothimage/0.png", 'rb'))
# # 이미지 여러장 묶어서 보내기
# photo_list = []
# #for i in range(len(os.walk("./clothimage").__next__()[2])): # 이미지 파일 개수만큼 for문 돌리기
# # photo_list.append(telegram.InputMediaPhoto(open("./clothimage/{}.png".format(i), "rb")))
# bot.sendMediaGroup(chat_id=id, media=photo_list)
# bot.sendMessage(chat_id=id, text=menual_message) #############################################
echo_handler
=
MessageHandler
(
Filters
.
text
,
handler
)
dispatcher
.
add_handler
(
echo_handler
)
Please
register
or
login
to post a comment