This repository was archived by the owner on Dec 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2.py
More file actions
55 lines (49 loc) · 1.61 KB
/
test2.py
File metadata and controls
55 lines (49 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import (
ReplyKeyboardMarkup,
KeyboardButton,
InlineKeyboardMarkup,
InlineKeyboardButton
)
from random import choice
import json
import random
import time
import pprint
#自行更新 #自行更新 #自行更新
TOKEN ="" #自行更新#自行更新
#自行更新 #自行更新 #自行更新
bot = telepot.Bot(TOKEN)
def print_msg(msg):
print(json.dumps(msg, indent=4))
# 接收chat後執行:
def on_chat(msg):
header = telepot.glance(msg, flavor="chat")
print_msg(msg)
#data=""
if header[0] == "text":
text = msg["text"]
username = msg["from"]["username"]
if text.startswith("/"):
command = text.lstrip("/")
print(command)
if command == "Hello" or command == "您好" or command == "你好" or command == "Hi":
print(1)
text = "Hi!需要甚麼服務呢?!"
bot.sendMessage(header[2], text.format(msg["from"]["first_name"]))
elif command == 'weather' or command == '天氣' or command == '氣象':
print(2)
text = ' https://www.cwb.gov.tw/V7/forecast/ '
bot.sendMessage(header[2], text.format(msg["from"]["first_name"]))
elif command == "mv":
print(3)
text = ' @youtube '
bot.sendMessage(header[2], text)
else :
text = "海豹還聽不懂你在說什麼QQ"
bot.sendMessage(header[2], text.format(msg["from"]["first_name"]))
MessageLoop(bot, on_chat).run_as_thread()
print('Listening ...')
while True:
time.sleep(10)