1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
6e1b0c597b
rm lexicon
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 7s
2024-12-27 16:39:39 +09:00
b3f0cdd622
add game 2024-12-27 16:39:38 +09:00
28 changed files with 363 additions and 816 deletions

@ -1 +1 @@
Subproject commit 03a64c3652bd60cc8cfab09bd70368a1c7dab9d8
Subproject commit e55225eb57a05f38ccc7be58ce6b00279f4d636c

View File

@ -108,7 +108,7 @@ $ docker compose build
$ docker compose up -d
```
## pds
## pds:card
- https://atproto.com/ja/guides/lexicon
- https://at.syu.is/at/did:plc:uqzpqmrjnptsxezjx4xuh2mn/ai.syui.card/3lagpwihqxi2v
@ -116,4 +116,29 @@ $ docker compose up -d
```sh
# oauth(button)
[yui]ai.syui.card.verify -> [user]ai.syui.card
[yui]
$ ./target/debug/ai card-verify -i 0 -p 0 -r 0 -h syui.ai -d did:plc:uqzpqmrjnptsxezjx4xuh2mn
{"uri":"at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.card.verify/3lagpvhppmd2q"}
[user]
$ ./target/debug/ai card -i 0 -p 0 -r 0 -v at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.card.verify/3lagpvhppmd2q
```
## pds:game
- https://atproto.com/ja/specs/record-key
- https://at.syu.is/at/did:plc:uqzpqmrjnptsxezjx4xuh2mn/ai.syui.game/self
```sh
# oauth(play)
[yui]ai.syui.game.user -> [user]ai.syui.game
[account]
# https://at.syu.is/at/did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/syui
## [rkey]
1. echo $handle|cut -d . -f 1
2. $handle
3. tid
```

View File

@ -1,56 +0,0 @@
{
"lexicon": 1,
"id": "ai.syui.card",
"defs": {
"main": {
"type": "record",
"description": "Record containing a cards box.",
"key": "tid",
"record": {
"type": "object",
"required": ["verify", "createdAt"],
"properties": {
"id":{
"type": "integer",
"minimum": 0,
"maximum": 14,
"default": 0
},
"cp":{
"type": "integer",
"minimum": 1,
"maximum": 5000,
"default": 1
},
"rank":{
"type": "integer",
"minimum": 0,
"maximum": 7,
"default": 0
},
"rare": {
"type": "string",
"enum": ["normal", "super", "ultra", "yui", "ai"],
"default": "normal"
},
"author": {
"type": "string",
"format": "uri",
"description": "https://verify...",
"default": "https://yui.syui.ai"
},
"verify": {
"type": "string",
"format": "at-uri",
"description": "at://verify..."
},
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this post was originally created."
}
}
}
}
}
}

View File

@ -1,62 +0,0 @@
{
"lexicon": 1,
"id": "ai.syui.card.verify",
"defs": {
"main": {
"type": "record",
"description": "Record containing a card verify.",
"key": "tid",
"record": {
"type": "object",
"required": ["handle", "did", "createdAt"],
"properties": {
"id":{
"type": "integer",
"minimum": 0,
"maximum": 14,
"default": 0
},
"cp":{
"type": "integer",
"minimum": 1,
"maximum": 10000,
"default": 1
},
"rank":{
"type": "integer",
"minimum": 0,
"maximum": 7,
"default": 0
},
"rare": {
"type": "string",
"enum": ["normal", "super", "ultra", "yui", "ai"],
"default": "normal"
},
"handle": {
"type": "string",
"maxLength": 32,
"maxGraphemes": 32
},
"did": {
"type": "string"
},
"embed": {
"type": "union",
"refs": [
"app.bsky.embed.images",
"app.bsky.embed.external",
"app.bsky.embed.record",
"app.bsky.embed.recordWithMedia"
]
},
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this post was originally created."
}
}
}
}
}
}

View File

@ -1,30 +0,0 @@
{
"lexicon": 1,
"id": "ai.syui.o.comment",
"defs": {
"main": {
"type": "record",
"description": "Record containing a Frontpage comment.",
"key": "tid",
"record": {
"type": "object",
"required": ["content", "createdAt", "post"],
"properties": {
"content": {
"type": "string",
"maxLength": 100000,
"maxGraphemes": 10000,
"description": "The content of the comment."
},
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this comment was originally created."
},
"parent": { "type": "ref", "ref": "com.atproto.repo.strongRef" },
"post": { "type": "ref", "ref": "com.atproto.repo.strongRef" }
}
}
}
}
}

View File

@ -1,33 +0,0 @@
{
"lexicon": 1,
"id": "ai.syui.o.post",
"defs": {
"main": {
"type": "record",
"description": "Record containing a Frontpage post.",
"key": "tid",
"record": {
"type": "object",
"required": ["title", "url", "createdAt"],
"properties": {
"title": {
"type": "string",
"maxLength": 3000,
"maxGraphemes": 300,
"description": "The title of the post."
},
"url": {
"type": "string",
"format": "uri",
"description": "The URL of the post."
},
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this post was originally created."
}
}
}
}
}
}

View File

@ -1,23 +0,0 @@
{
"lexicon": 1,
"id": "ai.syui.o.vote",
"defs": {
"main": {
"type": "record",
"description": "Record containing a Frontpage vote.",
"key": "tid",
"record": {
"type": "object",
"required": ["subject", "createdAt"],
"properties": {
"subject": { "type": "ref", "ref": "com.atproto.repo.strongRef" },
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this vote was originally created."
}
}
}
}
}
}

View File

@ -1,126 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.applyWrites",
"defs": {
"main": {
"type": "procedure",
"description": "Apply a batch transaction of repository creates, updates, and deletes. Requires auth, implemented by PDS.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["repo", "writes"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo (aka, current account)."
},
"validate": {
"type": "boolean",
"description": "Can be set to 'false' to skip Lexicon schema validation of record data across all operations, 'true' to require it, or leave unset to validate only for known Lexicons."
},
"writes": {
"type": "array",
"items": {
"type": "union",
"refs": ["#create", "#update", "#delete"],
"closed": true
}
},
"swapCommit": {
"type": "string",
"description": "If provided, the entire operation will fail if the current repo commit CID does not match this value. Used to prevent conflicting repo mutations.",
"format": "cid"
}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": [],
"properties": {
"commit": {
"type": "ref",
"ref": "com.atproto.repo.defs#commitMeta"
},
"results": {
"type": "array",
"items": {
"type": "union",
"refs": ["#createResult", "#updateResult", "#deleteResult"],
"closed": true
}
}
}
}
},
"errors": [
{
"name": "InvalidSwap",
"description": "Indicates that the 'swapCommit' parameter did not match current commit."
}
]
},
"create": {
"type": "object",
"description": "Operation which creates a new record.",
"required": ["collection", "value"],
"properties": {
"collection": { "type": "string", "format": "nsid" },
"rkey": { "type": "string", "maxLength": 15 },
"value": { "type": "unknown" }
}
},
"update": {
"type": "object",
"description": "Operation which updates an existing record.",
"required": ["collection", "rkey", "value"],
"properties": {
"collection": { "type": "string", "format": "nsid" },
"rkey": { "type": "string" },
"value": { "type": "unknown" }
}
},
"delete": {
"type": "object",
"description": "Operation which deletes an existing record.",
"required": ["collection", "rkey"],
"properties": {
"collection": { "type": "string", "format": "nsid" },
"rkey": { "type": "string" }
}
},
"createResult": {
"type": "object",
"required": ["uri", "cid"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"validationStatus": {
"type": "string",
"knownValues": ["valid", "unknown"]
}
}
},
"updateResult": {
"type": "object",
"required": ["uri", "cid"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"validationStatus": {
"type": "string",
"knownValues": ["valid", "unknown"]
}
}
},
"deleteResult": {
"type": "object",
"required": [],
"properties": {}
}
}
}

View File

@ -1,72 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.createRecord",
"defs": {
"main": {
"type": "procedure",
"description": "Create a single new repository record. Requires auth, implemented by PDS.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["repo", "collection", "record"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo (aka, current account)."
},
"collection": {
"type": "string",
"format": "nsid",
"description": "The NSID of the record collection."
},
"rkey": {
"type": "string",
"description": "The Record Key.",
"maxLength": 15
},
"validate": {
"type": "boolean",
"description": "Can be set to 'false' to skip Lexicon schema validation of record data, 'true' to require it, or leave unset to validate only for known Lexicons."
},
"record": {
"type": "unknown",
"description": "The record itself. Must contain a $type field."
},
"swapCommit": {
"type": "string",
"format": "cid",
"description": "Compare and swap with the previous commit by CID."
}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["uri", "cid"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"commit": {
"type": "ref",
"ref": "com.atproto.repo.defs#commitMeta"
},
"validationStatus": {
"type": "string",
"knownValues": ["valid", "unknown"]
}
}
}
},
"errors": [
{
"name": "InvalidSwap",
"description": "Indicates that 'swapCommit' didn't match current repo commit."
}
]
}
}
}

View File

@ -1,14 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.defs",
"defs": {
"commitMeta": {
"type": "object",
"required": ["cid", "rev"],
"properties": {
"cid": { "type": "string", "format": "cid" },
"rev": { "type": "string" }
}
}
}
}

View File

@ -1,56 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.deleteRecord",
"defs": {
"main": {
"type": "procedure",
"description": "Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["repo", "collection", "rkey"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo (aka, current account)."
},
"collection": {
"type": "string",
"format": "nsid",
"description": "The NSID of the record collection."
},
"rkey": {
"type": "string",
"description": "The Record Key."
},
"swapRecord": {
"type": "string",
"format": "cid",
"description": "Compare and swap with the previous record by CID."
},
"swapCommit": {
"type": "string",
"format": "cid",
"description": "Compare and swap with the previous commit by CID."
}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"properties": {
"commit": {
"type": "ref",
"ref": "com.atproto.repo.defs#commitMeta"
}
}
}
},
"errors": [{ "name": "InvalidSwap" }]
}
}
}

View File

@ -1,51 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.describeRepo",
"defs": {
"main": {
"type": "query",
"description": "Get information about an account and repository, including the list of collections. Does not require auth.",
"parameters": {
"type": "params",
"required": ["repo"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo."
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": [
"handle",
"did",
"didDoc",
"collections",
"handleIsCorrect"
],
"properties": {
"handle": { "type": "string", "format": "handle" },
"did": { "type": "string", "format": "did" },
"didDoc": {
"type": "unknown",
"description": "The complete DID document for this account."
},
"collections": {
"type": "array",
"description": "List of all the collections (NSIDs) for which this repo contains at least one record.",
"items": { "type": "string", "format": "nsid" }
},
"handleIsCorrect": {
"type": "boolean",
"description": "Indicates if handle is currently valid (resolves bi-directionally)"
}
}
}
}
}
}
}

View File

@ -1,45 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.getRecord",
"defs": {
"main": {
"type": "query",
"description": "Get a single record from a repository. Does not require auth.",
"parameters": {
"type": "params",
"required": ["repo", "collection", "rkey"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo."
},
"collection": {
"type": "string",
"format": "nsid",
"description": "The NSID of the record collection."
},
"rkey": { "type": "string", "description": "The Record Key." },
"cid": {
"type": "string",
"format": "cid",
"description": "The CID of the version of the record. If not specified, then return the most recent version."
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["uri", "value"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"value": { "type": "unknown" }
}
}
},
"errors": [{ "name": "RecordNotFound" }]
}
}
}

View File

@ -1,13 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.importRepo",
"defs": {
"main": {
"type": "procedure",
"description": "Import a repo in the form of a CAR file. Requires Content-Length HTTP header to be set.",
"input": {
"encoding": "application/vnd.ipld.car"
}
}
}
}

View File

@ -1,44 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.listMissingBlobs",
"defs": {
"main": {
"type": "query",
"description": "Returns a list of missing blobs for the requesting account. Intended to be used in the account migration flow.",
"parameters": {
"type": "params",
"properties": {
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 1000,
"default": 500
},
"cursor": { "type": "string" }
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["blobs"],
"properties": {
"cursor": { "type": "string" },
"blobs": {
"type": "array",
"items": { "type": "ref", "ref": "#recordBlob" }
}
}
}
}
},
"recordBlob": {
"type": "object",
"required": ["cid", "recordUri"],
"properties": {
"cid": { "type": "string", "format": "cid" },
"recordUri": { "type": "string", "format": "at-uri" }
}
}
}
}

View File

@ -1,69 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.listRecords",
"defs": {
"main": {
"type": "query",
"description": "List a range of records in a repository, matching a specific collection. Does not require auth.",
"parameters": {
"type": "params",
"required": ["repo", "collection"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo."
},
"collection": {
"type": "string",
"format": "nsid",
"description": "The NSID of the record type."
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 50,
"description": "The number of records to return."
},
"cursor": { "type": "string" },
"rkeyStart": {
"type": "string",
"description": "DEPRECATED: The lowest sort-ordered rkey to start from (exclusive)"
},
"rkeyEnd": {
"type": "string",
"description": "DEPRECATED: The highest sort-ordered rkey to stop at (exclusive)"
},
"reverse": {
"type": "boolean",
"description": "Flag to reverse the order of the returned records."
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["records"],
"properties": {
"cursor": { "type": "string" },
"records": {
"type": "array",
"items": { "type": "ref", "ref": "#record" }
}
}
}
}
},
"record": {
"type": "object",
"required": ["uri", "cid", "value"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"value": { "type": "unknown" }
}
}
}
}

View File

@ -1,73 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.putRecord",
"defs": {
"main": {
"type": "procedure",
"description": "Write a repository record, creating or updating it as needed. Requires auth, implemented by PDS.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["repo", "collection", "rkey", "record"],
"nullable": ["swapRecord"],
"properties": {
"repo": {
"type": "string",
"format": "at-identifier",
"description": "The handle or DID of the repo (aka, current account)."
},
"collection": {
"type": "string",
"format": "nsid",
"description": "The NSID of the record collection."
},
"rkey": {
"type": "string",
"description": "The Record Key.",
"maxLength": 15
},
"validate": {
"type": "boolean",
"description": "Can be set to 'false' to skip Lexicon schema validation of record data, 'true' to require it, or leave unset to validate only for known Lexicons."
},
"record": {
"type": "unknown",
"description": "The record to write."
},
"swapRecord": {
"type": "string",
"format": "cid",
"description": "Compare and swap with the previous record by CID. WARNING: nullable and optional field; may cause problems with golang implementation"
},
"swapCommit": {
"type": "string",
"format": "cid",
"description": "Compare and swap with the previous commit by CID."
}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["uri", "cid"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" },
"commit": {
"type": "ref",
"ref": "com.atproto.repo.defs#commitMeta"
},
"validationStatus": {
"type": "string",
"knownValues": ["valid", "unknown"]
}
}
}
},
"errors": [{ "name": "InvalidSwap" }]
}
}
}

View File

@ -1,15 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.strongRef",
"description": "A URI with a content-hash fingerprint.",
"defs": {
"main": {
"type": "object",
"required": ["uri", "cid"],
"properties": {
"uri": { "type": "string", "format": "at-uri" },
"cid": { "type": "string", "format": "cid" }
}
}
}
}

View File

@ -1,23 +0,0 @@
{
"lexicon": 1,
"id": "com.atproto.repo.uploadBlob",
"defs": {
"main": {
"type": "procedure",
"description": "Upload a new blob, to be referenced from a repository record. The blob will be deleted if it is not referenced within a time window (eg, minutes). Blob restrictions (mimetype, size, etc) are enforced when the reference is created. Requires auth, implemented by PDS.",
"input": {
"encoding": "*/*"
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["blob"],
"properties": {
"blob": { "type": "blob" }
}
}
}
}
}
}

View File

@ -107,6 +107,7 @@ pub struct BaseUrl {
pub record_list: String,
pub record_create: String,
pub record_delete: String,
pub record_put: String,
pub session_create: String,
pub session_refresh: String,
pub session_get: String,
@ -142,6 +143,7 @@ pub fn url(s: &str) -> String {
let baseurl = BaseUrl {
profile_get: "com.atproto.identity.resolveHandle".to_string(),
thread_get: "app.bsky.feed.getPostThread".to_string(),
record_put: "com.atproto.repo.putRecord".to_string(),
record_create: "com.atproto.repo.createRecord".to_string(),
record_delete: "com.atproto.repo.deleteRecord".to_string(),
describe: "com.atproto.repo.describeRepo".to_string(),
@ -173,6 +175,7 @@ pub fn url(s: &str) -> String {
"record_list" => t.to_string() + &baseurl.record_list,
"record_create" => t.to_string() + &baseurl.record_create,
"record_delete" => t.to_string() + &baseurl.record_delete,
"record_put" => t.to_string() + &baseurl.record_put,
"session_create" => t.to_string() + &baseurl.session_create,
"session_refresh" => t.to_string() + &baseurl.session_refresh,
"session_get" => t.to_string() + &baseurl.session_get,

5
src/game.rs Normal file
View File

@ -0,0 +1,5 @@
pub mod post_card;
pub mod post_card_verify;
pub mod post_game;
pub mod post_game_user;
pub mod post_game_login;

View File

@ -9,9 +9,7 @@ pub async fn post_request(verify: String, id: i32, cp: i32, rank: i32, rare: Str
let token = data_refresh(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_create");
let d = Timestamp::now_utc();
let d = d.to_string();

39
src/game/post_game.rs Normal file
View File

@ -0,0 +1,39 @@
extern crate reqwest;
use crate::data_toml;
use crate::data_refresh;
use crate::url;
use iso8601_timestamp::Timestamp;
use serde_json::json;
pub async fn post_request(col: String, account: String) -> String {
let token = data_refresh(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_put");
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"repo": handle.to_string(),
"did": did.to_string(),
"collection": col.to_string(),
"rkey": "self".to_string(),
"record": {
"account": account.to_string(),
"createdAt": d.to_string(),
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res;
}

View File

@ -0,0 +1,42 @@
extern crate reqwest;
use crate::data_toml;
use crate::data_refresh;
use crate::url;
use iso8601_timestamp::Timestamp;
use serde_json::json;
pub async fn post_request(col: String, username: String, login: bool, account: String) -> String {
let token = data_refresh(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_put");
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"repo": handle.to_string(),
"did": did.to_string(),
"collection": col.to_string(),
"rkey": "self".to_string(),
"record": {
"login": login,
"username": username.to_string(),
"account": account.to_string(),
"createdAt": d.to_string(),
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res;
}

View File

@ -0,0 +1,55 @@
extern crate reqwest;
use crate::data_toml;
use crate::data_refresh;
use crate::url;
use iso8601_timestamp::Timestamp;
use serde_json::json;
pub async fn post_request(col: String, user_name: String, user_did: String, user_handle: String, aiten: i32, limit: i32, chara: String, lv: i32, exp: i32, hp: i32, rank: i32, mode: i32, attach: i32, critical: i32, critical_d: i32) -> String {
let token = data_refresh(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_put");
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"repo": handle.to_string(),
"did": did.to_string(),
"collection": col.to_string(),
"rkey": user_name.to_string(),
"record": {
"did": user_did.to_string(),
"handle": user_handle.to_string(),
"aiten": aiten,
"limit": limit,
"character": {
chara.to_string(): {
"lv": lv,
"exp": exp,
"hp": hp,
"rank": rank,
"mode": mode,
"attach": attach,
"critical": critical,
"critical_d": critical_d,
}
},
"createdAt": d.to_string(),
"updatedAt": d.to_string(),
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res;
}

View File

@ -12,6 +12,11 @@ use crate::data::url;
use crate::data::w_cfg;
use crate::data::w_refresh;
use crate::feed_watch::c_feed_watch;
use crate::game::post_card;
use crate::game::post_card_verify;
use crate::game::post_game;
use crate::game::post_game_user;
use crate::game::post_game_login;
use data::ProfileIdentityResolve;
@ -30,8 +35,7 @@ pub mod notify_read;
pub mod openai;
pub mod post;
pub mod post_link;
pub mod post_card;
pub mod post_card_verify;
pub mod game;
pub mod profile;
pub mod refresh;
pub mod reply;
@ -193,7 +197,7 @@ fn main() {
)
.command(
Command::new("card-verify")
.description("<at://verify> -c <collection> -i <id> -p <cp> -r <rank> -rare <normal> -h <syui.ai> -d <did>")
.description("<at://verify> -c <collection> -i <id> -p <cp> -r <rank> -rare <normal> -H <syui.ai> -d <did>")
.action(card_verify)
.flag(
Flag::new("col", FlagType::String)
@ -216,13 +220,100 @@ fn main() {
)
.flag(
Flag::new("handle", FlagType::String)
.alias("handle"),
.alias("H"),
)
.flag(
Flag::new("did", FlagType::String)
.alias("did"),
)
)
.command(
Command::new("game")
.description("a <at://yui.syui.ai/ai.syui.game.user/username>")
.action(game)
.flag(
Flag::new("col", FlagType::String)
.alias("c"),
)
.flag(
Flag::new("account", FlagType::String)
.alias("a"),
)
)
.command(
Command::new("game-login")
.description("l <bool> -u <username> -c <collection>")
.action(game_login)
.flag(
Flag::new("col", FlagType::String)
.alias("c"),
)
.flag(
Flag::new("login", FlagType::Bool)
.alias("l"),
)
.flag(
Flag::new("username", FlagType::String)
.alias("u"),
)
)
.command(
Command::new("game-user")
.description("-chara ai -l 20240101 -ten 0 --lv 0 --exp 0 --hp 0 --rank 0 --mode 0 --attach 0 --critical 0 --critical_d 0")
.action(game_user)
.flag(
Flag::new("username", FlagType::String)
.alias("u"),
)
.flag(
Flag::new("col", FlagType::String)
.alias("c"),
)
.flag(
Flag::new("did", FlagType::String)
.alias("d"),
)
.flag(
Flag::new("handle", FlagType::String)
.alias("H"),
)
.flag(
Flag::new("character", FlagType::String)
.alias("chara"),
)
.flag(
Flag::new("aiten", FlagType::Int)
.alias("ten"),
)
.flag(
Flag::new("limit", FlagType::Int)
.alias("l"),
)
.flag(
Flag::new("lv", FlagType::Int)
)
.flag(
Flag::new("hp", FlagType::Int)
)
.flag(
Flag::new("attach", FlagType::Int)
)
.flag(
Flag::new("exp", FlagType::Int)
)
.flag(
Flag::new("critical", FlagType::Int)
)
.flag(
Flag::new("critical_d", FlagType::Int)
)
.flag(
Flag::new("rank", FlagType::Int)
)
.flag(
Flag::new("mode", FlagType::Int)
)
)
.command(
Command::new("like")
.description("like <cid> -u <uri>")
@ -303,6 +394,10 @@ fn main() {
Flag::new("post", FlagType::String)
.alias("p"),
)
.flag(
Flag::new("col", FlagType::String)
.alias("c"),
)
)
.command(
Command::new("follow")
@ -578,6 +673,8 @@ async fn c_card_verify(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string());
let user_handle = c.string_flag("handle").unwrap_or_else(|_| "syui.ai".to_string());
let user_did = c.string_flag("did").unwrap_or_else(|_| "did:plc:uqzpqmrjnptsxezjx4xuh2mn".to_string());
//match id === 1 let img = "xxx";
let str = post_card_verify::post_request(col, img, id, cp, rank, rare, user_handle, user_did);
println!("{}", str.await);
Ok(())
@ -594,6 +691,92 @@ fn card_verify(c: &Context) {
});
}
async fn c_game(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
let account = c.string_flag("account").unwrap_or_else(|_| "at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/syui".to_string());
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.game".to_string());
let handle = data_toml(&"handle");
if handle == "syui.ai" {
let str = post_game::post_request(col, account);
println!("{}", str.await);
Ok(())
} else {
Err(Box::new(std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Not authorized")))
}
}
fn game(c: &Context) {
refresh(c);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async {
if let Err(e) = c_game(c).await {
eprintln!("Error: {}", e);
}
});
}
async fn c_game_user(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.game.user".to_string());
let user_name = c.string_flag("username").unwrap_or_else(|_| "syui".to_string());
let user_handle = c.string_flag("handle").unwrap_or_else(|_| "syui.ai".to_string());
let user_did = c.string_flag("did").unwrap_or_else(|_| "did:plc:uqzpqmrjnptsxezjx4xuh2mn".to_string());
let chara = c.string_flag("character").unwrap_or_else(|_| "ai".to_string());
let limit = c.int_flag("limit")?.try_into()?;
let aiten = c.int_flag("aiten")?.try_into()?;
let lv = c.int_flag("lv")?.try_into()?;
let exp = c.int_flag("exp")?.try_into()?;
let hp = c.int_flag("hp")?.try_into()?;
let rank = c.int_flag("rank")?.try_into()?;
let mode = c.int_flag("mode")?.try_into()?;
let attach = c.int_flag("attach")?.try_into()?;
let critical = c.int_flag("critical")?.try_into()?;
let critical_d = c.int_flag("critical_d")?.try_into()?;
if data_toml(&"handle") == "yui.syui.ai" {
let str = post_game_user::post_request(col, user_name, user_did, user_handle, aiten, limit, chara, lv, exp, hp, rank, mode, attach, critical, critical_d);
println!("{}", str.await);
Ok(())
} else {
Err(Box::new(std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Not authorized")))
}
}
fn game_user(c: &Context) {
refresh(c);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async {
if let Err(e) = c_game_user(c).await {
eprintln!("Error: {}", e);
}
});
}
async fn c_game_login(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.game.login".to_string());
let user_name = c.string_flag("username").unwrap_or_else(|_| "syui".to_string());
let account = "at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/".to_string() + &user_name;
let login = c.bool_flag("login");
if data_toml(&"handle") == "yui.syui.ai" {
let str = post_game_login::post_request(col, user_name, login, account);
println!("{}", str.await);
Ok(())
} else {
Err(Box::new(std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Not authorized")))
}
}
fn game_login(c: &Context) {
refresh(c);
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async {
if let Err(e) = c_game_login(c).await {
eprintln!("Error: {}", e);
}
});
}
fn repost(c: &Context) {
refresh(c);
let m = c.args[0].to_string();
@ -648,6 +831,7 @@ fn mention(c: &Context) {
let h = async {
let str = profile::get_request(m.to_string()).await;
let profile: ProfileIdentityResolve = serde_json::from_str(&str).unwrap();
let col = c.string_flag("col").unwrap_or_else(|_| "app.bsky.feed.post".to_string());
let udid = profile.did;
let handle = m.to_string();
let at = "@".to_owned() + &handle;
@ -655,6 +839,7 @@ fn mention(c: &Context) {
let s = 0;
if let Ok(post) = c.string_flag("post") {
let str = mention::post_request(
col,
post.to_string(),
at.to_string(),
udid.to_string(),

View File

@ -5,13 +5,13 @@ use crate::url;
use iso8601_timestamp::Timestamp;
use serde_json::json;
pub async fn post_request(text: String, at: String, udid: String, s: i32, e: i32) -> String {
pub async fn post_request(col: String, text: String, at: String, udid: String, s: i32, e: i32) -> String {
let token = data_refresh(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_create");
let col = "app.bsky.feed.post".to_string();
//let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
@ -22,7 +22,7 @@ pub async fn post_request(text: String, at: String, udid: String, s: i32, e: i32
"collection": col.to_string(),
"record": {
"text": at.to_string() + &" ".to_string() + &text.to_string(),
"$type": "app.bsky.feed.post",
"$type": col.to_string(),
"createdAt": d.to_string(),
"facets": [
{