mirror of
				https://gitlab.com/akasroua/covot
				synced 2025-11-04 02:39:50 +01:00 
			
		
		
		
	Migrate bot to telethon library
This commit is contained in:
		
							parent
							
								
									7b2981bb8c
								
							
						
					
					
						commit
						2c63287f9d
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1 +1,2 @@
 | 
				
			|||||||
src/constants.py
 | 
					src/constants.py
 | 
				
			||||||
 | 
					*.session
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ with pkgs;
 | 
				
			|||||||
mkShell {
 | 
					mkShell {
 | 
				
			||||||
  buildInputs = [
 | 
					  buildInputs = [
 | 
				
			||||||
    python38
 | 
					    python38
 | 
				
			||||||
    python38Packages.python-telegram-bot
 | 
					    python38Packages.telethon
 | 
				
			||||||
    python38Packages.aiosmtpd
 | 
					    python38Packages.aiosmtpd
 | 
				
			||||||
    python38Packages.pytest
 | 
					    python38Packages.pytest
 | 
				
			||||||
  ];
 | 
					  ];
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										31
									
								
								src/bot.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/bot.py
									
									
									
									
									
								
							@ -1,30 +1,19 @@
 | 
				
			|||||||
from telegram.ext import Updater, CommandHandler
 | 
					from telethon import TelegramClient, events
 | 
				
			||||||
from constants import TOKEN
 | 
					from constants import API_ID, API_HASH, BOT_TOKEN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bot = TelegramClient("bot", API_ID, API_HASH).start(bot_token=BOT_TOKEN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def initialize_bot():
 | 
					@bot.on(events.NewMessage(pattern="/start"))
 | 
				
			||||||
    updater = Updater(token=TOKEN, use_context=True)
 | 
					async def start(event):
 | 
				
			||||||
    dispatcher = updater.dispatcher
 | 
					    await event.respond(
 | 
				
			||||||
    return updater, dispatcher
 | 
					        "Hola, muy buenas. Gracias por ponerte en contacto con UGR Tracing Bot. Para poder continuar con el proceso por favor responda a este mensaje con un identificador único (DNI o correo institucional). Muchas gracias."
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def start_callback(update, context):
 | 
					 | 
				
			||||||
    context.bot.send_message(
 | 
					 | 
				
			||||||
        chat_id=update.effective_chat.id,
 | 
					 | 
				
			||||||
        text="Hola, muy buenas. Gracias por ponerte en contacto con UGR Tracing Bot. Para poder continuar con el proceso por favor responda a este mensaje con un identificador único (DNI o correo institucional). Muchas gracias.",
 | 
					 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					    raise events.StopPropagation
 | 
				
			||||||
 | 
					 | 
				
			||||||
def add_callbacks(dispatcher):
 | 
					 | 
				
			||||||
    start_handler = CommandHandler("start", start_callback)
 | 
					 | 
				
			||||||
    dispatcher.add_handler(start_handler)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    updater, dispatcher = initialize_bot()
 | 
					    bot.run_until_disconnected()
 | 
				
			||||||
    add_callbacks(dispatcher)
 | 
					 | 
				
			||||||
    updater.start_polling()
 | 
					 | 
				
			||||||
    updater.idle()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user