diff --git a/bot/plugin_manager.py b/bot/plugin_manager.py index 7faea10..9e60b0a 100644 --- a/bot/plugin_manager.py +++ b/bot/plugin_manager.py @@ -12,6 +12,7 @@ from plugins.ddg_web_search import DDGWebSearchPlugin from plugins.wolfram_alpha import WolframAlphaPlugin from plugins.deepl import DeeplTranslatePlugin from plugins.worldtimeapi import WorldTimeApiPlugin +from plugins.whois import WhoisPlugin class PluginManager: @@ -34,6 +35,7 @@ class PluginManager: 'dice': DicePlugin, 'deepl_translate': DeeplTranslatePlugin, 'gtts_text_to_speech': GTTSTextToSpeech, + 'whois': WhoisPlugin, } self.plugins = [plugin_mapping[plugin]() for plugin in enabled_plugins if plugin in plugin_mapping] diff --git a/bot/plugins/whois.py b/bot/plugins/whois.py new file mode 100644 index 0000000..34c00ef --- /dev/null +++ b/bot/plugins/whois.py @@ -0,0 +1,32 @@ +from typing import Dict +from .plugin import Plugin +import whois + +class WhoisPlugin(Plugin): + """ + A plugin to query whois database + """ + def get_source_name(self) -> str: + return "Whois" + + def get_spec(self) -> [Dict]: + return [{ + "name": "get_whois", + "description": "Get whois registration and expiry information for a domain", + "parameters": { + "type": "object", + "properties": { + "domain": {"type": "string", "description": "Domain name"} + }, + "required": ["domain"], + }, + }] + + async def execute(self, function_name, **kwargs) -> Dict: + try: + whois_result = whois.whois(kwargs['domain']) + return whois_result + except whois.parser.PywhoisError as e: + return {'result': 'No such domain found'} + except Exception as e: + return {'error': 'An unexpected error occurred: ' + str(e)}