fix bot invite creator
This commit is contained in:
parent
99c348b086
commit
3ce6748ad6
1 changed files with 124 additions and 119 deletions
|
@ -52,14 +52,14 @@ class Bot{
|
|||
|
||||
const finput = settingsLeft.addFileInput(
|
||||
I18n.getTranslation("uploadPfp"),
|
||||
_=>{
|
||||
(_) => {
|
||||
if (file) {
|
||||
this.updatepfp(file);
|
||||
}
|
||||
},
|
||||
{ clear: true }
|
||||
{clear: true},
|
||||
);
|
||||
finput.watchForChange(_=>{
|
||||
finput.watchForChange((_) => {
|
||||
if (!_) {
|
||||
file = null;
|
||||
hypouser.avatar = null;
|
||||
|
@ -78,14 +78,14 @@ class Bot{
|
|||
let bfile: undefined | File | null;
|
||||
const binput = settingsLeft.addFileInput(
|
||||
I18n.getTranslation("uploadBanner"),
|
||||
_=>{
|
||||
(_) => {
|
||||
if (bfile !== undefined) {
|
||||
this.updatebanner(bfile);
|
||||
}
|
||||
},
|
||||
{ clear: true }
|
||||
{clear: true},
|
||||
);
|
||||
binput.watchForChange(_=>{
|
||||
binput.watchForChange((_) => {
|
||||
if (!_) {
|
||||
bfile = null;
|
||||
hypouser.banner = undefined;
|
||||
|
@ -104,7 +104,7 @@ class Bot{
|
|||
let changed = false;
|
||||
const pronounbox = settingsLeft.addTextInput(
|
||||
I18n.getTranslation("pronouns"),
|
||||
_=>{
|
||||
(_) => {
|
||||
if (newpronouns || newbio || changed) {
|
||||
this.updateProfile({
|
||||
pronouns: newpronouns,
|
||||
|
@ -113,17 +113,17 @@ class Bot{
|
|||
});
|
||||
}
|
||||
},
|
||||
{ initText: bot.pronouns }
|
||||
{initText: bot.pronouns},
|
||||
);
|
||||
pronounbox.watchForChange(_=>{
|
||||
pronounbox.watchForChange((_) => {
|
||||
hypouser.pronouns = _;
|
||||
newpronouns = _;
|
||||
regen();
|
||||
});
|
||||
const bioBox = settingsLeft.addMDInput(I18n.getTranslation("bio"), _=>{}, {
|
||||
const bioBox = settingsLeft.addMDInput(I18n.getTranslation("bio"), (_) => {}, {
|
||||
initText: bot.bio.rawString,
|
||||
});
|
||||
bioBox.watchForChange(_=>{
|
||||
bioBox.watchForChange((_) => {
|
||||
newbio = _;
|
||||
hypouser.bio = new MarkDown(_, this.owner);
|
||||
regen();
|
||||
|
@ -136,10 +136,10 @@ class Bot{
|
|||
}
|
||||
const colorPicker = settingsLeft.addColorInput(
|
||||
I18n.getTranslation("profileColor"),
|
||||
_=>{},
|
||||
{ initColor: color }
|
||||
(_) => {},
|
||||
{initColor: color},
|
||||
);
|
||||
colorPicker.watchForChange(_=>{
|
||||
colorPicker.watchForChange((_) => {
|
||||
console.log();
|
||||
color = _;
|
||||
hypouser.accent_color = Number.parseInt("0x" + _.substr(1), 16);
|
||||
|
@ -151,8 +151,10 @@ class Bot{
|
|||
const guildsettings = settings.addButton("Guilds");
|
||||
guildsettings.addTitle(I18n.getTranslation("botGuilds"));
|
||||
fetch(this.info.api + "/users/@me/guilds/", {
|
||||
headers:this.headers
|
||||
}).then(_=>_.json()).then((json:(guildjson["properties"])[])=>{
|
||||
headers: this.headers,
|
||||
})
|
||||
.then((_) => _.json())
|
||||
.then((json: guildjson["properties"][]) => {
|
||||
for (const guild of json) {
|
||||
const content = document.createElement("div");
|
||||
content.classList.add("discovery-guild");
|
||||
|
@ -161,7 +163,8 @@ class Bot{
|
|||
const banner = document.createElement("img");
|
||||
banner.classList.add("banner");
|
||||
banner.crossOrigin = "anonymous";
|
||||
banner.src = this.info.cdn + "/icons/" + guild.id + "/" + guild.banner + ".png?size=256";
|
||||
banner.src =
|
||||
this.info.cdn + "/icons/" + guild.id + "/" + guild.banner + ".png?size=256";
|
||||
banner.alt = "";
|
||||
content.appendChild(banner);
|
||||
}
|
||||
|
@ -171,7 +174,11 @@ class Bot{
|
|||
const img = document.createElement("img");
|
||||
img.classList.add("icon");
|
||||
img.crossOrigin = "anonymous";
|
||||
img.src = this.info.cdn + (guild.icon? "/icons/" + guild.id + "/" + guild.icon + ".png?size=48": "/embed/avatars/3.png");
|
||||
img.src =
|
||||
this.info.cdn +
|
||||
(guild.icon
|
||||
? "/icons/" + guild.id + "/" + guild.icon + ".png?size=48"
|
||||
: "/embed/avatars/3.png");
|
||||
img.alt = "";
|
||||
nameContainer.appendChild(img);
|
||||
|
||||
|
@ -183,7 +190,6 @@ class Bot{
|
|||
desc.textContent = guild.description;
|
||||
content.appendChild(desc);
|
||||
|
||||
|
||||
guildsettings.addHTMLArea(content);
|
||||
content.onclick = () => {
|
||||
const guildsetting = guildsettings.addSubOptions(guild.name);
|
||||
|
@ -192,13 +198,13 @@ class Bot{
|
|||
if (confirm(I18n.getTranslation("confirmGuildLeave", guild.name))) {
|
||||
fetch(this.info.api + "/users/@me/guilds/" + guild.id, {
|
||||
method: "DELETE",
|
||||
headers:this.headers
|
||||
})
|
||||
headers: this.headers,
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
settings.show();
|
||||
}
|
||||
|
@ -239,11 +245,7 @@ class Bot{
|
|||
});
|
||||
}
|
||||
}
|
||||
updateProfile(json: {
|
||||
bio?: string;
|
||||
pronouns?: string;
|
||||
accent_color?: number;
|
||||
}){
|
||||
updateProfile(json: {bio?: string; pronouns?: string; accent_color?: number}) {
|
||||
fetch(this.info.api + "/users/@me/profile", {
|
||||
method: "PATCH",
|
||||
headers: this.headers,
|
||||
|
@ -252,7 +254,7 @@ class Bot{
|
|||
}
|
||||
static InviteMaker(id: string, container: Form, info: Localuser["info"]) {
|
||||
const gen = container.addSubOptions(I18n.getTranslation("UrlGen"), {
|
||||
noSubmit:true
|
||||
noSubmit: true,
|
||||
});
|
||||
const params = new URLSearchParams("");
|
||||
params.set("instance", info.wellknown);
|
||||
|
@ -271,8 +273,11 @@ class Bot{
|
|||
}
|
||||
params.set("permissions", perms.allow.toString());
|
||||
const encoded = params.toString();
|
||||
url.setText(`${location.origin}/oauth2/authorize?${encoded}`);
|
||||
},100)
|
||||
const urlStr = `${location.origin}/oauth2/authorize?${encoded}`;
|
||||
if (urlStr == url.elm.deref()?.textContent) return;
|
||||
console.log(urlStr, url.text);
|
||||
url.setText(urlStr);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
export {Bot};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue