@spectratools/xapi-cli 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +121 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -791,6 +791,54 @@ posts.command("delete", {
|
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
});
|
|
794
|
+
posts.command("like", {
|
|
795
|
+
description: "Like a post by ID.",
|
|
796
|
+
args: z4.object({
|
|
797
|
+
id: z4.string().describe("Post ID to like")
|
|
798
|
+
}),
|
|
799
|
+
env: xApiWriteEnv,
|
|
800
|
+
output: z4.object({
|
|
801
|
+
liked: z4.boolean(),
|
|
802
|
+
id: z4.string()
|
|
803
|
+
}),
|
|
804
|
+
examples: [{ args: { id: "1234567890" }, description: "Like a post" }],
|
|
805
|
+
async run(c) {
|
|
806
|
+
try {
|
|
807
|
+
const client = createXApiClient(writeAuthToken(c.env));
|
|
808
|
+
const me = await client.getMe();
|
|
809
|
+
const res = await client.likePost(me.data.id, c.args.id);
|
|
810
|
+
return c.ok({ liked: res.data.liked, id: c.args.id });
|
|
811
|
+
} catch (error) {
|
|
812
|
+
const authError = toWriteAuthError("posts like", error);
|
|
813
|
+
if (authError) return c.error(authError);
|
|
814
|
+
throw error;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
posts.command("retweet", {
|
|
819
|
+
description: "Retweet a post by ID.",
|
|
820
|
+
args: z4.object({
|
|
821
|
+
id: z4.string().describe("Post ID to retweet")
|
|
822
|
+
}),
|
|
823
|
+
env: xApiWriteEnv,
|
|
824
|
+
output: z4.object({
|
|
825
|
+
retweeted: z4.boolean(),
|
|
826
|
+
id: z4.string()
|
|
827
|
+
}),
|
|
828
|
+
examples: [{ args: { id: "1234567890" }, description: "Retweet a post" }],
|
|
829
|
+
async run(c) {
|
|
830
|
+
try {
|
|
831
|
+
const client = createXApiClient(writeAuthToken(c.env));
|
|
832
|
+
const me = await client.getMe();
|
|
833
|
+
const res = await client.retweetPost(me.data.id, c.args.id);
|
|
834
|
+
return c.ok({ retweeted: res.data.retweeted, id: c.args.id });
|
|
835
|
+
} catch (error) {
|
|
836
|
+
const authError = toWriteAuthError("posts retweet", error);
|
|
837
|
+
if (authError) return c.error(authError);
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
});
|
|
794
842
|
posts.command("likes", {
|
|
795
843
|
description: "List users who liked a post.",
|
|
796
844
|
args: z4.object({
|
|
@@ -1198,6 +1246,70 @@ users.command("get", {
|
|
|
1198
1246
|
);
|
|
1199
1247
|
}
|
|
1200
1248
|
});
|
|
1249
|
+
users.command("follow", {
|
|
1250
|
+
description: "Follow a user by username or ID.",
|
|
1251
|
+
args: z7.object({
|
|
1252
|
+
username: z7.string().describe("Username (with or without @) or user ID")
|
|
1253
|
+
}),
|
|
1254
|
+
env: xApiWriteEnv,
|
|
1255
|
+
output: z7.object({
|
|
1256
|
+
id: z7.string(),
|
|
1257
|
+
username: z7.string(),
|
|
1258
|
+
following: z7.boolean(),
|
|
1259
|
+
pending_follow: z7.boolean().optional()
|
|
1260
|
+
}),
|
|
1261
|
+
examples: [{ args: { username: "jack" }, description: "Follow @jack" }],
|
|
1262
|
+
async run(c) {
|
|
1263
|
+
try {
|
|
1264
|
+
const client = createXApiClient(writeAuthToken(c.env));
|
|
1265
|
+
const me = await client.getMe();
|
|
1266
|
+
const targetRes = await resolveUser(client, c.args.username);
|
|
1267
|
+
const target = targetRes.data;
|
|
1268
|
+
const res = await client.followUser(me.data.id, target.id);
|
|
1269
|
+
return c.ok({
|
|
1270
|
+
id: target.id,
|
|
1271
|
+
username: target.username,
|
|
1272
|
+
following: res.data.following,
|
|
1273
|
+
pending_follow: res.data.pending_follow
|
|
1274
|
+
});
|
|
1275
|
+
} catch (error) {
|
|
1276
|
+
const authError = toWriteAuthError("users follow", error);
|
|
1277
|
+
if (authError) return c.error(authError);
|
|
1278
|
+
throw error;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
users.command("unfollow", {
|
|
1283
|
+
description: "Unfollow a user by username or ID.",
|
|
1284
|
+
args: z7.object({
|
|
1285
|
+
username: z7.string().describe("Username (with or without @) or user ID")
|
|
1286
|
+
}),
|
|
1287
|
+
env: xApiWriteEnv,
|
|
1288
|
+
output: z7.object({
|
|
1289
|
+
id: z7.string(),
|
|
1290
|
+
username: z7.string(),
|
|
1291
|
+
following: z7.boolean()
|
|
1292
|
+
}),
|
|
1293
|
+
examples: [{ args: { username: "jack" }, description: "Unfollow @jack" }],
|
|
1294
|
+
async run(c) {
|
|
1295
|
+
try {
|
|
1296
|
+
const client = createXApiClient(writeAuthToken(c.env));
|
|
1297
|
+
const me = await client.getMe();
|
|
1298
|
+
const targetRes = await resolveUser(client, c.args.username);
|
|
1299
|
+
const target = targetRes.data;
|
|
1300
|
+
const res = await client.unfollowUser(me.data.id, target.id);
|
|
1301
|
+
return c.ok({
|
|
1302
|
+
id: target.id,
|
|
1303
|
+
username: target.username,
|
|
1304
|
+
following: res.data.following
|
|
1305
|
+
});
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
const authError = toWriteAuthError("users unfollow", error);
|
|
1308
|
+
if (authError) return c.error(authError);
|
|
1309
|
+
throw error;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1201
1313
|
users.command("followers", {
|
|
1202
1314
|
description: "List followers of a user. Supports optional client-side baseline diffing for new follower detection.",
|
|
1203
1315
|
args: z7.object({
|
|
@@ -1439,7 +1551,15 @@ var cli = Cli7.create("xapi", {
|
|
|
1439
1551
|
version: pkg.version,
|
|
1440
1552
|
description: "X (Twitter) API CLI for spectra-the-bot."
|
|
1441
1553
|
});
|
|
1442
|
-
var WRITE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
1554
|
+
var WRITE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
1555
|
+
"posts create",
|
|
1556
|
+
"posts delete",
|
|
1557
|
+
"posts like",
|
|
1558
|
+
"posts retweet",
|
|
1559
|
+
"users follow",
|
|
1560
|
+
"users unfollow",
|
|
1561
|
+
"dm send"
|
|
1562
|
+
]);
|
|
1443
1563
|
cli.use(async ({ command, error }, next) => {
|
|
1444
1564
|
try {
|
|
1445
1565
|
return await next();
|