MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / syncJob

Function syncJob

apps/web/services/discord/sync.ts:12–89  ·  view source on GitHub ↗
({
  account,
  decodeBotToken,
  fullSync,
  logger,
}: {
  account: accounts & {
    discordAuthorizations: discordAuthorizations[];
  };
  decodeBotToken: (accessToken: string) => string;
  logger: Logger;
  fullSync?: boolean;
})

Source from the content-addressed store, hash-verified

10import { Logger } from '@linen/types';
11
12async function syncJob({
13 account,
14 decodeBotToken,
15 fullSync,
16 logger,
17}: {
18 account: accounts & {
19 discordAuthorizations: discordAuthorizations[];
20 };
21 decodeBotToken: (accessToken: string) => string;
22 logger: Logger;
23 fullSync?: boolean;
24}) {
25 logger.log({ sync: 'stared' });
26
27 if (!account.discordServerId) {
28 throw new Error('discord server id not found');
29 }
30 if (!account.discordAuthorizations || !account.discordAuthorizations.length) {
31 throw new Error('discord authorization not found');
32 }
33
34 const discordAuthorizations = account.discordAuthorizations.find(Boolean);
35 const onboardingTimestamp = discordAuthorizations?.syncFrom || new Date(0);
36
37 logger.log({ onboardingTimestamp });
38
39 const token = discordAuthorizations?.customBot
40 ? decodeBotToken(discordAuthorizations.accessToken)
41 : botV1().PRIVATE_TOKEN;
42
43 await crawlUsers({
44 accountId: account.id,
45 serverId: account.discordServerId,
46 token,
47 logger,
48 });
49
50 const hideChannels = account.newChannelsConfig === 'HIDDEN';
51
52 const channels = await listChannelsAndPersist({
53 serverId: account.discordServerId,
54 accountId: account.id,
55 token,
56 logger,
57 hideChannels,
58 });
59
60 if (fullSync) {
61 await ChannelsService.setCursorNull({ accountId: account.id });
62 }
63
64 // active threads are global (not channel specific)
65 await getActiveThreads({
66 serverId: account.discordServerId,
67 token,
68 onboardingTimestamp,
69 logger,

Callers 2

syncFunction · 0.90
discordSyncFunction · 0.70

Calls 9

botV1Function · 0.90
crawlUsersFunction · 0.90
listChannelsAndPersistFunction · 0.90
getActiveThreadsFunction · 0.90
getArchivedThreadsFunction · 0.90
getMessagesFunction · 0.90
setCursorNullMethod · 0.80
logMethod · 0.65
findMethod · 0.45

Tested by

no test coverage detected