isup: show state as 'down' if response is an HTTPError
This commit is contained in:
		
							
								
								
									
										11
									
								
								bot/isup.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								bot/isup.py
									
									
									
									
									
								
							| @@ -12,19 +12,22 @@ from . import Plugin | ||||
| class Useless(Plugin): | ||||
|     @command | ||||
|     def isup(self, mask: IrcString, target: IrcString, args: Dict): | ||||
|         """Checks if a address is up or down | ||||
|         """Checks if an address is up or down | ||||
|  | ||||
|         %%isup <address> | ||||
|         """ | ||||
|         address = args['<address>'] | ||||
|         if not address.startswith('http://'): | ||||
|         if not address.startswith('http://') and not address.startswith('https://'): | ||||
|             address = 'https://{}'.format(address) | ||||
|  | ||||
|         try: | ||||
|             requests.head(address) | ||||
|             res = requests.head(address) | ||||
|             res.raise_for_status() | ||||
|             state = 'up' | ||||
|         except requests.ConnectionError: | ||||
|             state = 'down' | ||||
|             state = 'down (timeout)' | ||||
|         except requests.HTTPError as e: | ||||
|             state = f'down ({e.response.status_code} {e.response.reason})' | ||||
|  | ||||
|         parsed = urlparse(address) | ||||
|         return '\x02{}://{}\x02 seems to be \x02{}\x02'.format(parsed.scheme, parsed.netloc, state) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user