forked from dingdang-robot/dingdang-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Halt.py
30 lines (26 loc) · 980 Bytes
/
Halt.py
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
# -*- coding: utf-8-*-
# 关闭系统插件
import logging
import sys
import time
import subprocess
reload(sys)
sys.setdefaultencoding('utf8')
WORDS = ["GUANJI"]
SLUG = "halt"
def handle(text, mic, profile, wxbot=None):
logger = logging.getLogger(__name__)
try:
mic.say('将要关闭系统,请在滴一声后进行确认,授权相关操作', cache=True)
input = mic.activeListen(MUSIC=True)
if input is not None and any(word in input for word in [u"确认", u"好", u"是", u"OK"]):
mic.say('授权成功,开始进行相关操作', cache=True)
time.sleep(3)
subprocess.Popen("shutdown -h now", shell=True)
return
mic.say('授权失败,操作已取消,请重新尝试', cache=True)
except Exception, e:
logger.error(e)
mic.say('抱歉,关闭系统失败', cache=True)
def isValid(text):
return any(word in text for word in [u"关机", u"关闭系统"])