示例#1
0
 def get_string(self, command_name, field_name, *args):
     """Gets string from strings.json file"""
     module_name = inspect.getmodule(inspect.stack()[1][0]).__name__[12:]
     reply = self.find_reply(self.bot.strings, field_name,
                             module_name.split(".") + [command_name])
     if reply:
         return load_json.replace_in_string(reply, self.bot.command_prefix,
                                            *args)
     else:
         print("ERROR: reply not found: " +
               field_name)  # ! To transform to log
     return ""
示例#2
0
 async def send_message(self, channel, reply, *args):
     """Sends back a message/embed response."""
     content = None
     embed = None
     if isinstance(reply, dict):
         reply = load_json.replace_in_object(reply, self.bot.command_prefix,
                                             *args)
         if "content" in reply:
             content = reply["content"]
         if "embed" in reply:
             embed = discord.Embed.from_dict(reply["embed"])
     else:
         content = load_json.replace_in_string(reply,
                                               self.bot.command_prefix,
                                               *args)
     return await channel.send(content, embed=embed)
示例#3
0
 def get_string(self, ctx, field_name, *args, stack_depth=1):
     """Gets string from strings.json file"""
     module_name = self.get_module_name_from_stack(stack_depth)
     modules = module_name.split(".")[:-1]
     if (modules and modules[-1] == "tosurnament"
             and ctx.command.cog_name in [
                 "bracket",
                 "players_spreadsheet",
                 "schedules_spreadsheet",
                 "qualifiers_spreadsheet",
                 "qualifiers_results_spreadsheet",
             ]):
         modules.append("bracket")
     reply = self.find_reply(ctx.guild, self.bot.strings, field_name,
                             modules + [ctx.command.cog_name],
                             ctx.command.name)
     if reply:
         return load_json.replace_in_string(reply, self.bot.command_prefix,
                                            *args)
     else:
         if field_name not in ["parameter", "example_parameter"]:
             self.bot.error("Reply not found: " + ctx.command.cog_name +
                            ": " + ctx.command.name + ": " + field_name)
     return ""