Skip to content

Commit

Permalink
Prettify code
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinaisslaying committed Mar 29, 2024
1 parent d0bc194 commit 3ca5465
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 118 deletions.
155 changes: 88 additions & 67 deletions src/Routes/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ router.post(
}

if (req.body.clientID) {
if (Number.isNaN(req.body.clientID) || req.body.clientID.includes(" ")) {
if (
Number.isNaN(req.body.clientID) ||
req.body.clientID.includes(" ")
) {
error = true;
errors.push(res.__("common.error.bot.arr.invalidClientID"));
}
Expand Down Expand Up @@ -287,24 +290,26 @@ router.post(
query: `{guild(id:"${req.body.widgetServer}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
});
});

let fetchChannel = true;

Expand Down Expand Up @@ -352,24 +357,26 @@ router.post(
query: `{channel(id:"${req.body.widgetChannel}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
});
});
}

if (req.body.twitter?.length > 15) {
Expand Down Expand Up @@ -591,7 +598,7 @@ router.post(
shortDesc: req.body.shortDescription,
longDesc: req.body.longDescription,
modNotes: req.body.modNotes,
lastDenyReason: botExists.lastDenyReason || '',
lastDenyReason: botExists.lastDenyReason || "",
reviewNotes: [],
editors,
commands,
Expand Down Expand Up @@ -682,7 +689,7 @@ router.post(
shortDesc: req.body.shortDescription,
longDesc: req.body.longDescription,
modNotes: req.body.modNotes,
lastDenyReason: botExists.lastDenyReason || '',
lastDenyReason: botExists.lastDenyReason || "",
reviewNotes: [],
editors,
commands,
Expand Down Expand Up @@ -1184,7 +1191,10 @@ router.post(
}

if (req.body.clientID) {
if (Number.isNaN(req.body.clientID) || req.body.clientID.includes(" ")) {
if (
Number.isNaN(req.body.clientID) ||
req.body.clientID.includes(" ")
) {
error = true;
errors.push(res.__("common.error.bot.arr.invalidClientID"));
}
Expand Down Expand Up @@ -1366,24 +1376,26 @@ router.post(
query: `{guild(id:"${req.body.widgetServer}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
});
});

let fetchChannel = true;

Expand Down Expand Up @@ -1431,24 +1443,26 @@ router.post(
query: `{channel(id:"${req.body.widgetChannel}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
});
});
}

if (req.body.twitter?.length > 15) {
Expand Down Expand Up @@ -1965,7 +1979,9 @@ router.get("/:id", variables, async (req: Request, res: Response) => {
});

router.get("/:id/exists", permission.auth, async (req, res) => {
res.type("text").send(String(await global.redis?.hexists("bots", req.params.id)));
res.type("text").send(
String(await global.redis?.hexists("bots", req.params.id))
);
});

router.get(
Expand Down Expand Up @@ -2576,7 +2592,10 @@ router.post(
}

if (req.body.clientID) {
if (Number.isNaN(req.body.clientID) || req.body.clientID.includes(" ")) {
if (
Number.isNaN(req.body.clientID) ||
req.body.clientID.includes(" ")
) {
error = true;
errors.push(res.__("common.error.bot.arr.invalidClientID"));
}
Expand Down Expand Up @@ -2758,24 +2777,26 @@ router.post(
query: `{guild(id:"${req.body.widgetServer}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (data && !data.guild?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.guildNotFound"
)
);
});
});

let fetchChannel = true;

Expand Down Expand Up @@ -3566,7 +3587,7 @@ router.post(
$set: {
vanityUrl: "",
lastDenyReason: req.body.reason,
"status.archived": true,
"status.archived": true
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/Routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ router.get("/", variables, (req: Request, res: Response) => {

router.post("/", variables, async (req: Request, res: Response) => {
let { query, only }: { query: string; only: string[] } = req.body;
if (!query || typeof(query) !== "string" || typeof(only) !== "object")
if (!query || typeof query !== "string" || typeof only !== "object")
return res.status(400).json({
error: true,
status: 400,
Expand Down
56 changes: 31 additions & 25 deletions src/Routes/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,26 @@ router.post(
query: `{channel(id:"${req.body.previewChannel}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
});
});
}

if (!req.body.shortDescription) {
Expand Down Expand Up @@ -438,7 +440,9 @@ router.get("/:id", variables, async (req: Request, res: Response) => {
});

router.get("/:id/exists", permission.auth, async (req, res) => {
res.type('text').send(String(await global.redis?.hexists("servers", req.params.id)));
res.type("text").send(
String(await global.redis?.hexists("servers", req.params.id))
);
});

router.get(
Expand Down Expand Up @@ -628,24 +632,26 @@ router.post(
query: `{channel(id:"${req.body.previewChannel}"){id}}`
}),
headers: { "Content-Type": "application/json" }
}).then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
})
.then(async (fetchRes: fetchRes) => {
const data: any = await fetchRes.json();
if (!data.channel?.id) {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
})
.catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
}
}).catch(() => {
error = true;
errors.push(
res.__(
"common.error.listing.arr.widgetbot.channelNotFound"
)
);
});
});
}

if (!req.body.shortDescription) {
Expand Down
4 changes: 3 additions & 1 deletion src/Routes/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ router.get("/:id", variables, async (req: Request, res: Response) => {
});

router.get("/:id/exists", permission.auth, async (req, res) => {
res.type('text').send(String(await global.redis?.hexists("templates", req.params.id)));
res.type("text").send(
String(await global.redis?.hexists("templates", req.params.id))
);
});

router.get(
Expand Down
6 changes: 5 additions & 1 deletion src/Util/Services/banned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export async function updateBanlist() {
await guilds.main.bans
.fetch()
.then(async (bans) => {
if (bans.size > 0) await global.redis?.hmset("bans", ...bans.map((ban) => [ban.user.id, true]));
if (bans.size > 0)
await global.redis?.hmset(
"bans",
...bans.map((ban) => [ban.user.id, true])
);
})
.catch((e) => console.error(e));
}
Expand Down
Loading

0 comments on commit 3ca5465

Please sign in to comment.