diff --git a/.dist/channel.js b/.dist/channel.js index 6f911e8..623f1a0 100644 --- a/.dist/channel.js +++ b/.dist/channel.js @@ -1017,7 +1017,7 @@ class Channel { body: JSON.stringify({ allow: "0", deny: "0", - id: role.snowflake, + id: role.id, type: 0 }) }); diff --git a/.dist/localuser.js b/.dist/localuser.js index f9c043c..26d5f16 100644 --- a/.dist/localuser.js +++ b/.dist/localuser.js @@ -476,6 +476,10 @@ class Localuser { createGuild() { let inviteurl = ""; const error = document.createElement("span"); + const fields = { + name: "", + icon: null, + }; const full = new Dialog(["tabs", [ ["Join using invite", [ "vdiv", @@ -509,12 +513,41 @@ class Localuser { } ] ]], - ["Create Server", [ - "text", "Not currently implemented, sorry" - ]] + ["Create Guild", + ["vdiv", + ["title", "Create a guild"], + ["fileupload", "Icon:", function (event) { + const reader = new FileReader(); + const target = event.target; + reader.readAsDataURL(target.files[0]); + reader.onload = () => { + fields.icon = reader.result; + }; + }], + ["textbox", "Name:", "", function (event) { + const target = event.target; + fields.name = target.value; + }], + ["button", "", "submit", () => { + this.makeGuild(fields).then(_ => { + if (_.message) { + alert(_.errors.name._errors[0].message); + } + else { + full.hide(); + } + }); + }]]] ]]); full.show(); } + async makeGuild(fields) { + return await (await fetch(this.info.api + "/guilds", { + method: "POST", + headers: this.headers, + body: JSON.stringify(fields), + })).json(); + } async guildDiscovery() { const content = document.createElement("div"); content.classList.add("guildy"); diff --git a/webpage/channel.ts b/webpage/channel.ts index 617a051..7cc5ca3 100644 --- a/webpage/channel.ts +++ b/webpage/channel.ts @@ -1005,7 +1005,7 @@ class Channel{ body:JSON.stringify({ allow:"0", deny:"0", - id:role.snowflake, + id:role.id, type:0 }) }) diff --git a/webpage/localuser.ts b/webpage/localuser.ts index f0267ff..8ad8553 100644 --- a/webpage/localuser.ts +++ b/webpage/localuser.ts @@ -487,7 +487,10 @@ class Localuser{ createGuild(){ let inviteurl=""; const error=document.createElement("span"); - + const fields:{name:string,icon:string}={ + name:"", + icon:null, + } const full=new Dialog(["tabs",[ ["Join using invite",[ "vdiv", @@ -522,12 +525,41 @@ class Localuser{ ] ]], - ["Create Server",[ - "text","Not currently implemented, sorry" + ["Create Guild", + ["vdiv", + ["title","Create a guild"], + ["fileupload","Icon:",function(event:InputEvent){ + const reader=new FileReader(); + const target=event.target as HTMLInputElement; + reader.readAsDataURL(target.files[0]); + reader.onload=() => { + fields.icon=reader.result as string; + } + }], + ["textbox","Name:","",function(event:InputEvent){ + const target=event.target as HTMLInputElement; + fields.name=target.value; + }], + ["button","","submit",()=>{ + this.makeGuild(fields).then(_=>{ + if(_.message){ + alert(_.errors.name._errors[0].message) + }else{ + full.hide(); + } + }) + }] ]] ]]) full.show(); } + async makeGuild(fields:{name:string,icon:string}){ + return await (await fetch(this.info.api+"/guilds",{ + method:"POST", + headers:this.headers, + body:JSON.stringify(fields), + })).json(); + } async guildDiscovery() { const content=document.createElement("div"); content.classList.add("guildy");