Add stdout and systemd service file, change drone ci file

master
santic-zombie 2 years ago
parent d079442e6a
commit 031bb11751
  1. 7
      .drone.yml
  2. 4
      src/misc.c
  3. 22
      src/tox_bot.c
  4. 14
      tox_bot.service

@ -30,7 +30,8 @@ steps:
script: script:
- if [ ! -d ~/tox_source ]; then mkdir ~/tox_source; fi - if [ ! -d ~/tox_source ]; then mkdir ~/tox_source; fi
- if [ ! -d ~/tox_bot ]; then mkdir ~/tox_bot; fi - if [ ! -d ~/tox_bot ]; then mkdir ~/tox_bot; fi
- if [ -f ~/tox_bot/echo_bot ]; then rm ~/tox_bot/echo_bot; fi - if [ ! -d ~/.config/systemd/user/ ]; then mkdir ~/.config/systemd/user/; fi
- if [ -f ~/tox_bot/echo_bot ]; then rm ~/tox_bot/echo_bot; fi
- name: Copy source bot files - name: Copy source bot files
image: appleboy/drone-scp image: appleboy/drone-scp
@ -61,8 +62,8 @@ steps:
- gcc -o echo_bot tox_bot.c commands.c misc.c -std=gnu99 -lsodium -I /usr/local/include/ -ltoxcore -lconfig - gcc -o echo_bot tox_bot.c commands.c misc.c -std=gnu99 -lsodium -I /usr/local/include/ -ltoxcore -lconfig
- cp echo_bot ~/tox_bot - cp echo_bot ~/tox_bot
- cp -f ../bot.cfg ../masterkeys.txt ~/tox_bot/ - cp -f ../bot.cfg ../masterkeys.txt ~/tox_bot/
- cp -f ../tox_bot.service ~/.config/systemd/user/
#- sudo systemctl restart tox_bot.service
- ls -lta ~/tox_bot - ls -lta ~/tox_bot
- rm -rfd ~/tox_source - rm -rfd ~/tox_source
- rm ~/tox.tar.gz - rm ~/tox.tar.gz

@ -54,7 +54,7 @@ int char_find(int idx, const char *s, char ch)
void log_msg(Tox *tox, const uint8_t *inmsg, uint32_t friend_number, bool user) void log_msg(Tox *tox, const uint8_t *inmsg, uint32_t friend_number, bool user)
{ {
char name[TOX_MAX_NAME_LENGTH]; char name[TOX_MAX_NAME_LENGTH];
if (user == true) { if (user == true) {
tox_friend_get_name(tox, friend_number, (uint8_t *) name, NULL); tox_friend_get_name(tox, friend_number, (uint8_t *) name, NULL);
size_t len = tox_friend_get_name_size(tox, friend_number, NULL); size_t len = tox_friend_get_name_size(tox, friend_number, NULL);
@ -74,7 +74,7 @@ void log_msg(Tox *tox, const uint8_t *inmsg, uint32_t friend_number, bool user)
strftime(cur_time, 128, "%d-%b-%Y %H:%M:%S", ptm); strftime(cur_time, 128, "%d-%b-%Y %H:%M:%S", ptm);
printf("%s (%s): %s\n", cur_time, name, inmsg); fprintf(stdout, "%s (%s): %s\n", cur_time, name, inmsg);
} }
int file_contains_key(const char *public_key, const char *path) int file_contains_key(const char *public_key, const char *path)

@ -79,25 +79,25 @@ int config_tox(Tox *tox)
const char *name; const char *name;
if (config_lookup_string(&cfg, "Tox_Bot_Name", &str)) { if (config_lookup_string(&cfg, "Tox_Bot_Name", &str)) {
printf("Tox bot name: %s\n", str); fprintf(stdout, "Tox bot name: %s\n", str);
name = str; name = str;
} }
else { else {
name = "Tox Bot test"; name = "Tox Bot test";
fprintf(stderr, "No 'Tox_Bot_Name' setting in configuration file. "); fprintf(stderr, "No 'Tox_Bot_Name' setting in configuration file. ");
printf("The default name is used\n"); fprintf(stdout, "The default name is used\n");
} }
const char *status_message; const char *status_message;
if (config_lookup_string(&cfg, "Tox_Bot_Status", &str)) { if (config_lookup_string(&cfg, "Tox_Bot_Status", &str)) {
printf("Tox bot status: %s\n", str); fprintf(stdout, "Tox bot status: %s\n", str);
status_message = str; status_message = str;
} }
else { else {
status_message = "Hello, World!"; status_message = "Hello, World!";
fprintf(stderr, "No 'Tox_Bot_Status' setting in configuration file. "); fprintf(stderr, "No 'Tox_Bot_Status' setting in configuration file. ");
printf("The default status is used\n"); fprintf(stdout, "The default status is used\n");
} }
tox_self_set_name(tox, name, strlen(name), NULL); tox_self_set_name(tox, name, strlen(name), NULL);
@ -199,7 +199,7 @@ void print_tox_id(Tox *tox)
tox_id_hex[i] = toupper(tox_id_hex[i]); tox_id_hex[i] = toupper(tox_id_hex[i]);
} }
printf("Tox ID: %s\n", tox_id_hex); fprintf(stdout, "Tox ID: %s\n", tox_id_hex);
} }
@ -219,12 +219,12 @@ static void friend_request_cb(Tox *tox, const uint8_t *public_key, const uint8_t
} }
if (file_contains_key(public_key, MASTERLIST_FILE) == 1) { if (file_contains_key(public_key, MASTERLIST_FILE) == 1) {
printf("New friend is Master: %s\n", tox_id_hex); fprintf(stdout, "New friend is Master: %s\n", tox_id_hex);
tox_friend_add_norequest(tox, public_key, NULL); tox_friend_add_norequest(tox, public_key, NULL);
update_savedata_file(tox); update_savedata_file(tox);
} }
else { else {
printf("New friend not on the list: %s\n", tox_id_hex); fprintf(stdout, "New friend not on the list: %s\n", tox_id_hex);
} }
} }
@ -256,13 +256,13 @@ void self_connection_status_cb(Tox *tox, TOX_CONNECTION connection_status, void
{ {
switch (connection_status) { switch (connection_status) {
case TOX_CONNECTION_NONE: case TOX_CONNECTION_NONE:
printf("Offline\n"); fprintf(stdout, "Offline\n");
break; break;
case TOX_CONNECTION_TCP: case TOX_CONNECTION_TCP:
printf("Online, using TCP\n"); fprintf(stdout, "Online, using TCP\n");
break; break;
case TOX_CONNECTION_UDP: case TOX_CONNECTION_UDP:
printf("Online, using UDP\n"); fprintf(stdout, "Online, using UDP\n");
break; break;
} }
} }
@ -285,7 +285,7 @@ int main()
update_savedata_file(tox); update_savedata_file(tox);
printf("Connecting...\n"); fprintf(stdout, "Connecting...\n");
while (1) { while (1) {
tox_iterate(tox, NULL); tox_iterate(tox, NULL);

@ -0,0 +1,14 @@
[Unit]
Description=Tox bot
[Service]
Type=simple
WorkingDirectory=/home/tox/tox_bot
ExecStart=/home/tox/tox_bot/echo_bot
StandardOutput=append:/home/tox/tox_bot/echo_bot.log
StandardError=append:/home/tox/tox_bot/echo_bot.log
User=tox
Restart=on-failure
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save