From 8b02d4312497c9d0d8d766c2ac816d7e3fa42aa4 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 6 Apr 2024 02:14:12 +0900 Subject: [PATCH] fix --- js/terminal.js | 148 +++++++++++++++++++++++++++++++++---------------- json/ai.json | 5 +- 2 files changed, 103 insertions(+), 50 deletions(-) diff --git a/js/terminal.js b/js/terminal.js index de3037e..628db8a 100755 --- a/js/terminal.js +++ b/js/terminal.js @@ -8,9 +8,32 @@ $(function() { if (did == null) { did = "did:plc:4hqjfn7m6n5hno3doamuhgef" }; if (user) { prompt = "[[b;#87cefa;]" + user + "][[b;#FFFF00;]@aios] ~$ " }; var tab = "[[b;#87cefa;]]"; - var command_all = ["ai", "timeline", "bsky_ver", "handle", "did", "plc"]; + var command_all = ["ai","ls","ai.json"]; var handle = "yui.syui.ai"; + var file_all = "ai.json"; + var ai_help = "\n\ +\nCommands:\ +\n ai\ +\n\ +\nFlags:\ +\n\t\t-h, --help\ +\n\ +\nOptions:\ +\n\ta\t\t\t\t: logo\ +\n\tv\t\t\t\t: pds version\ +\n\tp\t\t\t\t: ai profile\ +\n\tdid\t : did\ +\n\tplc\t : plc\ +\n\trecord : timeline\ +\n\ +\nex:\ +\n\t$ ai v\t: {\"version\":\"0.0.1\"}\ +\n\t\ +\nhttps://git.syui.ai/ai/bot\ +\n\t\ + "; + var ascii_logo = '\n\ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠉⠀⠀⠀⠀⠀⠈⠉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀\⠀ \n⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣦⣤⣤⣤⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀\⠀ \n⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀\⠀ \n⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆\⠀ \n⠀⠀⠘⠛⠛⠛⠛⠉⠉⠉⠉⠁⠀⠀⠀⠀⠈⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠉⠉⠉⠉⠙⠛⠛⠛⠛\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n\n'; var ascii_ai = "\n\ @@ -60,27 +83,52 @@ $(function() { "; let list = 'https://bsky.social/xrpc/com.atproto.repo.listRecords?repo='; - axios.get(list + did + '&collection=app.bsky.feed.post&limit=1') - .then(function (response) { - timeline = JSON.stringify(response.data.records[0].value,null,"\t"); - }) + function bsky_record() { + var u; + u = axios.get(list + did + '&collection=app.bsky.feed.post&limit=1') + .then(function (response) { + return JSON.stringify(response.data.records[0].value,null,"\t"); + }) + return u; + } - axios.get('https://bsky.social/xrpc/_health') - .then(function (response) { - bsky_ver = JSON.stringify(response.data,null,"\t"); - }) + function bsky_ver() { + var u; + u = axios.get('https://bsky.social/xrpc/_health') + .then(function (response) { + return JSON.stringify(response.data,null,"\t"); + }) + return u; + } let plc_server = "https://plc.directory/" - axios.get(plc_server + did + '/log') - .then(function (response) { - plc = JSON.stringify(response.data,null,"\t"); - }) + function bsky_plc() { + var u; + u = axios.get(plc_server + did + '/log') + .then(function (response) { + return JSON.stringify(response.data,null,"\t"); + }) + return u; + } let desc = 'https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo='; - axios.get(desc + did + '&collection=app.bsky.actor.profile') - .then(function (response) { - bsky_did = JSON.stringify(response.data,null,"\t"); - }) + function bsky_desc() { + var u; + u = axios.get(desc + did + '&collection=app.bsky.actor.profile') + .then(function (response) { + return JSON.stringify(response.data,null,"\t"); + }) + return u; + } + + function bsky_did() { + var u; + u = axios.get(desc + handle + '&collection=app.bsky.actor.profile') + .then(function (response) { + return JSON.stringify(response.data.did,null,"\t").replaceAll('"', ''); + }) + return u; + } function test_json() { var u; @@ -125,11 +173,27 @@ $(function() { var command, inputs; inputs = input.split(/ +/) command = inputs[0]; - if (inputs[0] === 'ai') { + option = inputs[1]; + if (did == null) { did = "did:plc:4hqjfn7m6n5hno3doamuhgef" }; + if (handle == null) { handle = "did:plc:4hqjfn7m6n5hno3doamuhgef" }; + if (command === 'ai' && inputs[1] === undefined) { + term.echo(ai_help); + } else if (command === 'ls') { + term.echo(file_all); + } else if (command === 'cat') { + if (option === 'ai.json') { + term.echo(test_json()); + } else { + term.echo(file_all); + } + } else if (command === 'ai' && option === 'a') { print_slowly(term, ascii_logo); + } else if (command === 'ai' && option === 'p') { + term.echo(ascii_ai); term.echo(test_json()); - } else if (inputs[0] === 'plc' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + } else if (command === 'ai' && option === 'plc') { + if (inputs[2] != undefined) { did = inputs[2]; } + url = desc + did + '&collection=app.bsky.actor.profile'; $.ajaxSetup({async: false}); $.getJSON(url, function(data) { did = JSON.stringify(data.did,null,"\t").replaceAll('"', '') @@ -139,45 +203,35 @@ $(function() { term.echo(JSON.stringify(data,null,"\t")); });$.ajaxSetup({async: true}); });$.ajaxSetup({async: true}); - } else if (inputs[0] === 'plc') { - term.echo(plc); - term.echo("$ plc "); - } else if (inputs[0] === 'timeline' && inputs[1] != undefined) { - url = list + inputs[1] + '&collection=app.bsky.feed.post&limit=1'; + } else if (command === 'ai' && option === 'record') { + if (inputs[2] != undefined) { did = inputs[2]; } + url = list + did + '&collection=app.bsky.feed.post&limit=1'; $.ajaxSetup({async: false}); $.getJSON(url, function(data) { term.echo(JSON.stringify(data,null,"\t")); - });$.ajaxSetup({async: true}); - } else if (inputs[0] === 'timeline') { - term.echo(timeline); - term.echo("$ timeline "); - } else if (inputs[0] === 'did' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + });$.ajaxSetup({async: true}); + } else if (command === 'ai' && option === 'did') { + if (inputs[2] != undefined) { handle = inputs[2]; } + url = desc + handle + '&collection=app.bsky.actor.profile'; $.ajaxSetup({async: false}); $.getJSON(url, function(data) { - term.echo(JSON.stringify(data.did,null,"\t")); - });$.ajaxSetup({async: true}); - } else if (inputs[0] === 'did') { + term.echo(JSON.stringify(data.did,null,"\t").replaceAll('"', '')); + });$.ajaxSetup({async: true}); + } else if (command === 'ai' && option === 'handle') { + if (inputs[2] != undefined) { did = inputs[2]; } url = desc + did + '&collection=app.bsky.actor.profile'; $.ajaxSetup({async: false}); $.getJSON(url, function(data) { - term.echo(JSON.stringify(data.did,null,"\t")); - });$.ajaxSetup({async: true}); - term.echo("$ did "); - } else if (inputs[0] === 'handle' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + term.echo(JSON.stringify(data,null,"\t")); + });$.ajaxSetup({async: true}); + } else if (command === 'ai' && option === 'v') { + url = 'https://bsky.social/xrpc/_health'; $.ajaxSetup({async: false}); $.getJSON(url, function(data) { term.echo(JSON.stringify(data,null,"\t")); - });$.ajaxSetup({async: true}); - } else if (inputs[0] === 'handle') { - term.echo(bsky_did); - term.echo("$ handle "); - } else if (inputs[0] === 'bsky_ver') { - term.echo(bsky_ver); + });$.ajaxSetup({async: true}); } else { - term.error(command + " is not a valid command"); - term.echo(command_all); + term.echo(ai_help); } } diff --git a/json/ai.json b/json/ai.json index 468c29e..0650f7a 100644 --- a/json/ai.json +++ b/json/ai.json @@ -1,7 +1,6 @@ { - "did": "did:plc:4hqjfn7m6n5hno3doamuhgef", "handle": "yui.syui.ai", "displayName": "ai", - "day":"01/23", - "size":"123cm" + "day": "01/23", + "size": "123cm" }