Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord: fetch backwards and add a beginningDate config #3329

Merged
merged 9 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Array [
"bot": false,
"discriminator": "7902",
"id": "664562775770791966",
"username": "BrianBelhumeur",
"username": "Beez",
},
},
Object {
Expand Down Expand Up @@ -288,112 +288,107 @@ Array [
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "10",
"id": "678394455849566208",
"content": "20",
"id": "678394498098659349",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812242234,
"timestampMs": 1581812252307,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "9",
"id": "678394451462193154",
"content": "19",
"id": "678394493124476939",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812241188,
"timestampMs": 1581812251121,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "8",
"id": "678394448497082388",
"content": "18",
"id": "678394489391415348",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812240481,
"timestampMs": 1581812250231,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "7",
"id": "678394445351092275",
"content": "17",
"id": "678394486644146187",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812239731,
"timestampMs": 1581812249576,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "6",
"id": "678394442301833247",
"content": "16",
"id": "678394484291141700",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812239004,
"timestampMs": 1581812249015,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "5",
"id": "678394436757094410",
"content": "15",
"id": "678394480184918016",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [
Object {
"id": "678399364418502669",
"name": "sourcecred",
"id": null,
"name": "😆",
},
],
"timestampMs": 1581812237682,
"timestampMs": 1581812248036,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "4",
"id": "678394433233747978",
"content": "14",
"id": "678394477106167818",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812236842,
"timestampMs": 1581812247302,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "3",
"id": "678394431149178940",
"content": "13",
"id": "678394473428025354",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812236345,
"timestampMs": 1581812246425,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "2",
"id": "678394428569813013",
"content": "12",
"id": "678394469048909841",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812235730,
"timestampMs": 1581812245381,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "1",
"id": "678394426153893948",
"content": "11",
"id": "678394468373626890",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [
Object {
"id": null,
"name": "👍",
},
],
"timestampMs": 1581812235154,
"reactionEmoji": Array [],
"timestampMs": 1581812245220,
},
]
`;
Expand All @@ -403,107 +398,102 @@ Array [
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "20",
"id": "678394498098659349",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812252307,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "19",
"id": "678394493124476939",
"content": "9",
"id": "678394451462193154",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812251121,
"timestampMs": 1581812241188,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "18",
"id": "678394489391415348",
"content": "8",
"id": "678394448497082388",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812250231,
"timestampMs": 1581812240481,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "17",
"id": "678394486644146187",
"content": "7",
"id": "678394445351092275",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812249576,
"timestampMs": 1581812239731,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "16",
"id": "678394484291141700",
"content": "6",
"id": "678394442301833247",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812249015,
"timestampMs": 1581812239004,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "15",
"id": "678394480184918016",
"content": "5",
"id": "678394436757094410",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [
Object {
"id": null,
"name": "😆",
"id": "678399364418502669",
"name": "sourcecred",
},
],
"timestampMs": 1581812248036,
"timestampMs": 1581812237682,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "14",
"id": "678394477106167818",
"content": "4",
"id": "678394433233747978",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812247302,
"timestampMs": 1581812236842,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "13",
"id": "678394473428025354",
"content": "3",
"id": "678394431149178940",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812246425,
"timestampMs": 1581812236345,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "12",
"id": "678394469048909841",
"content": "2",
"id": "678394428569813013",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812245381,
"timestampMs": 1581812235730,
},
Object {
"authorId": "143776454050709505",
"channelId": "678394406507905129",
"content": "11",
"id": "678394468373626890",
"content": "1",
"id": "678394426153893948",
"mentions": Array [],
"nonUserAuthor": false,
"reactionEmoji": Array [],
"timestampMs": 1581812245220,
"reactionEmoji": Array [
Object {
"id": null,
"name": "👍",
},
],
"timestampMs": 1581812235154,
},
]
`;
Expand Down
13 changes: 13 additions & 0 deletions packages/sourcecred/src/plugins/discord/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import {
type ChannelWeightConfig,
type WeightConfig,
} from "./reactionWeights";
import {
fromISO,
timestampISOParser,
type TimestampISO,
type TimestampMs,
} from "../../util/timestamp";

export type {BotToken as DiscordToken} from "./models";

Expand Down Expand Up @@ -71,6 +77,8 @@ export type DiscordConfigJson = $ReadOnlyArray<{|
+includeNsfwChannels?: boolean,
// This reduces graph size by replacing reaction nodes with message node weights.
+simplifyGraph?: boolean,
// This tells the fetcher not to fetch any messages before this date.
+beginningDate?: TimestampISO,
|}>;

const parserJson: C.Parser<DiscordConfigJson> = C.array(
Expand Down Expand Up @@ -100,6 +108,7 @@ const parserJson: C.Parser<DiscordConfigJson> = C.array(
propsChannels: C.array(C.string),
includeNsfwChannels: C.boolean,
simplifyGraph: C.boolean,
beginningDate: timestampISOParser,
}
)
);
Expand All @@ -110,6 +119,7 @@ export type DiscordConfig = {|
+propsChannels: $ReadOnlyArray<Model.Snowflake>,
+includeNsfwChannels: boolean,
+simplifyGraph: boolean,
+beginningTimestampMs: TimestampMs,
|};
export type DiscordConfigs = $ReadOnlyArray<DiscordConfig>;

Expand Down Expand Up @@ -144,6 +154,9 @@ export function _upgrade(json: DiscordConfigJson): DiscordConfigs {
propsChannels: config.propsChannels || [],
includeNsfwChannels: config.includeNsfwChannels || false,
simplifyGraph: config.simplifyGraph || false,
beginningTimestampMs: config.beginningDate
? fromISO(config.beginningDate)
: -Infinity,
}));
}

Expand Down
4 changes: 4 additions & 0 deletions packages/sourcecred/src/plugins/discord/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("plugins/discord/config", () => {
},
includeNsfwChannels: true,
simplifyGraph: true,
beginningDate: "1/1/2021 GMT",
},
];
const expected = [
Expand Down Expand Up @@ -63,6 +64,7 @@ describe("plugins/discord/config", () => {
},
includeNsfwChannels: true,
simplifyGraph: true,
beginningTimestampMs: 1609459200000,
},
];
const parsed: DiscordConfigs = parser.parseOrThrow(raw);
Expand Down Expand Up @@ -93,6 +95,7 @@ describe("plugins/discord/config", () => {
});
expect(parsed[0].includeNsfwChannels).toEqual(false);
expect(parsed[0].simplifyGraph).toEqual(false);
expect(parsed[0].beginningTimestampMs).toEqual(-Infinity);
});
it("can work with delimiters", () => {
const raw = [
Expand Down Expand Up @@ -153,6 +156,7 @@ describe("plugins/discord/config", () => {
},
includeNsfwChannels: true,
simplifyGraph: false,
beginningTimestampMs: -Infinity,
},
];
const parsed: DiscordConfigs = parser.parseOrThrow(raw);
Expand Down
Loading