Filter useless messages
This commit is contained in:
		
							
								
								
									
										28
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								main.py
									
									
									
									
									
								
							| @@ -132,6 +132,26 @@ async def get_messages(): | ||||
|         return messages | ||||
|  | ||||
|  | ||||
| async def bot_send(destination, message): | ||||
|     silent = False | ||||
|  | ||||
|     if 'tristen' and 'cardinal' in message.lower(): | ||||
|         logging.info('Tristen Cardinal spam, skipping.') | ||||
|         return | ||||
|  | ||||
|     if '@Y@o@u@' in message: | ||||
|         logging.info('Voice mail alert, muting.') | ||||
|         silent = True | ||||
|  | ||||
|     if '@M@e@s@s@a@g@e@' in message: | ||||
|         logging.info('Voice mail alert, muting.') | ||||
|         silent = True | ||||
|  | ||||
|     tg = await bot.send_message(destination, message, link_preview=False, silent=silent) | ||||
|  | ||||
|     logging.info('Sent TG bot message %s', tg.id) | ||||
|  | ||||
|  | ||||
| async def check_messages(): | ||||
|     messages = await get_messages() | ||||
|  | ||||
| @@ -147,9 +167,7 @@ async def check_messages(): | ||||
|             message['text'], | ||||
|         ) | ||||
|  | ||||
|         tg = await bot.send_message(settings.TANNER_ID, bot_message, link_preview=False) | ||||
|  | ||||
|         logging.info('Sent TG bot message %s', tg.id) | ||||
|         await bot_send(settings.TANNER_ID, bot_message) | ||||
|  | ||||
|         await delete_message(message['mid']) | ||||
|  | ||||
| @@ -182,7 +200,7 @@ async def send(event): | ||||
|     if res: | ||||
|         await event.reply('ok') | ||||
|     else: | ||||
|         await event.reply('Error sending SMS.') | ||||
|         await event.reply('Error sending SMS. Not allowed special characters?') | ||||
|  | ||||
| @bot.on(events.NewMessage(pattern='^(?!\/).*$')) | ||||
| async def new_message(event): | ||||
| @@ -212,7 +230,7 @@ async def new_message(event): | ||||
|     res = await send_message(from_field, event.raw_text) | ||||
|  | ||||
|     if not res: | ||||
|         await event.reply('Error sending SMS.') | ||||
|         await event.reply('Error sending SMS. Not allowed special characters?') | ||||
|  | ||||
|  | ||||
| async def main(): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user