Ejemplo n.º 1
0
def translate(ctx, path, *args):
    #print(args)
    #print(str(args))
    if ":" not in path:
        return (path % args)
    string = path.split(":")
    lan = dueserverconfig.get_language(ctx.guild.id)
    try:
        f = json.load(
            open(
                "dueutil/game/configs/localization/" + str(lan) + "/" +
                string[0] + "/" + string[1] + ".json", "r"))
        msg = f[string[2]]
    except (IndexError, FileNotFoundError, KeyError):
        #try:
        f = json.load(
            open(
                "dueutil/game/configs/localization/en/" + string[0] + "/" +
                string[1] + ".json", "r"))
        msg = f[string[2]]
        #except (IndexError, FileNotFoundError, KeyError):
        #raise util.BattleBananaException(ctx.channel, "Translation error, missing English translation")
        #TODO other translations for non commands
        #raise util.BattleBananaException(ctx.channel, translations.translate(ctx, "util:setlanguage:ERROR"))

    if "[CMD_KEY]" in msg:
        prefix = dueserverconfig.server_cmd_key(ctx.guild)
        msg = msg.replace("[CMD_KEY]", prefix)

    return (msg % args)
Ejemplo n.º 2
0
def translate_help(ctx, path, *args):
    string = path.split(":")
    lan = dueserverconfig.get_language(ctx.guild.id)
    try:
        f = json.load(
            open(
                "dueutil/game/configs/localization/" + str(lan) + "/" +
                string[0] + "/" + string[1] + ".json", "r"))
    except (IndexError, FileNotFoundError, KeyError):
        try:
            f = json.load(
                open(
                    "dueutil/game/configs/localization/en/" + string[0] + "/" +
                    string[1] + ".json", "r"))
        except (IndexError, FileNotFoundError, KeyError):
            if "[CMD_KEY]" in path:
                prefix = dueserverconfig.server_cmd_key(ctx.guild)
                path = path.replace("[CMD_KEY]", prefix)
            return path

    if "\n\nNote" in string[2]:
        string2 = string[2].split("\n\nNote")
        msg = f[string2[0]]
        msg += "\nNote:" + string2[1]
    else:
        msg = f[string[2]]

    if "[CMD_KEY]" in msg:
        prefix = dueserverconfig.server_cmd_key(ctx.guild)
        msg = msg.replace("[CMD_KEY]", prefix)

    return (msg % args)


#def getLocale(ctx, player, path):
#    string = path.split(":")
#    lan = dueserverconfig.get_language(ctx.guild.id)
#    try:
#        f = json.load(open("dueutil/game/configs/localization/"+str(lan)+"/"+string[0]+"/"+string[1]+".json", "r"))
#    except (IndexError, FileNotFoundError):
#        return "n/a"
#    msg = f[string[2]]
#
#    if "[PLAYER]" in msg:
#        msg = msg.replace("[PLAYER]", str(player))
#
#    return msg
Ejemplo n.º 3
0
 def on_message(self, message):
     if (message.author == self.user or message.channel.is_private
             or message.author.bot or not loaded()):
         return
     mentions_self_regex = "<@.?" + self.user.id + ">"
     if re.match("^" + mentions_self_regex, message.content):
         message.content = re.sub(
             mentions_self_regex + "\s*",
             dueserverconfig.server_cmd_key(message.server),
             message.content)
     yield from events.on_message_event(message)
Ejemplo n.º 4
0
    async def on_message(self, message):
        if (message.author == self.user or message.author.bot
                or isinstance(message.channel, discord.abc.PrivateChannel)
                or not self.is_ready()):
            return

        owner = message.author
        if owner.id == config["owner"] and not permissions.has_permission(
                owner, Permission.BANANA_OWNER):
            permissions.give_permission(owner, Permission.BANANA_OWNER)

        # what are you doing daughter - dev
        # fixing mac's shitty slow regex parser - me, theel
        message.content = message.content.replace(
            f"<@!{self.user.id}>", dueserverconfig.server_cmd_key(
                message.guild), 1) if message.content.startswith(
                    f"<@!{self.user.id}>") else message.content
        message.content = message.content.replace(
            f"<@{self.user.id}>", dueserverconfig.server_cmd_key(
                message.guild), 1) if message.content.startswith(
                    f"<@{self.user.id}>") else message.content

        await events.on_message_event(message)
Ejemplo n.º 5
0
    def on_message(self, message):
        if (message.author == self.user or message.channel.is_private
                or not loaded()):
            return
        try:
            if message.author.bot:
                return
        except:
            return
        if 0 <= (int(time.time()) % 900) <= 1.5:
            shard_number = shard_clients.index(self) + 1
            server_count = util.get_server_count()
            help_status = discord.Game(name="dueutil.org in %d servers!" %
                                       (server_count))
            yield from self.change_presence(game=help_status, afk=False)
        mentions_self_regex = "<@.?" + self.user.id + ">"
        if re.match("^" + mentions_self_regex, message.content):
            message.content = re.sub(
                mentions_self_regex + "\s*",
                dueserverconfig.server_cmd_key(message.server),
                message.content)
#        try:
        yield from events.on_message_event(message)
Ejemplo n.º 6
0
async def say(ctx, path, *args, **kwargs):
    #print(args)
    #if type(channel) is str:
    #    # Guild/Channel id
    #    server_id, channel_id = channel.split("/")
    #    channel = util.get_guild(int(server_id)).get_channel(int(channel_id))
    #if asyncio.get_event_loop() != clients[0].loop:
    #    # Allows it to speak across shards
    #    clients[0].run_task(say, *((channel,) + args), **kwargs)
    #else:
    try:
        string = str(path).split(":")
        lan = dueserverconfig.get_language(ctx.guild.id)
        try:
            f = json.load(
                open(
                    "dueutil/game/configs/localization/" + str(lan) + "/" +
                    string[0] + "/" + string[1] + ".json", "r"))
            msg = f[string[2]]
        except (IndexError, FileNotFoundError, KeyError):
            #try:
            f = json.load(
                open(
                    "dueutil/game/configs/localization/en/" + string[0] + "/" +
                    string[1] + ".json", "r"))
            msg = f[string[2]]
            #except (IndexError, FileNotFoundError, KeyError):
            #raise util.BattleBananaException(ctx.channel, "Translation error, missing English translation")

        if "[CMD_KEY]" in msg:
            prefix = dueserverconfig.server_cmd_key(ctx.guild)
            msg = msg.replace("[CMD_KEY]", prefix)

        return await ctx.reply((msg % args), **kwargs)
    except discord.Forbidden as send_error:
        raise util.SendMessagePermMissing(send_error)