Exemplo n.º 1
0
async def disconnect_guild_call(context_obj, arguments):
    """Hang up or stop trying to connect the call."""
    context_obj.channel_data.guild_call.connecting = False

    cmd_user_msg = embeds.PaginatedEmbed(
        await context_obj.language.get_text("guild_call_disconnected_title"))
    cmd_user_msg.embed.description = await context_obj.language.get_text(
        "guild_call_disconnected_desc")

    if context_obj.channel_data.guild_call.connected_channel is not None:
        connected_channel = context_obj.channel_data.guild_call.connected_channel
        connected_context = await context.get_context_from_channel(
            connected_channel)

        context_obj.channel_data.guild_call.messages = {}
        connected_context.channel_data.guild_call.messages = {}

        context_obj.channel_data.guild_call.connected_channel = None
        connected_context.channel_data.guild_call.connected_channel = None
        connected_context.channel_data.guild_call.connecting = False

        connected_msg = embeds.PaginatedEmbed(
            await connected_context.language.get_text(
                "other_party_disconnected_guild_call_title"))

        connected_msg.embed.description = await connected_context.language.get_text(
            "other_party_disconnected_guild_call_desc")

        await connected_msg.send(connected_context,
                                 channel=connected_channel,
                                 thumbnail=context_obj.message.guild.icon_url,
                                 author_icon=connected_channel.guild.icon_url)

    await cmd_user_msg.send(context_obj)
    return True
Exemplo n.º 2
0
async def connect_guild_call(context_obj, arguments):
    """Try to connect to a guild call."""
    disconnect_cmd = definitions.COMMANDS.get_sub_command_from_path(
        "guild_call", "disconnect")

    context_obj.channel_data.guild_call.connecting = True

    cmd_user_msg = embeds.PaginatedEmbed(
        await context_obj.language.get_text("guild_call_connecting_title"))
    cmd_user_msg.embed.description = "📡 " + await context_obj.language.get_text(
        "guild_call_connecting_desc", {
            "disconnect_cmd": await
            disconnect_cmd.get_command_string(context_obj)
        })

    await cmd_user_msg.send(context_obj)

    for key, channel_data in definitions.DATA_CACHE["channels"].items():
        channel_object = definitions.CLIENT.get_channel(key)
        valid_channel = (
            channel_data.guild_call.connecting
            and channel_data.guild_call.connected_channel is None
            and context_obj.message.guild.id != channel_object.guild.id)

        if valid_channel:
            channel_data.guild_call.connected_channel = context_obj.message.channel
            context_obj.channel_data.guild_call.connected_channel = channel_object
            channel_data.guild_call.connecting = False
            context_obj.channel_data.guild_call.connecting = False

            # Send messages to both channels indicating they can now talk.

            cmd_user_msg = embeds.PaginatedEmbed(
                await
                context_obj.language.get_text("guild_call_connected_title"))

            cmd_user_msg.embed.description = await context_obj.language.get_text(
                "guild_call_connected_desc")

            contact_context = await context.get_context_from_channel(
                channel_object)
            contact_channel_msg = embeds.PaginatedEmbed(
                await contact_context.language.get_text(
                    "guild_call_connected_title"))

            contact_channel_msg.embed.description = await context_obj.language.get_text(
                "guild_call_connected_desc")

            await cmd_user_msg.send(context_obj,
                                    thumbnail=channel_object.guild.icon_url)
            await contact_channel_msg.send(
                contact_context,
                channel=channel_object,
                thumbnail=context_obj.message.guild.icon_url,
                author_icon=channel_object.guild.icon_url)

            break

    return True
Exemplo n.º 3
0
async def add_shortcut(context, arguments, platform_type):
    """
    Add a shortcut in the database.

    Parametre "platform_type" is "category", "channel", "guild" or "user".
    """
    shortcut = Shortcut(arguments[0], context.message.author.id, arguments[1])
    data_object = getattr(context, platform_type + "_data")

    data_object.shortcuts[shortcut.name] = shortcut
    await database_functions.insert_shortcut(context, shortcut, platform_type)

    message = embeds.PaginatedEmbed(
        await context.language.get_text(platform_type + "_shortcut_added_title"))

    shortcut_cmd = definitions.COMMANDS.sub_commands["shortcut"]
    shortcut_name = shortcut.name
    if " " in shortcut_name:
        shortcut_name = '"' + shortcut_name + '"'

    shortcut_call = "{shortcut_cmd} {shortcut_name}".format(
        shortcut_cmd=await shortcut_cmd.get_command_string(context),
        shortcut_name=shortcut_name)

    message.embed.description = "✅ " + await context.language.get_text(
        platform_type + "_shortcut_added_desc",
        {"shortcut": shortcut.name, "shortcut_call": shortcut_call})

    await message.send(context)
    return True
Exemplo n.º 4
0
    async def dialogue(self, context, optional_argument, argument_number,
                       total_arguments):
        """Send a message about the argument to the user and wait for response."""
        if argument_number > total_arguments:
            argument_number = total_arguments

        emoji = None
        desc_key = None
        if optional_argument:
            emoji = "✅"
            desc_key = "confirm_to_stop"
        else:
            emoji = "❌"
            desc_key = "cancel_to_abort"

        message = embeds.PaginatedEmbed(await context.language.get_text(
            "argument_number", {
                "arg": argument_number,
                "total_arg": total_arguments
            }))

        localisation = self.localisation[context.language_id]
        message.embed.title = localisation["description"]
        message.embed.description = await context.language.get_text(desc_key)

        if "bonus_fields" in localisation:
            await Argument.add_dialogue_bonus_fields(context, message,
                                                     localisation)

        dialogue_msg = await message.send(context)
        await dialogue_msg.add_reaction(emoji)

        return await Argument.dialogue_response(context, dialogue_msg, emoji)
Exemplo n.º 5
0
async def display_shortcuts(context, platform_type):
    """Display all platform shortcuts."""
    shortcuts = []
    data_object = getattr(context, platform_type + "_data")
    for shortcut in data_object.shortcuts.values():
        shortcuts.append(shortcut.name)

    shortcuts.sort()

    shortcut_command = definitions.COMMANDS.get_sub_command_from_path("shortcut")
    shortcut_cmd_name = await shortcut_command.get_command_string(context)

    shortcut_instruction = shortcut_cmd_name + " [" + (
        await context.language.get_text("display_shortcuts_shortcut_name")) + "]"

    random_shortcut = random.choice(shortcuts)
    if " " in random_shortcut:
        random_shortcut = '"' + random_shortcut + '"'

    shortcut_example = shortcut_cmd_name + " " + random_shortcut

    message = embeds.PaginatedEmbed(
        await context.language.get_text("display_" + platform_type + "_shortcuts_title"),
        embeds.EmbedFieldCollection(
            shortcuts, await context.language.get_text("display_shortcuts_subtitle"), 2))

    message.embed.description = await context.language.get_text(
        "display_" + platform_type + "_shortcuts_desc",
        {"instruction": shortcut_instruction, "example": shortcut_example})

    await message.send(context)
    return True
Exemplo n.º 6
0
async def search(context, arguments):
    """Search currencies with search terms."""
    search_term = arguments[0]
    currencies = []

    columns = 1
    thumbnail = True
    if context.desktop_ui:
        columns = 2
        thumbnail = False

    search_term_lower = search_term.lower()
    for key, value in cache.CURRENCY_DATA["currencies"].items():
        if search_term_lower in value["name"].lower():
            currencies.append(key + " - " + value["name"])

    currencies.sort()
    message = embeds.PaginatedEmbed(
        await context.language.get_text("search_currencies_title"),
        embeds.EmbedFieldCollection(
            currencies, await context.language.get_text("currencies_title"),
            columns))

    message.embed.description = await context.language.get_text(
        "search_currencies_desc", {"search_term": search_term})

    await message.send(context, thumbnail=thumbnail)
    return True
Exemplo n.º 7
0
async def display_command_rules(context, arguments, platform):
    """Display command rules on any platform."""
    command_data = arguments[0]

    message = embeds.PaginatedEmbed(
        await context.language.get_text(
            "display_" + platform + "_command_rules_title",
            {"command": command_data["name"]}))

    command_rules = command_data["data"].command_rules

    message.embed.description = await context.language.get_text(
        "display_" + platform + "_command_rules_" + command_rules.type + "_rules_desc")

    members = []
    for member_id in command_rules.users:
        member = context.message.guild.get_member(member_id)
        member_name = None

        if member is not None:
            member_name = "{member.display_name} ({member.id})".format(member=member)
        else:
            member_name = "[{former_member}] ({id})".format(
                former_member=await context.language.get_text("former_guild_member"),
                id=member_id)

        members.append(member_name)

    roles = []
    for role_id in command_rules.roles:
        role = context.message.guild.get_role(role_id)
        role_name = None
        if role is not None:
            role_name = "{role.name} ({role.id})".format(role=role)
        else:
            role_name = "[{former_role}] ({id})".format(
                former_role=await context.language.get_text("former_guild_role"),
                id=role_id)

        roles.append(role_name)

    permissions = []
    if command_rules.permissions is not None:
        for permission_code in command_rules.permissions:
            permissions.append(context.language.permission_names[permission_code])

    if members:
        message.fields.append(embeds.EmbedFieldCollection(
            members, await context.language.get_text("members_title")))

    if roles:
        message.fields.append(embeds.EmbedFieldCollection(
            roles, await context.language.get_text("roles_title")))

    if permissions:
        message.fields.append(embeds.EmbedFieldCollection(
            permissions, await context.language.get_text("permissions_title")))

    await message.send(context)
    return True
Exemplo n.º 8
0
async def send_conversion(context, user_id=None):
    """Convert the found units and sends them to the channel."""
    message = await remove_hyperlinks(context.message.content)
    unit_matches = await get_unit_matches(context, message)

    if not unit_matches:
        return

    await definitions.CLIENT.remove_reactions(context.message, "ℹ")
    msg = ""
    for match in unit_matches:
        if msg != "":
            msg += "\n"

        if match[1] == "centimetre" and match[0] > 100:
            msg += await convert_to_us_height(context, match)
        elif isinstance(match[1], str):
            msg += await convert_normal(context, match)
        elif isinstance(match[1], float):
            msg += await convert_from_us_height(context, match)

    message = embeds.PaginatedEmbed(
        await context.language.get_text("auto_conversion_title"))

    member = context.message.guild.get_member(user_id)
    thumbnail = "default"
    if member:
        message.embed.title = await context.language.get_text(
            "auto_conversion_request", {"name": member.display_name})
        thumbnail = member.avatar_url

    message.embed.description = msg
    await message.send(context, thumbnail=thumbnail)
Exemplo n.º 9
0
async def view_all(context, arguments):
    """Display all currencies."""
    currencies = []

    columns = 1
    thumbnail = True
    if context.desktop_ui:
        columns = 2
        thumbnail = False

    for key, value in cache.CURRENCY_DATA["currencies"].items():
        currencies.append(key + " - " + value["name"])

    currencies.sort()
    message = embeds.PaginatedEmbed(
        await context.language.get_text("view_all_currencies_title"),
        embeds.EmbedFieldCollection(
            currencies, await context.language.get_text("currencies_title"),
            columns))

    message.embed.description = await context.language.get_text(
        "view_all_currencies_desc")

    await message.send(context, thumbnail=thumbnail)
    return True
Exemplo n.º 10
0
async def throw(context, arguments):
    """Throw the dice."""
    no_of_dice = arguments[0]
    dice_range = arguments[1:]
    dice_range.sort()

    dice_throws = []
    dice_results = []
    while len(dice_throws) < no_of_dice:
        dice_throw = random.randint(dice_range[0], dice_range[1])
        dice_throws.append(dice_throw)
        dice_results.append("🎲 " +
                            await context.language.format_number(dice_throw))

    dice_total = sum(dice_throws)
    min_total = dice_range[0] * no_of_dice
    max_total = dice_range[1] * no_of_dice
    percentage = await numbers.get_percentage(dice_total - min_total,
                                              max_total - min_total)

    formatted_percentage = await context.language.get_text(
        "percentage", {
            "number":
            await context.language.format_number(percentage,
                                                 decimal_rules=".2f")
        })

    thumbnail = "default"
    column_amount = 1
    if context.desktop_ui:
        column_amount = 3
        thumbnail = None

    message = embeds.PaginatedEmbed(
        await context.language.get_text("throw_dice_title"),
        embeds.EmbedFieldCollection(
            dice_results, await
            context.language.get_text("dice_results_title"), column_amount),
        embeds.EmbedFieldCollection(
            await context.language.get_text(
                "dice_results_analysis_content", {
                    "dice_total": await
                    context.language.format_number(dice_total),
                    "min_total": await
                    context.language.format_number(min_total),
                    "max_total": await
                    context.language.format_number(max_total),
                    "percentage": formatted_percentage
                }), await
            context.language.get_text("dice_results_analysis_title")))

    message.embed.description = await context.language.get_text(
        "throw_dice_desc", {"user_mention": context.message.author.mention})

    await message.send(context, thumbnail=thumbnail)
    return True
Exemplo n.º 11
0
async def no_action(context, commands, command_string):
    """Send a feedback message when the command called has no method to call."""
    message = embeds.PaginatedEmbed(
        await context.language.get_text("no_action_title"),
        embeds.EmbedFieldCollection(commands, await
                                    context.language.get_text("command")))

    message.embed.description = "ℹ " + await context.language.get_text(
        "no_action_desc", {"command": command_string})

    await message.send(context)
Exemplo n.º 12
0
async def failed_pre_check(context, custom_msg):
    """Send a failed pre-check feedback message."""
    message = embeds.PaginatedEmbed(
        await context.language.get_text("failed_pre_check_title"),
        embeds.EmbedFieldCollection(
            custom_msg, await
            context.language.get_text("failed_pre_check_custom_msg_title")))

    message.embed.description = ":grey_exclamation: " + await context.language.get_text(
        "failed_pre_check_desc")

    await message.send(context)
Exemplo n.º 13
0
async def invalid_argument(context, argument, custom_msg=None):
    """Send invalid argument feedback message."""
    message = embeds.PaginatedEmbed(
        await context.language.get_text("invalid_argument_title"),
        embeds.EmbedFieldCollection(
            custom_msg, await
            context.language.get_text("invalid_argument_custom_msg_title")))

    message.embed.description = "❌ " + await context.language.get_text(
        "invalid_argument_desc", {"arg": argument})

    await message.send(context)
Exemplo n.º 14
0
async def reset_language(context, platform):
    """Reset a language."""
    platform_data = getattr(context, platform + "_data")

    platform_data.language_id = None
    await database_functions.update_language(context, platform)
    await context.clear_cache()

    message = embeds.PaginatedEmbed(
        await context.language.get_text(platform + "_language_reset_title"))

    message.embed.description = "✅ " + await context.language.get_text(
        platform + "_language_reset_desc")

    await message.send(context)
    return True
Exemplo n.º 15
0
async def delete_shortcut(context, arguments, platform_type):
    """Delete a shortcut from the database."""
    shortcut_name = arguments[0]
    data_object = getattr(context, platform_type + "_data")

    await database_functions.delete_shortcut(context, shortcut_name, platform_type)
    del data_object.shortcuts[shortcut_name]

    message = embeds.PaginatedEmbed(
        await context.language.get_text(platform_type + "_shortcut_deleted_title"))

    message.embed.description = "✅ " + await context.language.get_text(
        platform_type + "_shortcut_deleted_desc", {"shortcut": shortcut_name})

    await message.send(context)
    return True
Exemplo n.º 16
0
async def not_authorised(context, command_string, last_working_command_string):
    """
    Feedback message.

    Send a feedback message when the user has attempted to use a command which they
    cannot use.
    """
    message = embeds.PaginatedEmbed(
        await context.language.get_text("unauthorised_command_title"))

    message.embed.description = "🚫 " + await context.language.get_text(
        "unauthorised_command_desc", {
            "command": command_string,
            "last_working": last_working_command_string
        })

    await message.send(context)
Exemplo n.º 17
0
async def invalid_command_no_subcommands(context, command_string,
                                         last_working_command_string):
    """
    Feedback message.

    Send a feedback message when an invalid command was called, and the last valid
    one does not have sub-commands.
    """
    message = embeds.PaginatedEmbed(
        await context.language.get_text("invalid_command_title"))

    message.embed.description = "❌ " + await context.language.get_text(
        "invalid_command_no_subcommands_desc", {
            "command": command_string,
            "last_working": last_working_command_string
        })

    await message.send(context)
Exemplo n.º 18
0
async def no_usable_sub_commands(context, command_string,
                                 last_working_command_string):
    """
    Feedback message.

    Send a feedback message when the user attempts to use a command with no usable
    sub-commands.
    """
    message = embeds.PaginatedEmbed(
        await context.language.get_text("no_usable_sub_commands_title"))

    message.embed.description = ":exclamation: " + await context.language.get_text(
        "no_usable_sub_commands_desc", {
            "command": command_string,
            "last_working": last_working_command_string
        })

    await message.send(context)
Exemplo n.º 19
0
async def add_command_rule(context, arguments, platform, ruletype):
    """Add any type of command rule."""
    command_data_objects = arguments[0]
    rules = arguments[1:]

    for command_data in command_data_objects:
        for rule in rules:
            await command_data["data"].command_rules.add_rule(rule, ruletype)

    await database_functions.update_command_data(context, platform)

    message = embeds.PaginatedEmbed(
        await context.language.get_text(platform + "_command_rules_added_title"))

    message.embed.description = "✅ " + await context.language.get_text(
        platform + "_command_rules_added_desc")

    await message.send(context)
    return True
Exemplo n.º 20
0
async def too_many_arguments(context, argument_count, argument):
    """Send too many arguments feedback message."""
    message = embeds.PaginatedEmbed(
        await context.language.get_text("too_many_arguments_title"))

    desc = None
    if argument_count == 1:
        desc = await context.language.get_text(
            "too_many_arguments_singular_desc", {
                "arg": argument,
                "args": argument_count
            })
    else:
        desc = await context.language.get_text(
            "too_many_arguments_plural_desc", {
                "arg": argument,
                "args": argument_count
            })

    message.embed.description = "❌ " + desc
    await message.send(context)
Exemplo n.º 21
0
async def guild_member_info(context, arguments):
    """Show basic information of a member."""
    member = arguments[0]

    join_time = member.joined_at.strftime(
        await context.language.get_text("datetime_format"))
    time_in_guild = await dates.get_time_difference_string(context, member.joined_at)
    join_data = await context.language.get_text(
        "datetime_and_time_passed", {"datetime": join_time, "time_passed": time_in_guild})

    creation_time = member.created_at.strftime(
        await context.language.get_text("datetime_format"))
    time_on_discord = await dates.get_time_difference_string(context, member.created_at)
    creation_data = await context.language.get_text(
        "datetime_and_time_passed",
        {"datetime": creation_time, "time_passed": time_on_discord})

    message = embeds.PaginatedEmbed(
        await context.language.get_text(
            "member_info_title", {"name": member.display_name}),
        embeds.EmbedFieldCollection(
            member.name, await context.language.get_text("member_info_discord_name")),
        embeds.EmbedFieldCollection(
            creation_data, await context.language.get_text("member_info_creation_time")),
        embeds.EmbedFieldCollection(
            join_data, await context.language.get_text(
                "member_info_join_time", {"guild": member.guild.name})),
        embeds.EmbedFieldCollection(
            member.top_role.name, await context.language.get_text(
                "member_info_top_role")))

    message.embed.description = await context.language.get_text(
        "member_info_desc", {"member": member.display_name})

    colour = member.colour
    if str(colour) == "#000000":
        colour = Embed.Empty

    await message.send(context, thumbnail=member.avatar_url, colour=colour)
    return True
Exemplo n.º 22
0
async def convert(context, arguments):
    """Convert from one currency to another."""
    amount = arguments[0]
    base_currency = arguments[1]
    target_currency = arguments[2]

    converted_amount = await numbers.convert(amount, base_currency["rate"],
                                             target_currency["rate"])

    message = embeds.PaginatedEmbed(await context.language.get_text(
        "convert_currency_title", {
            "base": base_currency["code"],
            "target": target_currency["code"]
        }))

    formatted_base_amount = await context.language.format_number(
        amount, decimal_rules=".2f")
    formatted_target_amount = await context.language.format_number(
        converted_amount, decimal_rules=".2f")

    base = await context.language.get_text("unit_representation", {
        "unit_amount": formatted_base_amount,
        "unit_name": base_currency["name"]
    })

    target = await context.language.get_text(
        "unit_representation", {
            "unit_amount": formatted_target_amount,
            "unit_name": target_currency["name"]
        })

    message.embed.description = ":currency_exchange: " + await context.language.get_text(
        "unit_conversion", {
            "unit_and_amount": base,
            "conversion_list": target
        })

    await message.send(context)
    return True
Exemplo n.º 23
0
async def set_language(context, arguments, platform):
    """Set language."""
    platform_data = getattr(context, platform + "_data")

    platform_data.language_id = arguments[0]
    await database_functions.update_language(context, platform)
    await context.clear_cache()

    message = embeds.PaginatedEmbed(
        await context.language.get_text(platform + "_language_updated_title"))

    confirmation_text = platform_data.language.flag_emoji
    if confirmation_text is None:
        confirmation_text = "✅"

    message.embed.description = confirmation_text + " " + (
        await context.language.get_text(
            platform + "_language_updated_desc",
            {"language": context.language.get_language_name(
                platform_data.language.obj_id)}))

    await message.send(context)
    return True
Exemplo n.º 24
0
async def get_command_info(context, arguments):
    """Get command info of a specific command."""
    command = arguments[0]

    aliases = await context.language.get_string_list(
        command.localisation[context.language_id]["names"][1:])

    if aliases == "":
        aliases = await context.language.get_text("no_aliases")

    platforms = ["category", "channel", "guild", "user", "global"]
    command_use_times = {}
    for platform in platforms:
        platform_cmd_data = getattr(getattr(context, platform + "_data"), "command_data")
        command_data = await platform_cmd_data.get_object_from_id_path(command.id_path)

        language_key = "command_" + platform + "_uses_"
        number = await context.language.format_number(command_data.use_times)
        number = "**" + number + "**"
        if command_data.use_times == 1:
            language_key += "singular"
        else:
            language_key += "plural"

        command_use_times[platform] = await context.language.get_text(
            language_key, {"times": number})

    basic_info = (
        "{aliases_title}: **{aliases_content}**\n"
        "{command_use_times[global]}\n"
        "{command_use_times[guild]}\n"
        "{command_use_times[category]}\n"
        "{command_use_times[channel]}\n"
        "{command_use_times[user]}").format(
            aliases_title=await context.language.get_text("command_aliases_title"),
            aliases_content=aliases, command_use_times=command_use_times)

    related_commands = ""
    for command in command.related_commands:
        if related_commands:
            related_commands += "\n"

        related_commands += await command.get_command_string(
            context, include_prefix=False)

    sub_commands = await command.get_sub_commands(context, filter_unallowed=False)

    sub_commands_string = ""
    for sub_command in sub_commands:
        if sub_commands_string:
            sub_commands_string += "\n"

        sub_command_name = await sub_command.get_command_string(
            context, include_prefix=False)

        sub_commands_string += (
            sub_command_name.split(".")[-1] + " - " +
            sub_command.localisation[context.language_id]["description"])

    message = embeds.PaginatedEmbed(
        await context.language.get_text(
            "command_info_title",
            {"command": await command.get_command_string(context, include_prefix=False)}),
        embeds.EmbedFieldCollection(
            basic_info, await context.language.get_text("basic_command_info_title")))

    if sub_commands_string:
        message.fields.append(embeds.EmbedFieldCollection(
            sub_commands_string, await context.language.get_text("sub_commands_title")))

    if related_commands:
        message.fields.append(embeds.EmbedFieldCollection(
            related_commands, await context.language.get_text("related_commands_title")))

    for i, argument in enumerate(command.arguments):
        message.fields.append(await argument.get_info_embed_field(context, i + 1))

    message.embed.title = command.localisation[context.language_id]["description"]
    message.embed.description = command.localisation[context.language_id]["help_text"]

    await message.send(context)
    return True