def matcher(func): """Add decorated function to skills list for regex matching.""" opsdroid = get_opsdroid() opsdroid.skills.append({ "regex": { "expression": regex, "case_sensitive": case_sensitive }, "skill": func, "config": opsdroid.loader.current_import_config }) return func
def matcher(func): """Add decorated function to skills list for crontab matching.""" opsdroid = get_opsdroid() if opsdroid: config = opsdroid.loader.current_import_config opsdroid.skills.append({ "crontab": crontab, "skill": func, "config": config, "timezone": timezone }) return func
async def respond(self, text): """Respond to this message using the connector it was created by.""" opsdroid = get_opsdroid() response = copy(self) response.text = text await self.connector.respond(response) if not self.responded_to: now = datetime.now() opsdroid.stats["total_responses"] = \ opsdroid.stats["total_responses"] + 1 opsdroid.stats["total_response_time"] = \ opsdroid.stats["total_response_time"] + \ (now - self.created).total_seconds() self.responded_to = True
def matcher(func): """Add decorated function to skills list for regex matching.""" opsdroid = get_opsdroid() if opsdroid: config = opsdroid.loader.current_import_config regex_setup = { "expression": regex, "case_sensitive": case_sensitive, "score_factor": score_factor or REGEX_SCORE_FACTOR, } opsdroid.skills.append({ "regex": regex_setup, "skill": func, "config": config }) return func
async def respond(self, text, room=None): """Respond to this message using the connector it was created by.""" opsdroid = get_opsdroid() response = copy(self) response.text = text if 'thinking-delay' in self.connector.configuration or \ 'typing-delay' in self.connector.configuration: await self._thinking_delay() await self._typing_delay(response.text) await self.connector.respond(response, room) if not self.responded_to: now = datetime.now() opsdroid.stats["total_responses"] = \ opsdroid.stats["total_responses"] + 1 opsdroid.stats["total_response_time"] = \ opsdroid.stats["total_response_time"] + \ (now - self.created).total_seconds() self.responded_to = True
def matcher(func): """Add decorated function to skills list for webhook matching.""" opsdroid = get_opsdroid() config = opsdroid.loader.current_import_config opsdroid.skills.append({ "webhook": webhook, "skill": func, "config": config }) async def wrapper(req, opsdroid=opsdroid, config=config): """Wrap up the aiohttp handler.""" _LOGGER.info("Running skill %s via webhook", webhook) opsdroid.stats["webhooks_called"] = \ opsdroid.stats["webhooks_called"] + 1 await func(opsdroid, config, req) return Web.build_response(200, {"called_skill": webhook}) opsdroid.web_server.web_app.router.add_post( "/skill/{}/{}".format(config["name"], webhook), wrapper) opsdroid.web_server.web_app.router.add_post( "/skill/{}/{}/".format(config["name"], webhook), wrapper) return func
def test_opsdroid(self): # Test that get_opsdroid returns None if no instances exist assert get_opsdroid() is None