def apply_vars_dict(self, tag, message): for k, v in tag.items(): if isinstance(v, dict): tag[k] = self.apply_vars_dict(v, message) elif isinstance(v, str): tag[k] = apply_vars(self, v, message) elif isinstance(v, list): tag[k] = [self.apply_vars_dict(_v, message) for _v in v] if k == 'timestamp': tag[k] = v[:-1] return tag
def apply_vars_dict(self, tag: Dict[str, Union[Any]], message: discord.Message) -> Dict[str, Union[Any]]: for k, v in tag.items(): if isinstance(v, dict): tag[k] = self.apply_vars_dict(v, message) elif isinstance(v, str): tag[k] = apply_vars(self.bot, v, message) elif isinstance(v, list): tag[k] = [self.apply_vars_dict(_v, message) for _v in v] if k == 'timestamp': tag[k] = v[:-1] return tag
def format_message(self, tag, message): try: tag = json.loads(tag) except json.JSONDecodeError: # message is not embed tag = apply_vars(self, tag, message) tag = {'content': tag} else: # message is embed tag = self.apply_vars_dict(tag, message) if any(i in message for i in ('embed', 'content')): tag['embed'] = discord.Embed.from_dict(tag['embed']) else: tag = None return tag
def format_message(self, tag: str, message: discord.Message) -> Dict[str, Union[Any]]: updated_tag: Dict[str, Union[Any]] try: updated_tag = json.loads(tag) except json.JSONDecodeError: # message is not embed tag = apply_vars(self.bot, tag, message) updated_tag = {'content': tag} else: # message is embed updated_tag = self.apply_vars_dict(updated_tag, message) if 'embed' in updated_tag: updated_tag['embed'] = discord.Embed.from_dict( updated_tag['embed']) else: updated_tag = None return updated_tag