forked from dymik739/modular-bot-framework-for-telegram
		
	Merge branch 'master' of http://10.1.1.1:3000/dymik739/modular-bot-framework-for-telegram
This commit is contained in:
		
							parent
							
								
									36793e9946
								
							
						
					
					
						commit
						f1d04954f0
					
				@ -6,6 +6,8 @@ import sys
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
import threading
 | 
					import threading
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from telegram import Message, Chat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# global variables
 | 
					# global variables
 | 
				
			||||||
STOP_REQUESTED = False
 | 
					STOP_REQUESTED = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -179,7 +181,6 @@ def queue_processor():
 | 
				
			|||||||
                        if mod.version == 1:
 | 
					                        if mod.version == 1:
 | 
				
			||||||
                            responce = mod.process(msg)
 | 
					                            responce = mod.process(msg)
 | 
				
			||||||
                            if len(responce) > 0:
 | 
					                            if len(responce) > 0:
 | 
				
			||||||
                                updater.bot.send_message(chat_id = msg.chat.id, text = responce)
 | 
					 | 
				
			||||||
                                print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
 | 
					                                print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
 | 
				
			||||||
                                break
 | 
					                                break
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -201,12 +202,6 @@ def queue_processor():
 | 
				
			|||||||
    print("[INFO] queue_processor thread stops successfully")
 | 
					    print("[INFO] queue_processor thread stops successfully")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# telegram bot processor
 | 
					 | 
				
			||||||
def message_handler(update, context):
 | 
					 | 
				
			||||||
    print("[DEBUG] Received new message") # just for testing
 | 
					 | 
				
			||||||
    message_queue.append(update.message)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# --- Final stage ---
 | 
					# --- Final stage ---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -220,25 +215,6 @@ processor_thread = threading.Thread( target = queue_processor, args = [] )
 | 
				
			|||||||
processor_thread.start()
 | 
					processor_thread.start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# connecting to Telegram servers and listening for messages
 | 
					 | 
				
			||||||
'''
 | 
					 | 
				
			||||||
TOKEN = readfile("config/token")
 | 
					 | 
				
			||||||
if not TOKEN:
 | 
					 | 
				
			||||||
    print("[CRIT] Token has not been defined, quitting")
 | 
					 | 
				
			||||||
    sys.exit(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# connect to Telegram servers
 | 
					 | 
				
			||||||
updater = Updater(TOKEN, use_context = True)
 | 
					 | 
				
			||||||
dispatcher = updater.dispatcher
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# assign the handler for messages
 | 
					 | 
				
			||||||
dispatcher.add_handler(MessageHandler(Filters.text, message_handler))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# run the bot
 | 
					 | 
				
			||||||
updater.start_polling()
 | 
					 | 
				
			||||||
updater.idle()
 | 
					 | 
				
			||||||
'''
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("Enter testing messages one by one, end with an empty line")
 | 
					print("Enter testing messages one by one, end with an empty line")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while True:
 | 
					while True:
 | 
				
			||||||
@ -246,4 +222,4 @@ while True:
 | 
				
			|||||||
    if len(new_msg) == 0:
 | 
					    if len(new_msg) == 0:
 | 
				
			||||||
        break
 | 
					        break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    message_queue.append({'text': new_msg, 'new_chat_photo': [], 'message_id': 74, 'new_chat_members': [], 'delete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created': False, 'chat': {'first_name': 'Дмитро', 'username': 'dmytrofiot23', 'id': 575246355, 'type': 'private'}, 'caption_entities': [], 'channel_chat_created': False, 'date': 1667585646, 'photo': [], 'entities': [], 'from': {'first_name': 'Дмитро', 'id': 575246355, 'is_bot': False, 'username': 'dmytrofiot23', 'language_code': 'en'}})
 | 
					    message_queue.append( Message(9, round(time.time()), Chat(575246355, 'supergroup'), text = new_msg) )
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user