Example #1
0
int
irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags)
{
    const char *ptr_data;
    char *data_with_colors, *msg;

    IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

    if (buffer == irc_raw_buffer)
    {
        if (dogechat_strcasecmp (input_data, "q") == 0)
            dogechat_buffer_close (buffer);
    }
    else
    {
        /*
         * if send unknown commands is enabled and that input data is a
         * command, then send this command to IRC server
         */
        if (dogechat_config_boolean (irc_config_network_send_unknown_commands)
            && !dogechat_string_input_for_buffer (input_data))
        {
            if (ptr_server)
            {
                irc_server_sendf (ptr_server, flags, NULL,
                                  "%s", dogechat_utf8_next_char (input_data));
            }
            return DOGECHAT_RC_OK;
        }

        if (ptr_channel)
        {
            ptr_data = dogechat_string_input_for_buffer (input_data);
            if (!ptr_data)
                ptr_data = input_data;
            data_with_colors = irc_color_encode (
                ptr_data,
                dogechat_config_boolean (irc_config_network_colors_send));

            msg = strdup ((data_with_colors) ? data_with_colors : ptr_data);
            if (msg)
            {
                irc_input_send_user_message (buffer, flags, NULL, msg);
                free (msg);
            }

            if (data_with_colors)
                free (data_with_colors);
        }
        else
        {
            dogechat_printf (buffer,
                            _("%s%s: this buffer is not a channel!"),
                            dogechat_prefix ("error"), IRC_PLUGIN_NAME);
        }
    }

    return DOGECHAT_RC_OK;
}
Example #2
0
void
alias_hook_command (struct t_alias *alias)
{
    char *str_priority_name, *str_completion;
    int length;

    /*
     * build string with priority and name: the alias priority is 2000, which
     * is higher than default one (1000), so the alias is executed before a
     * command (if a command with same name exists in core or in another plugin)
     */
    length = strlen (alias->name) + 16 + 1;
    str_priority_name = malloc (length);
    if (str_priority_name)
        snprintf (str_priority_name, length, "2000|%s", alias->name);

    /*
     * if alias has no custom completion, then default is to complete with
     * completion template of target command, for example if alias is
     * "/alias add test /buffer", then str_completion will be "%%buffer"
     */
    str_completion = NULL;
    if (!alias->completion)
    {
        length = 2 + strlen (alias->command) + 1;
        str_completion = malloc (length);
        if (str_completion)
        {
            snprintf (str_completion, length, "%%%%%s",
                      (dogechat_string_is_command_char (alias->command)) ?
                      dogechat_utf8_next_char (alias->command) : alias->command);
        }
    }

    alias->hook = dogechat_hook_command ((str_priority_name) ? str_priority_name : alias->name,
                                        alias->command,
                                        NULL, NULL,
                                        (str_completion) ? str_completion : alias->completion,
                                        &alias_cb, alias);

    if (str_priority_name)
        free (str_priority_name);
    if (str_completion)
        free (str_completion);
}
Example #3
0
struct t_alias *
alias_new (const char *name, const char *command, const char *completion)
{
    struct t_alias *new_alias, *ptr_alias, *pos_alias;

    if (!alias_name_valid (name))
    {
        dogechat_printf (NULL,
                        _("%s%s: invalid alias name: \"%s\""),
                        dogechat_prefix ("error"), ALIAS_PLUGIN_NAME,
                        name);
        return NULL;
    }

    if (!command || !command[0])
        return NULL;

    while (dogechat_string_is_command_char (name))
    {
        name = dogechat_utf8_next_char (name);
    }

    ptr_alias = alias_search (name);
    if (ptr_alias)
        alias_free (ptr_alias);

    new_alias = malloc (sizeof (*new_alias));
    if (new_alias)
    {
        new_alias->hook = NULL;
        new_alias->name = strdup (name);
        new_alias->command = strdup (command);
        new_alias->completion = (completion) ? strdup (completion) : NULL;
        new_alias->running = 0;

        alias_hook_command (new_alias);

        if (alias_list)
        {
            pos_alias = alias_find_pos (name);
            if (pos_alias)
            {
                /* insert alias into the list (before alias found) */
                new_alias->prev_alias = pos_alias->prev_alias;
                new_alias->next_alias = pos_alias;
                if (pos_alias->prev_alias)
                    (pos_alias->prev_alias)->next_alias = new_alias;
                else
                    alias_list = new_alias;
                pos_alias->prev_alias = new_alias;
            }
            else
            {
                /* add alias to end of list */
                new_alias->prev_alias = last_alias;
                new_alias->next_alias = NULL;
                last_alias->next_alias = new_alias;
                last_alias = new_alias;
            }
        }
        else
        {
            new_alias->prev_alias = NULL;
            new_alias->next_alias = NULL;
            alias_list = new_alias;
            last_alias = new_alias;
        }
    }

    return new_alias;
}