1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-11-28 21:39:53 +02:00

New way to launch archie, telegram bot, bat for fast install used packages (except pyAudio)

This commit is contained in:
MarkParker5
2020-08-30 00:40:02 +03:00
parent 5159471db4
commit 171217f808
12 changed files with 247 additions and 62 deletions

59
telegram_bot.py Normal file
View File

@@ -0,0 +1,59 @@
from Command import Command
import SpeechRecognition
import Text2Speech
import SmallTalk
import telebot
import config
import QA
threads = []
online = True
voids = 0
memory = []
voice = Text2Speech.Engine()
listener= SpeechRecognition.SpeechToText()
bot = telebot.TeleBot(config.telebot)
def reply(id, responce):
if responce['text']:
bot.send_message(id, responce['text'])
if responce['voice']:
bot.send_voice(id, voice.generate(responce['voice']).getBytes() )
def check_threads(threads):
for thread in threads:
if thread['finish_event'].is_set():
responce = thread['thread'].join()
reply(thread['id'], responce)
thread['finish_event'].clear()
del thread
def main(id, text):
text = text.lower()
if Command.isRepeat(text):
reply(memory[0]['responce']);
return
try: cmd, params = memory[0]['cmd'].checkContext(text).values(); params = {**memory[0]['params'], **params}
except: cmd, params = Command.reg_find(text).values()
responce = cmd.start(params)
reply(id, responce)
if responce['type'] == 'background': # add background thread to list
responce['thread']['id'] = id
threads.append(responce['thread'])
memory.insert(0, {
'cmd': cmd,
'params': params,
'responce': responce,
})
@bot.message_handler(content_types = ['text'])
def execute(msg):
main(msg.chat.id, msg.text)
while True:
#try:
print("Start polling...")
bot.polling(callback = check_threads, args = (threads,) )
#except:
print("Polling failed")