Przeglądaj źródła

New command-line options 'lists' and 'list_members'.

default 1 rok temu
rodzic
commit
d11d03787f
2 zmienionych plików z 47 dodań i 0 usunięć
  1. 13 0
      data.c
  2. 34 0
      main.c

+ 13 - 0
data.c

@@ -2340,6 +2340,19 @@ xs_val *list_maint(snac *user, const char *list, int op)
         }
 
         break;
+
+    case 4: /** find list id by name **/
+        if (xs_is_string(list)) {
+            xs *lol = list_maint(user, NULL, 0);
+            const xs_list *li;
+
+            xs_list_foreach(lol, li) {
+                if (strcmp(list, xs_list_get(li, 1)) == 0) {
+                    l = xs_dup(xs_list_get(li, 0));
+                    break;
+                }
+            }
+        }
     }
 
     return l;

+ 34 - 0
main.c

@@ -59,6 +59,8 @@ int usage(void)
     printf("import_csv {basedir} {uid}           Imports data from CSV files\n");
     printf("import_list {basedir} {uid} {file}   Imports a Mastodon CSV list file\n");
     printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
+    printf("lists {basedir} {uid}                Returns the names of the lists created by the user\n");
+    printf("list_members {basedir} {uid} {name}  Returns the list of accounts inside a list\n");
 
     return 1;
 }
@@ -282,9 +284,41 @@ int main(int argc, char *argv[])
         return migrate_account(&snac);
     }
 
+    if (strcmp(cmd, "lists") == 0) { /** **/
+        xs *lol = list_maint(&snac, NULL, 0);
+        const xs_list *l;
+
+        xs_list_foreach(lol, l) {
+            printf("%s (%s)\n", xs_list_get(l, 1), xs_list_get(l, 0));
+        }
+
+        return 0;
+    }
+
     if ((url = GET_ARGV()) == NULL)
         return usage();
 
+    if (strcmp(cmd, "list_members") == 0) { /** **/
+        xs *lid = list_maint(&snac, url, 4);
+
+        if (lid != NULL) {
+            xs *lcont = list_content(&snac, lid, NULL, 0);
+            const char *md5;
+
+            xs_list_foreach(lcont, md5) {
+                xs *actor = NULL;
+
+                if (valid_status(object_get_by_md5(md5, &actor))) {
+                    printf("%s (%s)\n", xs_dict_get(actor, "id"), xs_dict_get_def(actor, "preferredUsername", ""));
+                }
+            }
+        }
+        else
+            fprintf(stderr, "Cannot find list named '%s'\n", url);
+
+        return 0;
+    }
+
     if (strcmp(cmd, "alias") == 0) { /** **/
         xs *actor = NULL;
         xs *uid = NULL;