From 23468b1b77e68b171b53c6b6763fcb7f9fc7eb75 Mon Sep 17 00:00:00 2001 From: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:33:31 +0300 Subject: [PATCH 1/5] Squashed commit of the following: commit e587b8f81f366b175a042ef1eb96e44bc8807570 Author: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Tue Sep 21 19:19:57 2021 +0300 Create guild_experiments.example.json commit 9cb03c85618d62e3501146e96539e2c0c79416a3 Author: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Tue Sep 21 22:32:07 2021 +0300 Update Identify.ts commit 3b0e0bb116841c460f41b7429a59a577f61e3863 Author: BanTheNons <59115290+BanTheNons@users.noreply.github.com> Date: Tue Sep 21 16:56:14 2021 +0300 implemented guild experiments commit 489af5182d8c69f46b468f010480c88565fbb42f Author: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Tue Sep 21 22:26:53 2021 +0300 Update .gitignore --- api/src/routes/experiments.json | 4 + api/src/routes/experiments.ts | 6 +- api/tsconfig.json | 1 + gateway/.gitignore | 5 +- gateway/package-lock.json | 11 ++ gateway/package.json | 1 + gateway/src/opcodes/Identify.ts | 12 +- gateway/src/opcodes/experiments.json | 77 +-------- .../opcodes/guild_experiments.example.json | 43 +++++ gateway/src/opcodes/guild_experiments.json | 43 +++++ gateway/src/util/Experiments.ts | 156 ++++++++++++++++++ 11 files changed, 277 insertions(+), 82 deletions(-) create mode 100644 api/src/routes/experiments.json create mode 100644 gateway/src/opcodes/guild_experiments.example.json create mode 100644 gateway/src/opcodes/guild_experiments.json create mode 100644 gateway/src/util/Experiments.ts diff --git a/api/src/routes/experiments.json b/api/src/routes/experiments.json new file mode 100644 index 000000000..a321d43fa --- /dev/null +++ b/api/src/routes/experiments.json @@ -0,0 +1,4 @@ +{ + "experiments": {"fingerprint": "889800254663311382.rgUouuEkLbQi0SGiEMClnfgNZic", "assignments": [[4047587481, 0, 0, -1, 0], [1865079242, 0, 1, -1, 0], [3816091942, 3, 0, -1, 0], [4130837190, 0, 10, -1, 0], [1861568052, 0, 1, -1, 0], [1578940118, 1, 1, -1, 0], [1571676964, 0, 1, -1, 2], [1658164312, 2, 1, -1, 0], [98883956, 1, 1, -1, 0], [3114091169, 0, 1, -1, 0], [2570684145, 4, 1, -1, 2], [4007615411, 0, 1, -1, 0], [852550504, 3, 1, -1, 0], [4168223991, 0, 1, -1, 0], [478613943, 2, 1, -1, 1], [284670956, 0, 1, -1, 0], [2099185390, 0, 1, -1, 0], [1202202685, 0, 1, -1, 0], [3633864632, 0, 1, -1, 0], [3103053065, 0, 1, -1, 0], [820624960, 0, 1, -1, 0], [2599708267, 0, 1, -1, 0], [2885186814, 0, 1, -1, 0], [221503477, 0, 1, -1, 0], [1054317075, 0, 1, -1, 3], [683872522, 0, 1, -1, 1], [1739278764, 0, 2, -1, 0], [2855249023, 0, 1, -1, 0], [3721841948, 0, 1, -1, 0], [1365487849, 6, 1, -1, 0], [955229746, 0, 1, -1, 0], [3128009767, 0, 10, -1, 0], [441885003, 0, 1, -1, 0], [3433971238, 0, 1, -1, 2], [1038765354, 3, 1, -1, 0], [2973729510, 2, 1, -1, 0], [3884442008, 0, 1, -1, 0], [978673395, 1, 1, -1, 0], [4050927174, 0, 1, -1, 0], [1260103069, 0, 1, -1, 0], [4168894280, 0, 1, -1, 0], [2003494159, 1, 1, -1, 0], [2458926251, 1, 6, -1, 2], [4027800, 1, 6, -1, 3], [51193042, 0, 1, -1, 0], [2063302207, 1, 6, -1, 4], [2634540382, 3, 1, -1, 0], [886364171, 0, 1, -1, 0], [427713714, 0, 1, -1, 0], [3388129398, 0, 1, -1, 0], [446728522, 0, 1, -1, 0], [3305874255, 0, 1, -1, 0], [3316720711, 0, 1, -1, 0], [1126477623, 0, 1, -1, 0], [2617218444, 4, 1, -1, 2], [3615263239, 0, 1, -1, 0], [3035674767, 0, 1, -1, 0], [261678880, 0, 1, -1, 0], [144783748, 0, 1, -1, 0], [2898830675, 0, 1, -1, 0], [2311413706, 0, 1, -1, 0], [1304635016, 0, 1, -1, 0], [3840356350, 4, 1, -1, 0], [1047093347, 0, 1, -1, 2], [3354177721, 0, 1, -1, 0], [3643362751, 0, 1, -1, 0], [698017395, 0, 1, -1, 0], [902020832, 3, 3, -1, 1], [2165627712, 2, 1, -1, 0], [3346844407, 0, 1, -1, 0], [3753034466, 1, 2, -1, 0], [881221695, 1, 1, -1, 0], [2144100145, 0, 1, -1, 0], [3749399219, 0, 0, -1, 0], [55060776, 1, 2, -1, 0], [3125584553, 1, 1, -1, 0], [2906015343, 2, 0, -1, 0], [219203323, 1, 1, -1, 0], [2854861606, 0, 1, -1, 1], [3884403666, 1, 1, -1, 0], [1041569008, 0, 1, -1, 0], [2780619238, 1, 1, -1, 0], [2839301427, 1, 1, -1, 0], [2481496956, 0, 1, -1, 0], [1305004983, 0, 1, -1, 0], [126562871, 2, 2, -1, 0], [3296195750, 0, 0, -1, 0]]}, + "with_guild_experiments": {"fingerprint": "889800328839561216.vZ4Xe0ZSjeF7pcyqPJRxRP6lsFQ", "assignments": [[4047587481, 0, 0, -1, 0], [1865079242, 0, 1, -1, 0], [3816091942, 3, 0, -1, 0], [4130837190, 0, 10, -1, 0], [1861568052, 0, 1, -1, 0], [1578940118, 1, 1, -1, 0], [1571676964, 0, 1, -1, 2], [1658164312, 2, 1, -1, 0], [98883956, 1, 1, -1, 0], [3114091169, 0, 1, -1, 0], [2570684145, 4, 1, -1, 2], [4007615411, 0, 1, -1, 0], [852550504, 3, 1, -1, 0], [4168223991, 0, 1, -1, 0], [478613943, 2, 1, -1, 1], [284670956, 0, 1, -1, 0], [2099185390, 0, 1, -1, 0], [1202202685, 0, 1, -1, 0], [3633864632, 0, 1, -1, 0], [3103053065, 0, 1, -1, 0], [820624960, 0, 1, -1, 0], [2599708267, 0, 1, -1, 0], [2885186814, 0, 1, -1, 0], [221503477, 0, 1, -1, 0], [1054317075, 0, 1, -1, 3], [683872522, 0, 1, -1, 1], [1739278764, 0, 2, -1, 0], [2855249023, 0, 1, -1, 0], [3721841948, 0, 1, -1, 0], [1365487849, 6, 1, -1, 0], [955229746, 0, 1, -1, 0], [3128009767, 0, 10, -1, 0], [441885003, 0, 1, -1, 0], [3433971238, 0, 1, -1, 2], [1038765354, 3, 1, -1, 0], [2973729510, 2, 1, -1, 0], [3884442008, 0, 1, -1, 0], [978673395, 1, 1, -1, 0], [4050927174, 0, 1, -1, 0], [1260103069, 0, 1, -1, 0], [4168894280, 0, 1, -1, 0], [2003494159, 1, 1, -1, 0], [2458926251, 1, 6, -1, 2], [4027800, 1, 6, -1, 3], [51193042, 0, 1, -1, 0], [2063302207, 1, 6, -1, 4], [2634540382, 3, 1, -1, 0], [886364171, 0, 1, -1, 0], [427713714, 0, 1, -1, 0], [3388129398, 0, 1, -1, 0], [446728522, 0, 1, -1, 0], [3305874255, 0, 1, -1, 0], [3316720711, 0, 1, -1, 0], [1126477623, 0, 1, -1, 0], [2617218444, 4, 1, -1, 2], [3615263239, 0, 1, -1, 0], [3035674767, 0, 1, -1, 0], [261678880, 0, 1, -1, 0], [144783748, 0, 1, -1, 0], [2898830675, 0, 1, -1, 0], [2311413706, 0, 1, -1, 0], [1304635016, 0, 1, -1, 0], [3840356350, 4, 1, -1, 0], [1047093347, 0, 1, -1, 2], [3354177721, 0, 1, -1, 0], [3643362751, 0, 1, -1, 0], [698017395, 0, 1, -1, 0], [902020832, 3, 3, -1, 1], [2165627712, 2, 1, -1, 0], [3346844407, 0, 1, -1, 0], [3753034466, 1, 2, -1, 0], [881221695, 1, 1, -1, 0], [2144100145, 0, 1, -1, 0], [3749399219, 0, 1, -1, 0], [55060776, 1, 2, -1, 0], [3125584553, 1, 1, -1, 0], [2906015343, 2, 0, -1, 0], [219203323, 1, 1, -1, 0], [2854861606, 0, 1, -1, 1], [3884403666, 1, 1, -1, 0], [1041569008, 0, 1, -1, 0], [2780619238, 1, 2, -1, 0], [2839301427, 1, 1, -1, 0], [2481496956, 0, 1, -1, 0], [1305004983, 0, 1, -1, 0], [2735830691, 0, 1, -1, 0], [206611123, 0, 1, -1, 0], [126562871, 2, 0, -1, 0], [3296195750, 0, 1, -1, 0]]} +} \ No newline at end of file diff --git a/api/src/routes/experiments.ts b/api/src/routes/experiments.ts index 966ed99c2..95bbab79a 100644 --- a/api/src/routes/experiments.ts +++ b/api/src/routes/experiments.ts @@ -1,11 +1,13 @@ import { Router, Response, Request } from "express"; import { route } from "@fosscord/api"; +import { experiments, with_guild_experiments } from "./experiments.json"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - // TODO: - res.send({ fingerprint: "", assignments: [] }); + console.log(req.params) + if (req.url.includes("with_guild_experiments=true")) return res.json(with_guild_experiments); + else return res.json(experiments); }); export default router; diff --git a/api/tsconfig.json b/api/tsconfig.json index 21a8eb96b..981c46ffd 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -62,6 +62,7 @@ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ /* Advanced Options */ + "resolveJsonModule": true, "skipLibCheck": true /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, "baseUrl": ".", diff --git a/gateway/.gitignore b/gateway/.gitignore index daf8591a1..ada60519f 100644 --- a/gateway/.gitignore +++ b/gateway/.gitignore @@ -104,4 +104,7 @@ dist .tern-port .DS_Store -data \ No newline at end of file +data + +# Guild experiments +src/opcodes/guild_experiments.json \ No newline at end of file diff --git a/gateway/package-lock.json b/gateway/package-lock.json index ae6009dbd..a1b0b83a8 100644 --- a/gateway/package-lock.json +++ b/gateway/package-lock.json @@ -17,6 +17,7 @@ "lambert-server": "^1.2.8", "missing-native-js-functions": "^1.2.15", "mongoose-autopopulate": "^0.12.3", + "murmurhash": "^2.0.0", "node-fetch": "^2.6.1", "typeorm": "^0.2.37", "uuid": "^8.3.2", @@ -1553,6 +1554,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "node_modules/murmurhash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/murmurhash/-/murmurhash-2.0.0.tgz", + "integrity": "sha512-Uo7ZHw+PLe2Q8/qbPIVYxAaoi+TYGZwu1a8ryeeASRXJLRSaLCblAGfjh02eu4+/9aUJBpkHXZv42AXmzOW2kw==" + }, "node_modules/mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", @@ -3787,6 +3793,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "murmurhash": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/murmurhash/-/murmurhash-2.0.0.tgz", + "integrity": "sha512-Uo7ZHw+PLe2Q8/qbPIVYxAaoi+TYGZwu1a8ryeeASRXJLRSaLCblAGfjh02eu4+/9aUJBpkHXZv42AXmzOW2kw==" + }, "mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", diff --git a/gateway/package.json b/gateway/package.json index 6b9e27d6f..136801ef9 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -34,6 +34,7 @@ "lambert-server": "^1.2.8", "missing-native-js-functions": "^1.2.15", "mongoose-autopopulate": "^0.12.3", + "murmurhash": "^2.0.0", "node-fetch": "^2.6.1", "typeorm": "^0.2.37", "uuid": "^8.3.2", diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index d91cd7f2b..8a38baa74 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -20,12 +20,18 @@ import { import { setupListener } from "../listener/listener"; import { IdentifySchema } from "../schema/Identify"; import { Send } from "@fosscord/gateway/util/Send"; -// import experiments from "./experiments.json"; -const experiments: any = []; +import experiments from "./experiments.json"; +import guildExperiments from "./guild_experiments.json"; import { check } from "./instanceOf"; +import { encodeGuildExperiment } from "../util/Experiments"; import { Recipient } from "@fosscord/util"; import { genSessionId } from "@fosscord/gateway/util/SessionUtils"; +let guild_experiments: any = []; +if (guildExperiments.length) guildExperiments.forEach((experiment, index) => { + guild_experiments[index] = encodeGuildExperiment(experiment) as any; +}); + // TODO: bot sharding // TODO: check priviliged intents // TODO: check if already identified @@ -173,7 +179,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { x.threads = []; return x; }), - guild_experiments: [], // TODO + guild_experiments, // TODO geo_ordered_rtc_regions: [], // TODO relationships: user.relationships.map((x) => x.toPublicRelationship()), read_state: { diff --git a/gateway/src/opcodes/experiments.json b/gateway/src/opcodes/experiments.json index 0370b5da9..b7350ef5c 100644 --- a/gateway/src/opcodes/experiments.json +++ b/gateway/src/opcodes/experiments.json @@ -1,76 +1 @@ -[ - [4047587481, 0, 0, -1, 0], - [1509401575, 0, 1, -1, 0], - [1865079242, 0, 1, -1, 0], - [1962538549, 1, 0, -1, 0], - [3816091942, 3, 2, -1, 0], - [4130837190, 0, 10, -1, 0], - [1861568052, 0, 1, -1, 0], - [2290910058, 6, 2, -1, 0], - [1578940118, 1, 1, -1, 0], - [1571676964, 0, 1, -1, 2], - [3640172371, 0, 2, -1, 2], - [1658164312, 2, 1, -1, 0], - [98883956, 1, 1, -1, 0], - [3114091169, 0, 1, -1, 0], - [2570684145, 4, 1, -1, 2], - [4007615411, 0, 1, -1, 0], - [3665310159, 2, 1, -1, 1], - [852550504, 3, 1, -1, 0], - [2333572067, 0, 1, -1, 0], - [935994771, 1, 1, -1, 0], - [1127795596, 1, 1, -1, 0], - [4168223991, 0, 1, -1, 0], - [18585280, 0, 1, -1, 1], - [327482016, 0, 1, -1, 2], - [3458098201, 7, 1, -1, 0], - [478613943, 2, 1, -1, 1], - [2792197902, 0, 1, -1, 2], - [284670956, 0, 1, -1, 0], - [2099185390, 0, 1, -1, 0], - [1202202685, 0, 1, -1, 0], - [2122174751, 0, 1, -1, 0], - [3633864632, 0, 1, -1, 0], - [3103053065, 0, 1, -1, 0], - [820624960, 0, 1, -1, 0], - [1134479292, 0, 1, -1, 0], - [2511257455, 3, 1, -1, 3], - [2599708267, 0, 1, -1, 0], - [613180822, 1, 1, -1, 0], - [2885186814, 0, 1, -1, 0], - [221503477, 0, 1, -1, 0], - [1054317075, 0, 1, -1, 3], - [683872522, 0, 1, -1, 1], - [1739278764, 0, 2, -1, 0], - [2855249023, 0, 1, -1, 0], - [3721841948, 0, 1, -1, 0], - [1285203515, 0, 1, -1, 0], - [1365487849, 6, 1, -1, 0], - [955229746, 0, 1, -1, 0], - [3128009767, 0, 10, -1, 0], - [441885003, 0, 1, -1, 0], - [3433971238, 0, 1, -1, 2], - [1038765354, 3, 1, -1, 0], - [1174347196, 0, 1, -1, 0], - [3649806352, 1, 1, -1, 0], - [2973729510, 2, 1, -1, 0], - [2571931329, 1, 6, -1, 0], - [3884442008, 0, 1, -1, 0], - [978673395, 1, 1, -1, 0], - [4050927174, 0, 1, -1, 0], - [1260103069, 0, 1, -1, 0], - [4168894280, 0, 1, -1, 0], - [4045587091, 0, 1, -1, 0], - [2003494159, 1, 1, -1, 0], - [51193042, 0, 1, -1, 0], - [2634540382, 3, 1, -1, 0], - [886364171, 0, 1, -1, 0], - [3898604944, 0, 1, -1, 0], - [3388129398, 0, 1, -1, 0], - [3964382884, 2, 1, -1, 1], - [3305874255, 0, 1, -1, 0], - [156590431, 0, 1, -1, 0], - [3106485751, 0, 0, -1, 0], - [3035674767, 0, 1, -1, 0], - [851697110, 0, 1, -1, 0] -] +[[4047587481, 0, 0, -1, 0], [1865079242, 0, 1, -1, 0], [3816091942, 3, 0, -1, 0], [4130837190, 0, 10, -1, 0], [1861568052, 0, 1, -1, 0], [1578940118, 1, 1, -1, 0], [1571676964, 0, 1, -1, 2], [1658164312, 2, 1, -1, 0], [98883956, 1, 1, -1, 0], [3114091169, 0, 1, -1, 0], [2570684145, 4, 1, -1, 2], [4007615411, 0, 1, -1, 0], [852550504, 3, 1, -1, 0], [4168223991, 0, 1, -1, 0], [478613943, 2, 1, -1, 1], [284670956, 0, 1, -1, 0], [2099185390, 0, 1, -1, 0], [1202202685, 0, 1, -1, 0], [3633864632, 0, 1, -1, 0], [3103053065, 0, 1, -1, 0], [820624960, 0, 1, -1, 0], [2599708267, 0, 1, -1, 0], [2885186814, 0, 1, -1, 0], [221503477, 0, 1, -1, 0], [1054317075, 0, 1, -1, 3], [683872522, 0, 1, -1, 1], [1739278764, 0, 2, -1, 0], [2855249023, 0, 1, -1, 0], [3721841948, 0, 1, -1, 0], [1365487849, 6, 1, -1, 0], [955229746, 0, 1, -1, 0], [3128009767, 0, 10, -1, 0], [441885003, 0, 1, -1, 0], [3433971238, 0, 1, -1, 2], [1038765354, 3, 1, -1, 0], [2973729510, 2, 1, -1, 0], [3884442008, 0, 1, -1, 0], [978673395, 1, 1, -1, 0], [4050927174, 0, 1, -1, 0], [1260103069, 0, 1, -1, 0], [4168894280, 0, 1, -1, 0], [2003494159, 1, 1, -1, 0], [2458926251, 1, 6, -1, 2], [4027800, 1, 6, -1, 3], [51193042, 0, 1, -1, 0], [2063302207, 1, 6, -1, 4], [2634540382, 3, 1, -1, 0], [886364171, 0, 1, -1, 0], [427713714, 0, 1, -1, 0], [3388129398, 0, 1, -1, 0], [446728522, 0, 1, -1, 0], [3305874255, 0, 1, -1, 0], [3316720711, 0, 1, -1, 0], [1126477623, 0, 1, -1, 0], [2617218444, 4, 1, -1, 2], [3615263239, 0, 1, -1, 0], [3035674767, 0, 1, -1, 0], [261678880, 0, 1, -1, 0], [144783748, 0, 1, -1, 0], [2898830675, 0, 1, -1, 0], [2311413706, 0, 1, -1, 0], [1304635016, 0, 1, -1, 0], [3840356350, 4, 1, -1, 0], [1047093347, 0, 1, -1, 2], [3354177721, 0, 1, -1, 0], [3643362751, 0, 1, -1, 0], [698017395, 0, 1, -1, 0], [902020832, 3, 3, -1, 1], [2165627712, 2, 1, -1, 0], [3346844407, 0, 1, -1, 0], [3753034466, 1, 2, -1, 0], [881221695, 1, 1, -1, 0], [2144100145, 0, 1, -1, 0], [3749399219, 0, 0, -1, 0], [55060776, 1, 2, -1, 0], [3125584553, 1, 1, -1, 0], [2906015343, 2, 0, -1, 0], [219203323, 1, 1, -1, 0], [2854861606, 0, 1, -1, 1], [3884403666, 1, 1, -1, 0], [1041569008, 0, 1, -1, 0], [2780619238, 1, 1, -1, 0], [2839301427, 1, 1, -1, 0], [2481496956, 0, 1, -1, 0], [1305004983, 0, 1, -1, 0], [126562871, 2, 2, -1, 0], [3296195750, 0, 0, -1, 0]] diff --git a/gateway/src/opcodes/guild_experiments.example.json b/gateway/src/opcodes/guild_experiments.example.json new file mode 100644 index 000000000..0e0d753b6 --- /dev/null +++ b/gateway/src/opcodes/guild_experiments.example.json @@ -0,0 +1,43 @@ +[ + { + "hashKey": 3563379711, + "revision": 0, + "populations": [ + { + "buckets": { + "1": { + "rollout": [ + { + "min": 0, + "max": 1000 + } + ] + }, + "2": { + "rollout": [ + { + "min": 1000, + "max": 10000 + } + ] + } + }, + "filters": [ + { + "type": "guild_ids", + "ids": [ + 1234, + 5678 + ] + } + ] + } + ], + "overrides": { + "2": [ + "203290518795452416" + ] + } + } + +] \ No newline at end of file diff --git a/gateway/src/opcodes/guild_experiments.json b/gateway/src/opcodes/guild_experiments.json new file mode 100644 index 000000000..0e0d753b6 --- /dev/null +++ b/gateway/src/opcodes/guild_experiments.json @@ -0,0 +1,43 @@ +[ + { + "hashKey": 3563379711, + "revision": 0, + "populations": [ + { + "buckets": { + "1": { + "rollout": [ + { + "min": 0, + "max": 1000 + } + ] + }, + "2": { + "rollout": [ + { + "min": 1000, + "max": 10000 + } + ] + } + }, + "filters": [ + { + "type": "guild_ids", + "ids": [ + 1234, + 5678 + ] + } + ] + } + ], + "overrides": { + "2": [ + "203290518795452416" + ] + } + } + +] \ No newline at end of file diff --git a/gateway/src/util/Experiments.ts b/gateway/src/util/Experiments.ts new file mode 100644 index 000000000..67901f52d --- /dev/null +++ b/gateway/src/util/Experiments.ts @@ -0,0 +1,156 @@ +// Code from https://gitlab.com/derpystuff/discord-experiments/-/blob/main/index.js +//@ts-nocheck + +import murmurhash from "murmurhash"; + +export function encodeGuildExperiment(experiment){ + let encodedExperiment = [experiment.hashKey, null, experiment.revision] //Default config + if(experiment.populations){ //Parse Populations + let parsedPopulations = []; + experiment.populations.forEach(function(population){ + let parsedPopulation = []; + let parsedBuckets = []; + Object.keys(population.buckets).forEach(function(bucketId){ //Parse Bucket + let parsedBucket = []; + let bucket = population.buckets[bucketId] + parsedBucket.push(parseInt(bucketId)) + let rollouts = []; + bucket.rollout.forEach(function(rollout){ //Apply rollouts to this bucket + rollouts.push({ + s: rollout.min, + e: rollout.max + }) + }) + parsedBucket.push(rollouts) + parsedBuckets.push(parsedBucket) + }) + parsedPopulation.push(parsedBuckets) + let parsedFilters = []; + population.filters.forEach(function(filter){ //Parse filters + let parsedFilter = []; + //special case + if(filter.type == "unknown_filter"){ + parsedFilter = [filter.hash, filter.data] + } else { + parsedFilter = [murmurhash.v3(filter.type.toLowerCase())] + let filterData = []; + //get the keys + if(filter.guild_features){ // guild_has_feature + filterData.push([murmurhash.v3("guild_features"), filter.guild_features]) + } else if(filter.min_id || filter.max_id){ //guild_id_range guild_member_count_range + filterData.push([murmurhash.v3("min_id"), filter.min_id]) + filterData.push([murmurhash.v3("max_id"), filter.max_id]) + } else if(filter.ids){ //guild_ids + filterData.push([murmurhash.v3("guild_ids"), filter.ids]) + } + parsedFilter.push(filterData) + } + parsedFilters.push(parsedFilter) + }) + parsedPopulation.push(parsedFilters) + parsedPopulations.push(parsedPopulation) + }) + encodedExperiment.push(parsedPopulations) + let parsedOverrides = []; + Object.keys(experiment.overrides).forEach(function(override){ //Parse Overrides + parsedOverrides.push({b: parseInt(override), k: experiment.overrides[override]}) + }) + encodedExperiment.push(parsedOverrides) + return encodedExperiment; + } + } + + export function decodeGuildExperiment(experiment){ //Decodes Experiments + let parsedExperiment = {hashKey: experiment[0], revision: experiment[2], populations:[]}; + let parsedPopulations = [] + experiment[3].forEach(function(population){ + let parsedBuckets = {}; + population[0].forEach(function(bucket){ //Parse Buckets and Filters + parsedBuckets[bucket[0].toString()] = {rollout:[]} + bucket[1].forEach(function(rollout){ + parsedBuckets[bucket[0].toString()].rollout.push({min: rollout.s, max: rollout.e}) + }) + }) + let parsedFilters = [] + population[1].forEach(function(filter){ + //Filters we know + switch(filter[0]){ + case 1604612045: //guild_has_feature + parse = { + type: "guild_has_feature" + } + filter[1].forEach(function(filterData){ + if(filterData[0] == 1183251248){ //guild_features + parse.guild_features = filterData[1] + } else { + console.log('[EXPERIMENT] Expected guild_features, got ' + filterData) + } + }) + parsedFilters.push(parse) + break; + case 3013771838: //guild_ids + parse = { + type: "guild_ids" + } + filter[1].forEach(function(filterData){ + if(filterData[0] == 3013771838){ //guild_ids + parse.ids = filterData[1] + } else { + console.log('[EXPERIMENT] Expected guild_ids, got ' + filterData) + } + }) + parsedFilters.push(parse) + break; + case 2404720969: //guild_id_range + parse = { + type: "guild_id_range" + } + filter[1].forEach(function(filterData){ + if(filterData[0] == 3399957344){ //min_id + parse.min_id = filterData[1] + } else if(filterData[0] == 1238858341){ //max_id + parse.max_id = filterData[1] + } else { + console.log('[EXPERIMENT] Expected min_id or max_id, got ' + filterData) + } + }) + parsedFilters.push(parse) + break; + case 2918402255: //guild_member_count_range + parse = { + type: "guild_member_count_range" + } + filter[1].forEach(function(filterData){ + if(filterData[0] == 3399957344){ //min_id + parse.min_id = filterData[1] + } else if(filterData[0] == 1238858341){ //max_id + parse.max_id = filterData[1] + } else { + console.log('[EXPERIMENT] Expected min_id or max_id, got ' + filterData) + } + }) + parsedFilters.push(parse) + break; + default: + parsedFilters.push({ + type: "unknown_filter", + hash: filter[0], + data: filter[1] + }) + break; + } + }) + parsedPopulations.push({ + buckets: parsedBuckets, + filters: parsedFilters + }) + parsedExperiment.populations = parsedPopulations + }) + let parsedOverrides = {}; + experiment[4].forEach(function(override){ //Parse overrides + parsedOverrides[override.b.toString()] = override.k + }) + parsedExperiment.overrides = parsedOverrides + return parsedExperiment; + } + \ No newline at end of file From 445189c6e23ead08fea5167b909ae9580a13a36d Mon Sep 17 00:00:00 2001 From: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:43:24 +0300 Subject: [PATCH 2/5] Update guild_experiments.json --- gateway/src/opcodes/guild_experiments.json | 32 ++++++++-------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/gateway/src/opcodes/guild_experiments.json b/gateway/src/opcodes/guild_experiments.json index 0e0d753b6..a2787ebb4 100644 --- a/gateway/src/opcodes/guild_experiments.json +++ b/gateway/src/opcodes/guild_experiments.json @@ -1,6 +1,12 @@ [ { - "hashKey": 3563379711, + "id":"2021-06_stage_events", + "title": "Stage Events", + "description": [ + "Control", + "Treatment 1: Guild can use Stage Events" + ], + "hashKey": 4150241132, "revision": 0, "populations": [ { @@ -9,14 +15,6 @@ "rollout": [ { "min": 0, - "max": 1000 - } - ] - }, - "2": { - "rollout": [ - { - "min": 1000, "max": 10000 } ] @@ -24,20 +22,14 @@ }, "filters": [ { - "type": "guild_ids", - "ids": [ - 1234, - 5678 + "type": "guild_has_feature", + "guild_features": [ + "PARTNERED" ] } ] } ], - "overrides": { - "2": [ - "203290518795452416" - ] - } + "overrides": {} } - -] \ No newline at end of file +] From e200c7b1967a880b89370d7a18c3d929b5ed9120 Mon Sep 17 00:00:00 2001 From: BuildTools <59115290+BanTheNons@users.noreply.github.com> Date: Wed, 22 Sep 2021 16:55:49 +0300 Subject: [PATCH 3/5] compile json files --- gateway/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/tsconfig.json b/gateway/tsconfig.json index 2530aa41e..63a1b9c7f 100644 --- a/gateway/tsconfig.json +++ b/gateway/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "src/**/*.json"], "exclude": ["*.js", "dist", "attachments"], "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ From e972703c59324c4d79526703d2de16931c0eef62 Mon Sep 17 00:00:00 2001 From: BanTheNons <59115290+BanTheNons@users.noreply.github.com> Date: Tue, 28 Sep 2021 08:00:04 +0300 Subject: [PATCH 4/5] Update experiments.ts --- api/src/routes/experiments.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/routes/experiments.ts b/api/src/routes/experiments.ts index 95bbab79a..d3e6ee74e 100644 --- a/api/src/routes/experiments.ts +++ b/api/src/routes/experiments.ts @@ -5,9 +5,8 @@ import { experiments, with_guild_experiments } from "./experiments.json"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - console.log(req.params) if (req.url.includes("with_guild_experiments=true")) return res.json(with_guild_experiments); - else return res.json(experiments); + return res.json(experiments); }); export default router; From 5a6421f4a5795ebe44967c28a509a15917af0555 Mon Sep 17 00:00:00 2001 From: BanTheNons <59115290+BanTheNons@users.noreply.github.com> Date: Tue, 28 Sep 2021 08:07:48 +0300 Subject: [PATCH 5/5] Delete guild_experiments.json You can just rename guild_experments.example.json and you should be good to go. --- gateway/src/opcodes/guild_experiments.json | 35 ---------------------- 1 file changed, 35 deletions(-) delete mode 100644 gateway/src/opcodes/guild_experiments.json diff --git a/gateway/src/opcodes/guild_experiments.json b/gateway/src/opcodes/guild_experiments.json deleted file mode 100644 index a2787ebb4..000000000 --- a/gateway/src/opcodes/guild_experiments.json +++ /dev/null @@ -1,35 +0,0 @@ -[ - { - "id":"2021-06_stage_events", - "title": "Stage Events", - "description": [ - "Control", - "Treatment 1: Guild can use Stage Events" - ], - "hashKey": 4150241132, - "revision": 0, - "populations": [ - { - "buckets": { - "1": { - "rollout": [ - { - "min": 0, - "max": 10000 - } - ] - } - }, - "filters": [ - { - "type": "guild_has_feature", - "guild_features": [ - "PARTNERED" - ] - } - ] - } - ], - "overrides": {} - } -]