diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-01-14 13:33:24 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-01-14 13:33:24 +0100 |
commit | 32b93c857f89283f276be5ae2e39c9d11c87fece (patch) | |
tree | df7b4bcd0f375d06f2d5d4333f491680a0973cb6 | |
parent | Move isTextChannel to channel (diff) | |
download | server-32b93c857f89283f276be5ae2e39c9d11c87fece.tar.xz |
var -> let
Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com>
62 files changed, 133 insertions, 133 deletions
diff --git a/scripts/benchmark/connections.js b/scripts/benchmark/connections.js index 1a30d49f..c2b9e19e 100644 --- a/scripts/benchmark/connections.js +++ b/scripts/benchmark/connections.js @@ -4,7 +4,7 @@ const WebSocket = require("ws"); const endpoint = process.env.GATEWAY || "ws://localhost:3001"; const connections = Number(process.env.CONNECTIONS) || 50; const token = process.env.TOKEN; -var cores = 1; +let cores = 1; try { cores = Number(process.env.THREADS) || os.cpus().length; } catch { diff --git a/scripts/client.js b/scripts/client.js index 3cdd3719..4756fe46 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -232,15 +232,15 @@ const processFile = async (name) => { console.log(); - var existing = await fs.readdir(CACHE_PATH); + let existing = await fs.readdir(CACHE_PATH); while (existing.length > 0) { - var file = existing.shift(); + let file = existing.shift(); process.stdout.write( `Patching existing ${file}. Remaining: ${existing.length}. \r`, ); - var text = await fs.readFile(path.join(CACHE_PATH, file)); + let text = await fs.readFile(path.join(CACHE_PATH, file)); if (file.includes(".js") || file.includes(".css")) { text = doPatch(text.toString()); await fs.writeFile(path.join(CACHE_PATH, file), text.toString()); @@ -260,7 +260,7 @@ const processFile = async (name) => { let promises = []; - for (var i = 0; i < assets.length; i++) { + for (let i = 0; i < assets.length; i++) { const asset = assets[i]; if (existsSync(path.join(CACHE_PATH, `${asset}.js`))) { diff --git a/scripts/openapi.js b/scripts/openapi.js index 6f066e94..827acdec 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js @@ -15,7 +15,7 @@ const specification = JSON.parse( ); function combineSchemas(schemas) { - var definitions = {}; + let definitions = {}; for (const name in schemas) { definitions = { diff --git a/scripts/rights.js b/scripts/rights.js index 86c8db16..47e9dc51 100644 --- a/scripts/rights.js +++ b/scripts/rights.js @@ -8,7 +8,7 @@ const { Rights } = require(".."); const allRights = new Rights(1).bitfield; console.log(`All rights:`, allRights); -var discordLike = allRights; +let discordLike = allRights; discordLike -= Rights.FLAGS.OPERATOR; discordLike -= Rights.FLAGS.MANAGE_APPLICATIONS; discordLike -= Rights.FLAGS.MANAGE_MESSAGES; diff --git a/scripts/schema.js b/scripts/schema.js index fedbf25f..cfd99d4e 100644 --- a/scripts/schema.js +++ b/scripts/schema.js @@ -41,7 +41,7 @@ const Excluded = [ ]; function modify(obj) { - for (var k in obj) { + for (let k in obj) { if (typeof obj[k] === "object" && obj[k] !== null) { modify(obj[k]); } @@ -65,7 +65,7 @@ function main() { ); console.log(schemas); - var definitions = {}; + let definitions = {}; for (const name of schemas) { const part = TJS.generateSchema(program, name, settings, [], generator); @@ -100,11 +100,11 @@ function main() { main(); function walk(dir) { - var results = []; - var list = fs.readdirSync(dir); + let results = []; + let list = fs.readdirSync(dir); list.forEach(function (file) { file = dir + "/" + file; - var stat = fs.statSync(file); + let stat = fs.statSync(file); if (stat && stat.isDirectory()) { /* Recurse into a subdirectory */ results = results.concat(walk(file)); diff --git a/scripts/stresstest/index.js b/scripts/stresstest/index.js index a9a65097..740a9011 100644 --- a/scripts/stresstest/index.js +++ b/scripts/stresstest/index.js @@ -19,19 +19,19 @@ setInterval(() => { getUsers(); }, 60 * 1000); async function generate() { - var accounts = await JSON.parse(fs.readFileSync("accounts.json")); + let accounts = await JSON.parse(fs.readFileSync("accounts.json")); console.log(accounts); - var account = await register(); + let account = await register(); accounts.push(account); fs.writeFileSync("accounts.json", JSON.stringify(accounts)); console.log(accounts.length); - var y = await login(account); + let y = await login(account); sendMessage(y); } async function getUsers() { - var accounts = await JSON.parse(fs.readFileSync("accounts.json")); + let accounts = await JSON.parse(fs.readFileSync("accounts.json")); accounts.forEach(async (x) => { - var y = await login(x); + let y = await login(x); console.log(y); sendMessage(y); }); diff --git a/scripts/stresstest/src/login/index.js b/scripts/stresstest/src/login/index.js index 291e2b8b..7f04e569 100644 --- a/scripts/stresstest/src/login/index.js +++ b/scripts/stresstest/src/login/index.js @@ -1,14 +1,14 @@ const fetch = require("node-fetch"); const fs = require("fs"); -var config = require("../../config.json"); +let config = require("../../config.json"); module.exports = login; async function login(account) { - var body = { + let body = { fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw", login: account.email, password: account.password, }; - var x = await fetch(config.url + "/auth/login", { + let x = await fetch(config.url + "/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), diff --git a/scripts/stresstest/src/message/send.js b/scripts/stresstest/src/message/send.js index 1e5ea062..637cc11e 100644 --- a/scripts/stresstest/src/message/send.js +++ b/scripts/stresstest/src/message/send.js @@ -1,14 +1,14 @@ const fetch = require("node-fetch"); const fs = require("fs"); -var config = require("../../config.json"); +let config = require("../../config.json"); module.exports = sendMessage; async function sendMessage(account) { - var body = { + let body = { fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw", content: "Test", tts: false, }; - var x = await fetch( + let x = await fetch( config.url + "/channels/" + config["text-channel"] + "/messages", { method: "POST", diff --git a/scripts/stresstest/src/register/index.js b/scripts/stresstest/src/register/index.js index 38089dc7..0cfdc44a 100644 --- a/scripts/stresstest/src/register/index.js +++ b/scripts/stresstest/src/register/index.js @@ -1,21 +1,21 @@ const fetch = require("node-fetch"); const fs = require("fs"); -var config = require("../../config.json"); +let config = require("../../config.json"); module.exports = generate; async function generate() { - var mail = (Math.random() + 10).toString(36).substring(2); + let mail = (Math.random() + 10).toString(36).substring(2); mail = mail + "." + (Math.random() + 10).toString(36).substring(2) + "@stresstest.com"; - var password = + let password = (Math.random() * 69).toString(36).substring(-7) + (Math.random() * 69).toString(36).substring(-7) + (Math.random() * 69).toString(36).substring(-8); console.log(mail); console.log(password); - var body = { + let body = { fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw", email: mail, username: "Fosscord Stress Test", @@ -26,7 +26,7 @@ async function generate() { gift_code_sku_id: null, captcha_key: null, }; - var x = await fetch(config.url + "/auth/register", { + let x = await fetch(config.url + "/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), diff --git a/src/api/Server.ts b/src/api/Server.ts index f74505f6..088c1953 100644 --- a/src/api/Server.ts +++ b/src/api/Server.ts @@ -45,7 +45,7 @@ export class FosscordServer extends Server { this.app.use( morgan("combined", { skip: (req, res) => { - var skip = !( + let skip = !( process.env["LOG_REQUESTS"]?.includes( res.statusCode.toString(), ) ?? false diff --git a/src/api/routes/v9/channels/#channel_id/index.ts b/src/api/routes/v9/channels/#channel_id/index.ts index a164fff6..60d7987f 100644 --- a/src/api/routes/v9/channels/#channel_id/index.ts +++ b/src/api/routes/v9/channels/#channel_id/index.ts @@ -74,7 +74,7 @@ router.patch( "/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { - var payload = req.body as ChannelModifySchema; + let payload = req.body as ChannelModifySchema; const { channel_id } = req.params; if (payload.icon) payload.icon = await handleFile( diff --git a/src/api/routes/v9/channels/#channel_id/messages/#message_id/index.ts b/src/api/routes/v9/channels/#channel_id/messages/#message_id/index.ts index d57d9a1b..53c3c934 100644 --- a/src/api/routes/v9/channels/#channel_id/messages/#message_id/index.ts +++ b/src/api/routes/v9/channels/#channel_id/messages/#message_id/index.ts @@ -41,7 +41,7 @@ router.patch( }), async (req: Request, res: Response) => { const { message_id, channel_id } = req.params; - var body = req.body as MessageCreateSchema; + let body = req.body as MessageCreateSchema; const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, @@ -109,7 +109,7 @@ router.put( }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; - var body = req.body as MessageCreateSchema; + let body = req.body as MessageCreateSchema; const attachments: Attachment[] = []; const rights = await getRights(req.user_id); diff --git a/src/api/routes/v9/channels/#channel_id/messages/#message_id/reactions.ts b/src/api/routes/v9/channels/#channel_id/messages/#message_id/reactions.ts index 9f774682..3115d909 100644 --- a/src/api/routes/v9/channels/#channel_id/messages/#message_id/reactions.ts +++ b/src/api/routes/v9/channels/#channel_id/messages/#message_id/reactions.ts @@ -196,7 +196,7 @@ router.delete( "/:emoji/:user_id", route({}), async (req: Request, res: Response) => { - var { message_id, channel_id, user_id } = req.params; + let { message_id, channel_id, user_id } = req.params; const emoji = getEmoji(req.params.emoji); diff --git a/src/api/routes/v9/channels/#channel_id/messages/index.ts b/src/api/routes/v9/channels/#channel_id/messages/index.ts index 9913d3d8..d8c69dd0 100644 --- a/src/api/routes/v9/channels/#channel_id/messages/index.ts +++ b/src/api/routes/v9/channels/#channel_id/messages/index.ts @@ -51,7 +51,7 @@ router.get("/", async (req: Request, res: Response) => { if (limit < 1 || limit > 100) throw new HTTPError("limit must be between 1 and 100", 422); - var halfLimit = Math.floor(limit / 2); + let halfLimit = Math.floor(limit / 2); const permissions = await getPermission( req.user_id, @@ -61,7 +61,7 @@ router.get("/", async (req: Request, res: Response) => { permissions.hasThrow("VIEW_CHANNEL"); if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]); - var query: FindManyOptions<Message> & { where: { id?: any } } = { + let query: FindManyOptions<Message> & { where: { id?: any } } = { order: { timestamp: "DESC" }, take: limit, where: { channel_id }, @@ -129,7 +129,7 @@ router.get("/", async (req: Request, res: Response) => { which causes erorrs when, say, the `application` property is `null`. **/ - // for (var curr in x) { + // for (let curr in x) { // if (x[curr] === null) // delete x[curr]; // } @@ -174,7 +174,7 @@ router.post( }), async (req: Request, res: Response) => { const { channel_id } = req.params; - var body = req.body as MessageCreateSchema; + let body = req.body as MessageCreateSchema; const attachments: Attachment[] = []; const channel = await Channel.findOneOrFail({ @@ -202,7 +202,7 @@ router.post( } if (!req.rights.has(Rights.FLAGS.BYPASS_RATE_LIMITS)) { - var limits = Config.get().limits; + let limits = Config.get().limits; if (limits.absoluteRate.register.enabled) { const count = await Message.count({ where: { @@ -227,7 +227,7 @@ router.post( } const files = (req.files as Express.Multer.File[]) ?? []; - for (var currFile of files) { + for (let currFile of files) { try { const file = await uploadFile( `/attachments/${channel.id}`, diff --git a/src/api/routes/v9/channels/#channel_id/permissions.ts b/src/api/routes/v9/channels/#channel_id/permissions.ts index b08cd0c8..574f2bae 100644 --- a/src/api/routes/v9/channels/#channel_id/permissions.ts +++ b/src/api/routes/v9/channels/#channel_id/permissions.ts @@ -25,7 +25,7 @@ router.put( const { channel_id, overwrite_id } = req.params; const body = req.body as ChannelPermissionOverwriteSchema; - var channel = await Channel.findOneOrFail({ + let channel = await Channel.findOneOrFail({ where: { id: channel_id }, }); if (!channel.guild_id) throw new HTTPError("Channel not found", 404); @@ -39,7 +39,7 @@ router.put( } else throw new HTTPError("type not supported", 501); //@ts-ignore - var overwrite: ChannelPermissionOverwrite = + let overwrite: ChannelPermissionOverwrite = channel.permission_overwrites?.find((x) => x.id === overwrite_id); if (!overwrite) { // @ts-ignore diff --git a/src/api/routes/v9/channels/#channel_id/purge.ts b/src/api/routes/v9/channels/#channel_id/purge.ts index e158fb4c..b66fb24a 100644 --- a/src/api/routes/v9/channels/#channel_id/purge.ts +++ b/src/api/routes/v9/channels/#channel_id/purge.ts @@ -50,7 +50,7 @@ router.post( // TODO: send the deletion event bite-by-bite to prevent client stress - var query: FindManyOptions<Message> & { where: { id?: any } } = { + let query: FindManyOptions<Message> & { where: { id?: any } } = { order: { id: "ASC" }, // take: limit, where: { diff --git a/src/api/routes/v9/channels/#channel_id/webhooks.ts b/src/api/routes/v9/channels/#channel_id/webhooks.ts index 9f6e5a4d..9af188f0 100644 --- a/src/api/routes/v9/channels/#channel_id/webhooks.ts +++ b/src/api/routes/v9/channels/#channel_id/webhooks.ts @@ -34,7 +34,7 @@ router.post( if (webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks); - var { avatar, name } = req.body as WebhookCreateSchema; + let { avatar, name } = req.body as WebhookCreateSchema; name = trimSpecial(name); // TODO: move this diff --git a/src/api/routes/v9/discoverable-guilds.ts b/src/api/routes/v9/discoverable-guilds.ts index 428ca605..837c85a9 100644 --- a/src/api/routes/v9/discoverable-guilds.ts +++ b/src/api/routes/v9/discoverable-guilds.ts @@ -8,8 +8,8 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { offset, limit, categories } = req.query; - var showAllGuilds = Config.get().guild.discovery.showAllGuilds; - var configLimit = Config.get().guild.discovery.limit; + let showAllGuilds = Config.get().guild.discovery.showAllGuilds; + let configLimit = Config.get().guild.discovery.limit; let guilds; if (categories == undefined) { guilds = showAllGuilds diff --git a/src/api/routes/v9/guild-recommendations.ts b/src/api/routes/v9/guild-recommendations.ts index 8bf1e508..8ee7fe66 100644 --- a/src/api/routes/v9/guild-recommendations.ts +++ b/src/api/routes/v9/guild-recommendations.ts @@ -8,7 +8,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { limit, personalization_disabled } = req.query; - var showAllGuilds = Config.get().guild.discovery.showAllGuilds; + let showAllGuilds = Config.get().guild.discovery.showAllGuilds; const genLoadId = (size: Number) => [...Array(size)] diff --git a/src/api/routes/v9/guilds/#guild_id/delete.ts b/src/api/routes/v9/guilds/#guild_id/delete.ts index b951e4f4..2c15e0de 100644 --- a/src/api/routes/v9/guilds/#guild_id/delete.ts +++ b/src/api/routes/v9/guilds/#guild_id/delete.ts @@ -18,7 +18,7 @@ const router = Router(); // discord prefixes this route with /delete instead of using the delete method // docs are wrong https://discord.com/developers/docs/resources/guild#delete-guild router.post("/", route({}), async (req: Request, res: Response) => { - var { guild_id } = req.params; + let { guild_id } = req.params; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, diff --git a/src/api/routes/v9/guilds/#guild_id/index.ts b/src/api/routes/v9/guilds/#guild_id/index.ts index 79c20678..d2e22011 100644 --- a/src/api/routes/v9/guilds/#guild_id/index.ts +++ b/src/api/routes/v9/guilds/#guild_id/index.ts @@ -50,7 +50,7 @@ router.patch( "MANAGE_GUILDS", ); - var guild = await Guild.findOneOrFail({ + let guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["emojis", "roles", "stickers"], }); @@ -92,7 +92,7 @@ router.patch( "DISCOVERABLE", ]; - for (var feature of diff) { + for (let feature of diff) { if (MUTABLE_FEATURES.includes(feature)) continue; throw FosscordApiErrors.FEATURE_IS_IMMUTABLE.withParams( diff --git a/src/api/routes/v9/guilds/#guild_id/members/#member_id/index.ts b/src/api/routes/v9/guilds/#guild_id/members/#member_id/index.ts index 0fcdd57c..f68ea8c4 100644 --- a/src/api/routes/v9/guilds/#guild_id/members/#member_id/index.ts +++ b/src/api/routes/v9/guilds/#guild_id/members/#member_id/index.ts @@ -91,19 +91,19 @@ router.put("/", route({}), async (req: Request, res: Response) => { // TODO: join others by controller } - var guild = await Guild.findOneOrFail({ + let guild = await Guild.findOneOrFail({ where: { id: guild_id }, }); - var emoji = await Emoji.find({ + let emoji = await Emoji.find({ where: { guild_id: guild_id }, }); - var roles = await Role.find({ + let roles = await Role.find({ where: { guild_id: guild_id }, }); - var stickers = await Sticker.find({ + let stickers = await Sticker.find({ where: { guild_id: guild_id }, }); diff --git a/src/api/routes/v9/guilds/#guild_id/members/#member_id/nick.ts b/src/api/routes/v9/guilds/#guild_id/members/#member_id/nick.ts index 20443821..f889fe2c 100644 --- a/src/api/routes/v9/guilds/#guild_id/members/#member_id/nick.ts +++ b/src/api/routes/v9/guilds/#guild_id/members/#member_id/nick.ts @@ -8,8 +8,8 @@ router.patch( "/", route({ body: "MemberNickChangeSchema" }), async (req: Request, res: Response) => { - var { guild_id, member_id } = req.params; - var permissionString: PermissionResolvable = "MANAGE_NICKNAMES"; + let { guild_id, member_id } = req.params; + let permissionString: PermissionResolvable = "MANAGE_NICKNAMES"; if (member_id === "@me") { member_id = req.user_id; permissionString = "CHANGE_NICKNAME"; diff --git a/src/api/routes/v9/guilds/#guild_id/messages/search.ts b/src/api/routes/v9/guilds/#guild_id/messages/search.ts index 88488871..6338422c 100644 --- a/src/api/routes/v9/guilds/#guild_id/messages/search.ts +++ b/src/api/routes/v9/guilds/#guild_id/messages/search.ts @@ -44,7 +44,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json({ messages: [], total_results: 0 }); - var query: FindManyOptions<Message> = { + let query: FindManyOptions<Message> = { order: { timestamp: sort_order ? (sort_order.toUpperCase() as "ASC" | "DESC") @@ -78,7 +78,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { }); const ids = []; - for (var channel of channels) { + for (let channel of channels) { const perm = await getPermission( req.user_id, req.params.guild_id, diff --git a/src/api/routes/v9/guilds/#guild_id/prune.ts b/src/api/routes/v9/guilds/#guild_id/prune.ts index 8089ad84..81741df5 100644 --- a/src/api/routes/v9/guilds/#guild_id/prune.ts +++ b/src/api/routes/v9/guilds/#guild_id/prune.ts @@ -11,16 +11,16 @@ export const inactiveMembers = async ( days: number, roles: string[] = [], ) => { - var date = new Date(); + let date = new Date(); date.setDate(date.getDate() - days); //Snowflake should have `generateFromTime` method? Or similar? - var minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22); + let minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22); /** idea: ability to customise the cutoff variable possible candidates: public read receipt, last presence, last VC leave **/ - var members = await Member.find({ + let members = await Member.find({ where: [ { guild_id, @@ -65,7 +65,7 @@ export const inactiveMembers = async ( router.get("/", route({}), async (req: Request, res: Response) => { const days = parseInt(req.query.days as string); - var roles = req.query.include_roles; + let roles = req.query.include_roles; if (typeof roles === "string") roles = [roles]; //express will return array otherwise const members = await inactiveMembers( @@ -84,7 +84,7 @@ router.post( async (req: Request, res: Response) => { const days = parseInt(req.body.days); - var roles = req.query.include_roles; + let roles = req.query.include_roles; if (typeof roles === "string") roles = [roles]; const { guild_id } = req.params; diff --git a/src/api/routes/v9/guilds/#guild_id/templates.ts b/src/api/routes/v9/guilds/#guild_id/templates.ts index 3b5eddaa..a069bb8b 100644 --- a/src/api/routes/v9/guilds/#guild_id/templates.ts +++ b/src/api/routes/v9/guilds/#guild_id/templates.ts @@ -26,7 +26,7 @@ const TemplateGuildProjection: (keyof Guild)[] = [ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - var templates = await Template.find({ + let templates = await Template.find({ where: { source_guild_id: guild_id }, }); diff --git a/src/api/routes/v9/guilds/#guild_id/voice-states/#user_id/index.ts b/src/api/routes/v9/guilds/#guild_id/voice-states/#user_id/index.ts index af03a07e..6506f060 100644 --- a/src/api/routes/v9/guilds/#guild_id/voice-states/#user_id/index.ts +++ b/src/api/routes/v9/guilds/#guild_id/voice-states/#user_id/index.ts @@ -19,7 +19,7 @@ router.patch( route({ body: "VoiceStateUpdateSchema" }), async (req: Request, res: Response) => { const body = req.body as VoiceStateUpdateSchema; - var { guild_id, user_id } = req.params; + let { guild_id, user_id } = req.params; if (user_id === "@me") user_id = req.user_id; const perms = await getPermission( diff --git a/src/api/routes/v9/guilds/#guild_id/widget.json.ts b/src/api/routes/v9/guilds/#guild_id/widget.json.ts index 2c3124a2..af2e5f57 100644 --- a/src/api/routes/v9/guilds/#guild_id/widget.json.ts +++ b/src/api/routes/v9/guilds/#guild_id/widget.json.ts @@ -28,7 +28,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { if (!guild.widget_enabled) throw new HTTPError("Widget Disabled", 404); // Fetch existing widget invite for widget channel - var invite = await Invite.findOne({ + let invite = await Invite.findOne({ where: { channel_id: guild.widget_channel_id }, }); diff --git a/src/api/routes/v9/users/#id/profile.ts b/src/api/routes/v9/users/#id/profile.ts index 5c649056..1e28430c 100644 --- a/src/api/routes/v9/users/#id/profile.ts +++ b/src/api/routes/v9/users/#id/profile.ts @@ -35,8 +35,8 @@ router.get( relations: ["connected_accounts"], }); - var mutual_guilds: object[] = []; - var premium_guild_since; + let mutual_guilds: object[] = []; + let premium_guild_since; if (with_mutual_guilds == "true") { const requested_member = await Member.find({ diff --git a/src/api/routes/v9/users/#id/relationships.ts b/src/api/routes/v9/users/#id/relationships.ts index c6480567..8bfa2ca1 100644 --- a/src/api/routes/v9/users/#id/relationships.ts +++ b/src/api/routes/v9/users/#id/relationships.ts @@ -18,7 +18,7 @@ router.get( "/", route({ test: { response: { body: "UserRelationsResponse" } } }), async (req: Request, res: Response) => { - var mutual_relations: object[] = []; + let mutual_relations: object[] = []; const requested_relations = await User.findOneOrFail({ where: { id: req.params.id }, relations: ["relationships"], @@ -35,7 +35,7 @@ router.get( rmem.type === 1 && rmem.to_id !== req.user_id ) { - var relation_user = await User.getPublicUser(rmem.to_id); + let relation_user = await User.getPublicUser(rmem.to_id); mutual_relations.push({ id: relation_user.id, diff --git a/src/api/routes/v9/users/@me/guilds/#guild_id/settings.ts b/src/api/routes/v9/users/@me/guilds/#guild_id/settings.ts index 436261d4..d84edb41 100644 --- a/src/api/routes/v9/users/@me/guilds/#guild_id/settings.ts +++ b/src/api/routes/v9/users/@me/guilds/#guild_id/settings.ts @@ -25,7 +25,7 @@ router.patch( const body = req.body as UserGuildSettingsSchema; if (body.channel_overrides) { - for (var channel in body.channel_overrides) { + for (let channel in body.channel_overrides) { Channel.findOneOrFail({ where: { id: channel } }); } } diff --git a/src/api/routes/v9/users/@me/index.ts b/src/api/routes/v9/users/@me/index.ts index 37356d9d..42c820f8 100644 --- a/src/api/routes/v9/users/@me/index.ts +++ b/src/api/routes/v9/users/@me/index.ts @@ -37,7 +37,7 @@ router.patch( }); // Populated on password change - var newToken: string | undefined; + let newToken: string | undefined; if (body.avatar) body.avatar = await handleFile( @@ -102,7 +102,7 @@ router.patch( } if (body.username) { - var check_username = body?.username?.replace(/\s/g, ""); + let check_username = body?.username?.replace(/\s/g, ""); if (!check_username) { throw FieldErrors({ username: { diff --git a/src/api/routes/v9/users/@me/mfa/codes-verification.ts b/src/api/routes/v9/users/@me/mfa/codes-verification.ts index 3411605b..e278c5ec 100644 --- a/src/api/routes/v9/users/@me/mfa/codes-verification.ts +++ b/src/api/routes/v9/users/@me/mfa/codes-verification.ts @@ -20,7 +20,7 @@ router.post( const user = await User.findOneOrFail({ where: { id: req.user_id } }); - var codes: BackupCode[]; + let codes: BackupCode[]; if (regenerate) { await BackupCode.update( { user: { id: req.user_id } }, diff --git a/src/api/routes/v9/users/@me/mfa/codes.ts b/src/api/routes/v9/users/@me/mfa/codes.ts index 33053028..32f32772 100644 --- a/src/api/routes/v9/users/@me/mfa/codes.ts +++ b/src/api/routes/v9/users/@me/mfa/codes.ts @@ -33,7 +33,7 @@ router.post( }); } - var codes: BackupCode[]; + let codes: BackupCode[]; if (regenerate) { await BackupCode.update( { user: { id: req.user_id } }, diff --git a/src/api/routes/v9/users/@me/relationships.ts b/src/api/routes/v9/users/@me/relationships.ts index 3eec704b..6b5d429c 100644 --- a/src/api/routes/v9/users/@me/relationships.ts +++ b/src/api/routes/v9/users/@me/relationships.ts @@ -157,7 +157,7 @@ async function updateRelationship( select: userProjection, }); - var relationship = user.relationships.find((x) => x.to_id === id); + let relationship = user.relationships.find((x) => x.to_id === id); const friendRequest = friend.relationships.find( (x) => x.to_id === req.user_id, ); @@ -201,13 +201,13 @@ async function updateRelationship( if (user.relationships.length >= maxFriends) throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends); - var incoming_relationship = Relationship.create({ + let incoming_relationship = Relationship.create({ nickname: undefined, type: RelationshipType.incoming, to: user, from: friend, }); - var outgoing_relationship = Relationship.create({ + let outgoing_relationship = Relationship.create({ nickname: undefined, type: RelationshipType.outgoing, to: friend, diff --git a/src/api/start.ts b/src/api/start.ts index 495f4438..d219ac31 100644 --- a/src/api/start.ts +++ b/src/api/start.ts @@ -8,7 +8,7 @@ config(); import { FosscordServer } from "./Server"; import cluster from "cluster"; import os from "os"; -var cores = 1; +let cores = 1; try { cores = Number(process.env.THREADS) || os.cpus().length; } catch { @@ -28,7 +28,7 @@ if (cluster.isPrimary && process.env.NODE_ENV == "production") { cluster.fork(); }); } else { - var port = Number(process.env.PORT) || 3001; + let port = Number(process.env.PORT) || 3001; const server = new FosscordServer({ port }); server.start().catch(console.error); diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 93dc3bf4..0d8c52b2 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -126,11 +126,11 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { throw new HTTPError("Empty messages are not allowed", 50006); } - var content = opts.content; - var mention_channel_ids = [] as string[]; - var mention_role_ids = [] as string[]; - var mention_user_ids = [] as string[]; - var mention_everyone = false; + let content = opts.content; + let mention_channel_ids = [] as string[]; + let mention_role_ids = [] as string[]; + let mention_user_ids = [] as string[]; + let mention_everyone = false; if (content) { // TODO: explicit-only mentions @@ -181,7 +181,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { // TODO: cache link result in db export async function postHandleMessage(message: Message) { const content = message.content?.replace(/ *\`[^)]*\` */g, ""); // remove markdown - var links = content?.match(LINK_REGEX); + let links = content?.match(LINK_REGEX); if (!links) return; const data = { ...message }; @@ -214,8 +214,8 @@ export async function postHandleMessage(message: Message) { // tried to use shorthand but types didn't like me L if (!Array.isArray(res)) res = [res]; - for (var embed of res) { - var cache = EmbedCache.create({ + for (let embed of res) { + let cache = EmbedCache.create({ url: link, embed: embed, }); diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts index 5dcae953..a8911613 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts @@ -43,7 +43,7 @@ export interface RouteOptions { } export function route(opts: RouteOptions) { - var validate: AnyValidateFunction<any> | undefined; + let validate: AnyValidateFunction<any> | undefined; if (opts.body) { validate = ajv.getSchema(opts.body); if (!validate) throw new Error(`Body schema ${opts.body} not found`); diff --git a/src/api/util/utility/passwordStrength.ts b/src/api/util/utility/passwordStrength.ts index 35c55999..8eafd0c3 100644 --- a/src/api/util/utility/passwordStrength.ts +++ b/src/api/util/utility/passwordStrength.ts @@ -20,7 +20,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored export function checkPassword(password: string): number { const { minLength, minNumbers, minUpperCase, minSymbols } = Config.get().register.password; - var strength = 0; + let strength = 0; // checks for total password len if (password.length >= minLength - 1) { diff --git a/src/bundle/stats.ts b/src/bundle/stats.ts index 3a9b2d85..38131d83 100644 --- a/src/bundle/stats.ts +++ b/src/bundle/stats.ts @@ -28,7 +28,7 @@ export function initStats() { // osu.mem.info(), // osu.netstat.inOut(), // ]); - // var networkUsage = ""; + // let networkUsage = ""; // if (typeof network === "object") { // networkUsage = `| [Network]: in ${network.total.inputMb}mb | out ${network.total.outputMb}mb`; // } diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts index 72c7da03..c4e654f9 100644 --- a/src/cdn/routes/attachments.ts +++ b/src/cdn/routes/attachments.ts @@ -35,8 +35,8 @@ router.post( Config.get()?.cdn.endpointPublic || "http://localhost:3003"; await storage.set(path, buffer); - var width; - var height; + let width; + let height; if (mimetype.includes("image")) { const dimensions = imageSize(buffer); if (dimensions) { diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts index 50a76d4b..ce3f2c52 100644 --- a/src/cdn/routes/avatars.ts +++ b/src/cdn/routes/avatars.ts @@ -33,7 +33,7 @@ router.post( const { buffer, mimetype, size, originalname, fieldname } = req.file; const { user_id } = req.params; - var hash = crypto + let hash = crypto .createHash("md5") .update(Snowflake.generate()) .digest("hex"); @@ -59,7 +59,7 @@ router.post( ); router.get("/:user_id", async (req: Request, res: Response) => { - var { user_id } = req.params; + let { user_id } = req.params; user_id = user_id.split(".")[0]; // remove .file extension const path = `avatars/${user_id}`; @@ -74,7 +74,7 @@ router.get("/:user_id", async (req: Request, res: Response) => { }); export const getAvatar = async (req: Request, res: Response) => { - var { user_id, hash } = req.params; + let { user_id, hash } = req.params; hash = hash.split(".")[0]; // remove .file extension const path = `avatars/${user_id}/${hash}`; diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index bdfa0355..cf3cc5d5 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -33,7 +33,7 @@ router.post( const { buffer, mimetype, size, originalname, fieldname } = req.file; const { role_id } = req.params; - var hash = crypto + let hash = crypto .createHash("md5") .update(Snowflake.generate()) .digest("hex"); @@ -58,7 +58,7 @@ router.post( ); router.get("/:role_id", async (req: Request, res: Response) => { - var { role_id } = req.params; + let { role_id } = req.params; //role_id = role_id.split(".")[0]; // remove .file extension const path = `role-icons/${role_id}`; @@ -73,7 +73,7 @@ router.get("/:role_id", async (req: Request, res: Response) => { }); router.get("/:role_id/:hash", async (req: Request, res: Response) => { - var { role_id, hash } = req.params; + let { role_id, hash } = req.params; //hash = hash.split(".")[0]; // remove .file extension const path = `role-icons/${role_id}/${hash}`; diff --git a/src/cdn/util/FileStorage.ts b/src/cdn/util/FileStorage.ts index e8d499e2..3ef2553f 100644 --- a/src/cdn/util/FileStorage.ts +++ b/src/cdn/util/FileStorage.ts @@ -10,7 +10,7 @@ import ExifTransformer from "exif-be-gone"; function getPath(path: string) { // STORAGE_LOCATION has a default value in start.ts const root = process.env.STORAGE_LOCATION || "../"; - var filename = join(root, path); + let filename = join(root, path); if (path.indexOf("\0") !== -1 || !filename.startsWith(root)) throw new Error("invalid path"); diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts index fff5aacf..c82608ce 100644 --- a/src/gateway/events/Connection.ts +++ b/src/gateway/events/Connection.ts @@ -9,7 +9,7 @@ import { Message } from "./Message"; import { Deflate, Inflate } from "fast-zlib"; import { URL } from "url"; import { Config } from "@fosscord/util"; -var erlpack: any; +let erlpack: any; try { erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts index 605bb366..d9a21cf9 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts @@ -9,14 +9,14 @@ import path from "path"; import fs from "fs/promises"; const bigIntJson = BigIntJson({ storeAsString: true }); -var erlpack: any; +let erlpack: any; try { erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} export async function Message(this: WebSocket, buffer: WS.Data) { // TODO: compression - var data: Payload; + let data: Payload; if ( (buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON @@ -82,7 +82,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) { : undefined; try { - var ret = await OPCodeHandler.call(this, data); + let ret = await OPCodeHandler.call(this, data); Sentry.withScope((scope) => { scope.setSpan(transaction); scope.setUser({ id: this.user_id }); diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 1c3cab28..2b1bfc3f 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -49,7 +49,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { try { const { jwtSecret } = Config.get().security; - var { decoded } = await checkToken(identify.token, jwtSecret); // will throw an error if invalid + let { decoded } = await checkToken(identify.token, jwtSecret); // will throw an error if invalid } catch (error) { console.error("invalid token", error); return this.close(CLOSECODES.Authentication_failed); @@ -127,7 +127,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { return this.close(CLOSECODES.Invalid_shard); } } - var users: PublicUser[] = []; + let users: PublicUser[] = []; const merged_members = members.map((x: Member) => { return [ @@ -145,7 +145,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { guilds = guilds.map((guild) => { if (user.bot) { setTimeout(() => { - var promise = Send(this, { + let promise = Send(this, { op: OPCODES.Dispatch, t: EVENTEnum.GuildCreate, s: this.sequence++, diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts index a3bac6e9..9a449abe 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts @@ -108,7 +108,7 @@ async function getMembers(guild_id: string, range: [number, number]) { (a.activities.length - b.activities.length) * 2 ); }); - var session: Session | undefined = sessions.first(); + let session: Session | undefined = sessions.first(); if (session?.status == "offline") { session.status = member?.user?.settings?.status || "online"; diff --git a/src/gateway/start.ts b/src/gateway/start.ts index 84de674f..70c9f1a1 100644 --- a/src/gateway/start.ts +++ b/src/gateway/start.ts @@ -6,7 +6,7 @@ import { Server } from "./Server"; import { config } from "dotenv"; config(); -var port = Number(process.env.PORT); +let port = Number(process.env.PORT); if (isNaN(port)) port = 3002; const server = new Server({ diff --git a/src/gateway/util/Send.ts b/src/gateway/util/Send.ts index c31233c8..7b973313 100644 --- a/src/gateway/util/Send.ts +++ b/src/gateway/util/Send.ts @@ -1,4 +1,4 @@ -var erlpack: any; +let erlpack: any; try { erlpack = require("@yukikaze-bot/erlpack"); } catch (error) { diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 23f2ea55..4dbefcea 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -201,7 +201,7 @@ export class Channel extends BaseClass { !guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") && channel.name ) { - for (var character of InvisibleCharacters) + for (let character of InvisibleCharacters) if (channel.name.includes(character)) throw new HTTPError( "Channel name cannot include invalid characters", diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index 7f3536fa..44c137ff 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -355,9 +355,9 @@ export class Guild extends BaseClass { for (const channel of body.channels?.sort((a, b) => a.parent_id ? 1 : -1, )) { - var id = ids.get(channel.id) || Snowflake.generate(); + let id = ids.get(channel.id) || Snowflake.generate(); - var parent_id = ids.get(channel.parent_id); + let parent_id = ids.get(channel.parent_id); await Channel.createChannel( { ...channel, guild_id, id, parent_id }, diff --git a/src/util/util/AutoUpdate.ts b/src/util/util/AutoUpdate.ts index 6fbad63e..9bc94d7a 100644 --- a/src/util/util/AutoUpdate.ts +++ b/src/util/util/AutoUpdate.ts @@ -18,7 +18,7 @@ export function enableAutoUpdate(opts: { downloadType?: "zip"; }) { if (!opts.checkInterval) return; - var interval = 1000 * 60 * 60 * 24; + let interval = 1000 * 60 * 60 * 24; if (typeof opts.checkInterval === "number") opts.checkInterval = 1000 * interval; diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts index 149f3746..4a6d66df 100644 --- a/src/util/util/Config.ts +++ b/src/util/util/Config.ts @@ -6,8 +6,8 @@ import { ConfigValue } from "../config"; // TODO: yaml instead of json const overridePath = process.env.CONFIG_PATH ?? ""; -var config: ConfigValue; -var pairs: ConfigEntity[]; +let config: ConfigValue; +let pairs: ConfigEntity[]; // TODO: use events to inform about config updates // Config keys are separated with _ @@ -89,7 +89,7 @@ function applyConfig(val: ConfigValue) { } function pairsToConfig(pairs: ConfigEntity[]) { - var value: any = {}; + let value: any = {}; pairs.forEach((p) => { const keys = p.key.split("_"); diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts index 2089d453..a1d78cf0 100644 --- a/src/util/util/Database.ts +++ b/src/util/util/Database.ts @@ -7,7 +7,7 @@ import path from "path"; // UUID extension option is only supported with postgres // We want to generate all id's with Snowflakes that's why we have our own BaseEntity class -var dbConnection: DataSource | undefined; +let dbConnection: DataSource | undefined; // For typeorm cli if (!process.env) { diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts index 0c12487e..de7193c3 100644 --- a/src/util/util/Permissions.ts +++ b/src/util/util/Permissions.ts @@ -11,7 +11,7 @@ import { BitField } from "./BitField"; import "missing-native-js-functions"; import { BitFieldResolvable, BitFlag } from "./BitField"; -var HTTPError: any; +let HTTPError: any; try { HTTPError = require("lambert-server").HTTPError; @@ -242,9 +242,9 @@ export async function getPermission( } = {}, ) { if (!user_id) throw new HTTPError("User not found"); - var channel: Channel | undefined; - var member: Member | undefined; - var guild: Guild | undefined; + let channel: Channel | undefined; + let member: Member | undefined; + let guild: Guild | undefined; if (channel_id) { channel = await Channel.findOneOrFail({ @@ -293,7 +293,7 @@ export async function getPermission( if (!recipient_ids?.length) recipient_ids = null; // TODO: remove guild.roles and convert recipient_ids to recipients - var permission = Permissions.finalPermission({ + let permission = Permissions.finalPermission({ user: { id: user_id, roles: member?.roles.map((x) => x.id) || [], diff --git a/src/util/util/Rights.ts b/src/util/util/Rights.ts index 68a7c840..a23a15c2 100644 --- a/src/util/util/Rights.ts +++ b/src/util/util/Rights.ts @@ -3,7 +3,7 @@ import "missing-native-js-functions"; import { BitFieldResolvable, BitFlag } from "./BitField"; import { User } from "../entities"; -var HTTPError: any; +let HTTPError: any; try { HTTPError = require("lambert-server").HTTPError; diff --git a/src/util/util/Snowflake.ts b/src/util/util/Snowflake.ts index 69effb2e..d380f889 100644 --- a/src/util/util/Snowflake.ts +++ b/src/util/util/Snowflake.ts @@ -87,10 +87,10 @@ export class Snowflake { static generateWorkerProcess() { // worker process - returns a number - var time = BigInt(Date.now() - Snowflake.EPOCH) << BigInt(22); - var worker = Snowflake.workerId << 17n; - var process = Snowflake.processId << 12n; - var increment = Snowflake.INCREMENT++; + let time = BigInt(Date.now() - Snowflake.EPOCH) << BigInt(22); + let worker = Snowflake.workerId << 17n; + let process = Snowflake.processId << 12n; + let increment = Snowflake.INCREMENT++; return BigInt(time | worker | process | increment); } diff --git a/src/webrtc/events/Connection.ts b/src/webrtc/events/Connection.ts index 9300b6b2..210b8b07 100644 --- a/src/webrtc/events/Connection.ts +++ b/src/webrtc/events/Connection.ts @@ -5,7 +5,7 @@ import WS from "ws"; import { VoiceOPCodes } from "../util"; import { onClose } from "./Close"; import { onMessage } from "./Message"; -var erlpack: any; +let erlpack: any; try { erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} diff --git a/src/webrtc/events/Message.ts b/src/webrtc/events/Message.ts index 38676f6c..862710bf 100644 --- a/src/webrtc/events/Message.ts +++ b/src/webrtc/events/Message.ts @@ -12,7 +12,7 @@ const PayloadSchema = { export async function onMessage(this: WebSocket, buffer: Buffer) { try { - var data: Payload = JSON.parse(buffer.toString()); + let data: Payload = JSON.parse(buffer.toString()); if (data.op !== VoiceOPCodes.IDENTIFY && !this.user_id) return this.close(CLOSECODES.Not_authenticated); diff --git a/src/webrtc/opcodes/Video.ts b/src/webrtc/opcodes/Video.ts index dcbc9aa0..87d1b57c 100644 --- a/src/webrtc/opcodes/Video.ts +++ b/src/webrtc/opcodes/Video.ts @@ -14,7 +14,7 @@ export async function onVideo(this: WebSocket, payload: Payload) { const id = "stream" + this.user_id; - var stream = this.client.in.stream!; + let stream = this.client.in.stream!; if (!stream) { stream = this.client.transport!.createIncomingStream( // @ts-ignore @@ -88,7 +88,7 @@ function attachTrack( ); outTrack.attachTo(track); this.client.out.stream!.addTrack(outTrack); - var ssrcs = this.client.out.tracks.get(user_id)!; + let ssrcs = this.client.out.tracks.get(user_id)!; if (!ssrcs) ssrcs = this.client.out.tracks .set(user_id, { audio_ssrc: 0, rtx_ssrc: 0, video_ssrc: 0 }) @@ -116,7 +116,7 @@ function handleSSRC(this: WebSocket, type: "audio" | "video", ssrcs: SSRCs) { const transport = this.client.transport!; const id = type + ssrcs.media; - var track = stream.getTrack(id); + let track = stream.getTrack(id); if (!track) { console.log("createIncomingStreamTrack", id); track = transport.createIncomingStreamTrack(type, { id, ssrcs }); diff --git a/src/webrtc/util/MediaServer.ts b/src/webrtc/util/MediaServer.ts index 520b8682..3c6283a7 100644 --- a/src/webrtc/util/MediaServer.ts +++ b/src/webrtc/util/MediaServer.ts @@ -11,7 +11,7 @@ export const PublicIP = process.env.PUBLIC_IP || "127.0.0.1"; try { const range = process.env.WEBRTC_PORT_RANGE || "4000"; - var ports = range.split("-"); + let ports = range.split("-"); const min = Number(ports[0]); const max = Number(ports[1]); |