Added name and Tox ID completion.
This commit is contained in:
parent
d90e3e5b58
commit
78364e3d13
@ -838,10 +838,10 @@ twc_commands_init()
|
||||
"manage friends",
|
||||
"list"
|
||||
" || add <address> [<message>]"
|
||||
" || remove <number>"
|
||||
" || remove <number>|<name>|<Tox ID>"
|
||||
" || requests"
|
||||
" || accept <number>|all"
|
||||
" || decline <number>|all",
|
||||
" || accept <number>|<name>|<Tox ID>|all"
|
||||
" || decline <number>|<name>|<Tox ID>|all",
|
||||
" list: list all friends\n"
|
||||
" add: add a friend by their public Tox address\n"
|
||||
"requests: list friend requests\n"
|
||||
@ -849,10 +849,10 @@ twc_commands_init()
|
||||
" decline: decline friend requests\n",
|
||||
"list"
|
||||
" || add"
|
||||
" || remove"
|
||||
" || remove %(tox_friend_name)|%(tox_friend_tox_id)"
|
||||
" || requests"
|
||||
" || accept"
|
||||
" || decline",
|
||||
" || accept %(tox_friend_name)|%(tox_friend_tox_id)"
|
||||
" || decline %(tox_friend_name)|%(tox_friend_tox_id)",
|
||||
twc_cmd_friend, NULL);
|
||||
|
||||
weechat_hook_command("group",
|
||||
@ -878,10 +878,11 @@ twc_commands_init()
|
||||
|
||||
weechat_hook_command("msg",
|
||||
"send a message to a Tox friend",
|
||||
"<id> [<message>]",
|
||||
" id: friend number of the person to message\n"
|
||||
"<number>|<name>|<Tox ID> [<message>]",
|
||||
"number, name, Tox ID: friend to message\n"
|
||||
"message: message to send",
|
||||
NULL, twc_cmd_msg, NULL);
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)",
|
||||
twc_cmd_msg, NULL);
|
||||
|
||||
weechat_hook_command("myid",
|
||||
"get your Tox ID to give to friends",
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
|
||||
#include "twc-completion.h"
|
||||
|
||||
@ -32,6 +33,61 @@ enum
|
||||
TWC_UNLOADED_PROFILES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TWC_COMPLETE_FRIEND_NAME = 2 << 0,
|
||||
TWC_COMPLETE_FRIEND_ID = 1 << 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Complete a friends number, name and/or Tox ID.
|
||||
*/
|
||||
int
|
||||
twc_completion_friend(void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int flags = (int)(intptr_t)data;
|
||||
struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
|
||||
|
||||
if (!profile)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
uint32_t friend_count = tox_count_friendlist(profile->tox);
|
||||
int32_t *friend_numbers = malloc(sizeof(int32_t) * friend_count);
|
||||
tox_get_friendlist(profile->tox, friend_numbers, friend_count);
|
||||
|
||||
for (uint32_t i = 0; i < friend_count; ++i)
|
||||
{
|
||||
if (flags & TWC_COMPLETE_FRIEND_ID)
|
||||
{
|
||||
uint8_t tox_id[TOX_CLIENT_ID_SIZE];
|
||||
char hex_id[TOX_CLIENT_ID_SIZE * 2 + 1];
|
||||
|
||||
tox_get_client_id(profile->tox, friend_numbers[i], tox_id);
|
||||
twc_bin2hex(tox_id, TOX_CLIENT_ID_SIZE, hex_id);
|
||||
|
||||
weechat_hook_completion_list_add(completion,
|
||||
hex_id,
|
||||
0,
|
||||
WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
|
||||
if (flags & TWC_COMPLETE_FRIEND_NAME)
|
||||
{
|
||||
char *name = twc_get_name_nt(profile->tox, friend_numbers[i]);
|
||||
|
||||
weechat_hook_completion_list_add(completion,
|
||||
name,
|
||||
0,
|
||||
WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete a profile name, possibly filtering by loaded/unloaded profiles.
|
||||
*/
|
||||
@ -69,12 +125,20 @@ twc_completion_init()
|
||||
twc_completion_profile,
|
||||
(void *)(intptr_t)TWC_ALL_PROFILES);
|
||||
weechat_hook_completion("tox_loaded_profiles",
|
||||
"profile",
|
||||
"loaded profile",
|
||||
twc_completion_profile,
|
||||
(void *)(intptr_t)TWC_LOADED_PROFILES);
|
||||
weechat_hook_completion("tox_unloaded_profiles",
|
||||
"profile",
|
||||
"unloaded profile",
|
||||
twc_completion_profile,
|
||||
(void *)(intptr_t)TWC_UNLOADED_PROFILES);
|
||||
weechat_hook_completion("tox_friend_tox_id",
|
||||
"friend Tox ID",
|
||||
twc_completion_friend,
|
||||
(void *)(intptr_t)TWC_COMPLETE_FRIEND_ID);
|
||||
weechat_hook_completion("tox_friend_name",
|
||||
"friend name",
|
||||
twc_completion_friend,
|
||||
(void *)(intptr_t)TWC_COMPLETE_FRIEND_NAME);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user