-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopenai.js
More file actions
1 lines (1 loc) · 2.21 KB
/
openai.js
File metadata and controls
1 lines (1 loc) · 2.21 KB
1
(()=>{"use strict";function t(t){for(const o in t)void 0===t[o]&&delete t[o];return t}var o;!function(t){let o,e,n,i;o||(o={}),e||(e={}),n||(n={}),i||(i={})}(o||(o={}));const e=top.Scratch||o;new class{constructor(o){this.option=o,this.blocks=[],this.menus={};for(const e of o.blocks){if(this[e.opcode]=e.bind,null!=e.menu&&Object.keys(Object(e.menu)).length>0)for(const t in e.menu)this.menus[t]={items:e.menu[t]};const o=e.text.match(/\[\S*:\S*]/gi),n={};null==o||o.map((o=>{const[i,c]=o.slice(1,-1).split(":");e.text=e.text.replace(o,`[${i}]`),n[i]=t({type:Scratch.ArgumentType[c.toUpperCase()],defaultValue:null!=e.default?e.default[i]:void 0,menu:null!=e.menu&&e.menu[i]?i:void 0})})),this.blocks.push(t({opcode:e.opcode,blockType:e.blockType,text:e.text,arguments:n,disableMonitor:e.disableMonitor}))}}getInfo(){return t({id:this.option.id,name:this.option.name,color1:this.option.color1,color2:this.option.color2,color3:this.option.color3,menuIconURI:this.option.menuIconURI,blockIconURI:this.option.blockIconURI,docsURI:this.option.docsURI,blocks:this.blocks,menus:this.menus})}register(){try{Scratch.extensions.register(this)}catch(o){t=`Failed to load extension ${this.option.name}`,top.mdui.snackbar(t),console.error(o)}var t}}({id:"openai",name:"ChatGPT",color1:"#0e0e0e",blocks:[{opcode:"ask",blockType:e.BlockType.REPORTER,text:"询问 ChatGPT [message:string]",default:{message:""},bind:({message:t})=>{return o=void 0,e=void 0,i=function*(){try{const o=yield fetch("https://chatgpt.deeptrain.net/gpt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:t})});return(yield o.json()).message}catch(t){return console.error(t),"请求过多!请稍后重试!"}},new((n=void 0)||(n=Promise))((function(t,c){function s(t){try{a(i.next(t))}catch(t){c(t)}}function r(t){try{a(i.throw(t))}catch(t){c(t)}}function a(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,r)}a((i=i.apply(o,e||[])).next())}));var o,e,n,i},disableMonitor:!0},{opcode:"donate",blockType:e.BlockType.COMMAND,text:"捐赠",bind:()=>window.open("https://afdian.net/@zmh-program")},{opcode:"info",blockType:e.BlockType.COMMAND,text:"(使用过程中有非正常言论请忽略)",bind:()=>""}]}).register()})();