1 #include "command_funcs.h"
2
3 #include "friend.h"
4 #include "groups.h"
5 #include "debug.h"
6 #include "tox.h"
7 #include "macros.h"
8
9 #include <stdlib.h>
10 #include <string.h>
11
slash_send_file(void * object,char * filepath,int UNUSED (arg_length))12 bool slash_send_file(void *object, char *filepath, int UNUSED(arg_length)) {
13 if (filepath) {
14 FRIEND *f = object;
15 LOG_TRACE("slash_send_file", "File path is: %s" , filepath);
16 postmessage_toxcore(TOX_FILE_SEND_NEW_SLASH, f->number, 0xFFFF, (void *)filepath);
17 return true;
18 }
19
20 LOG_ERR("slash_send_file", " filepath was NULL.");
21 return false;
22 }
23
slash_device(void * object,char * arg,int UNUSED (arg_length))24 bool slash_device(void *object, char *arg, int UNUSED(arg_length)) {
25 FRIEND *f = object;
26 uint8_t id[TOX_ADDRESS_SIZE * 2];
27 string_to_id(id, arg);
28 void *data = malloc(TOX_ADDRESS_SIZE * sizeof(char));
29
30 if (data) {
31 memcpy(data, id, TOX_ADDRESS_SIZE);
32 postmessage_toxcore(TOX_FRIEND_NEW_DEVICE, f->number, 0, data);
33 return true;
34 }
35 LOG_ERR("slash_device", " Could not allocate memory.");
36 return false;
37 }
38
39
slash_alias(void * object,char * arg,int arg_length)40 bool slash_alias(void *object, char *arg, int arg_length) {
41 FRIEND *f = object;
42 if (arg) {
43 friend_set_alias(f, (uint8_t *)arg, arg_length);
44 } else {
45 friend_set_alias(f, NULL, 0);
46 }
47
48 utox_write_metadata(f);
49 return true;
50 }
51
slash_invite(void * object,char * arg,int UNUSED (arg_length))52 bool slash_invite(void *object, char *arg, int UNUSED(arg_length)) {
53 GROUPCHAT *g = object;
54 FRIEND *f = find_friend_by_name((uint8_t *)arg);
55 if (f != NULL && f->online) {
56 postmessage_toxcore(TOX_GROUP_SEND_INVITE, g->number, f->number, NULL);
57 return true;
58 }
59 return false;
60 }
61
slash_topic(void * object,char * arg,int arg_length)62 bool slash_topic(void *object, char *arg, int arg_length) {
63 GROUPCHAT *g = object;
64 void *d = malloc(arg_length);
65 if (d) {
66 memcpy(d, arg, arg_length);
67 postmessage_toxcore(TOX_GROUP_SET_TOPIC, g->number, arg_length, d);
68 return true;
69 }
70 LOG_ERR("slash_topic", " Could not allocate memory.");
71 return false;
72 }
73