Skip to content

Commit d2e2ed7

Browse files
committed
feat: prepare the platform for multiple bots
1 parent 545071c commit d2e2ed7

File tree

15 files changed

+87
-16
lines changed

15 files changed

+87
-16
lines changed

api-schema.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ input AdminCreateBotInput {
1111
clientId: String!
1212
clientSecret: String!
1313
communityId: String!
14+
platform: BotPlatform!
1415
token: String!
1516
}
1617

@@ -217,6 +218,7 @@ type Bot {
217218
inviteUrl: String!
218219
name: String!
219220
permissions: [BotRole!]
221+
platform: BotPlatform!
220222
redirectUrl: String!
221223
redirectUrlSet: Boolean
222224
started: Boolean!
@@ -231,6 +233,11 @@ type BotPaging {
231233
meta: PagingMeta!
232234
}
233235

236+
enum BotPlatform {
237+
Discord
238+
Telegram
239+
}
240+
234241
type BotRole {
235242
botId: String
236243
createdAt: DateTime
@@ -809,6 +816,7 @@ input UserCreateBotInput {
809816
clientId: String!
810817
clientSecret: String!
811818
communityId: String!
819+
platform: BotPlatform!
812820
token: String!
813821
}
814822

apps/api-e2e/src/api/api-bot-user-feature.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AdminCreateBotInput, Bot, UserCreateBotInput, UserUpdateBotInput } from '@pubkey-link/sdk'
1+
import { AdminCreateBotInput, Bot, BotPlatform, UserCreateBotInput, UserUpdateBotInput } from '@pubkey-link/sdk'
22
import { getAliceCookie, getBobCookie, sdk } from '../support'
33

44
const defaultCommunityId = 'pubkey'
@@ -7,6 +7,7 @@ const defaultInput: AdminCreateBotInput = {
77
clientId: 'pubkey',
88
clientSecret: 'pubkey',
99
token: 'pubkey',
10+
platform: BotPlatform.Discord,
1011
}
1112

1213
// TODO: Figure out how to test this

libs/api/bot/data-access/src/lib/api-bot-sync.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class ApiBotSyncService {
126126
return this.core.data.rolePermission
127127
.findMany({
128128
where: {
129-
role: { community: { bot: { id: botId } } },
129+
role: { community: { bots: { some: { id: botId } } } },
130130
},
131131
select: {
132132
roleId: true,
@@ -153,7 +153,7 @@ export class ApiBotSyncService {
153153
return this.core.data.communityMember
154154
.findMany({
155155
where: {
156-
community: { bot: { id: botId } },
156+
community: { bots: { some: { id: botId } } },
157157
user: {
158158
status: UserStatus.Active,
159159
identities: { some: { provider: IdentityProvider.Discord } },
@@ -174,7 +174,7 @@ export class ApiBotSyncService {
174174
communities: {
175175
where: {
176176
// The community related to this bot
177-
community: { bot: { id: botId } },
177+
community: { bots: { some: { id: botId } } },
178178
},
179179
include: {
180180
// Get the roles for this member in the community

libs/api/bot/data-access/src/lib/dto/admin-create-bot.input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, InputType } from '@nestjs/graphql'
2+
import { BotPlatform } from '../entity/bot-platform.enum'
23

34
@InputType()
45
export class AdminCreateBotInput {
@@ -10,4 +11,6 @@ export class AdminCreateBotInput {
1011
clientSecret!: string
1112
@Field()
1213
communityId!: string
14+
@Field(() => BotPlatform)
15+
platform!: BotPlatform
1316
}

libs/api/bot/data-access/src/lib/dto/user-create-bot.input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, InputType } from '@nestjs/graphql'
2+
import { BotPlatform } from '../entity/bot-platform.enum'
23

34
@InputType()
45
export class UserCreateBotInput {
@@ -10,4 +11,6 @@ export class UserCreateBotInput {
1011
clientSecret!: string
1112
@Field()
1213
communityId!: string
14+
@Field(() => BotPlatform)
15+
platform!: BotPlatform
1316
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { registerEnumType } from '@nestjs/graphql'
2+
import { BotPlatform } from '@prisma/client'
3+
4+
export { BotPlatform }
5+
6+
registerEnumType(BotPlatform, { name: 'BotPlatform' })

libs/api/bot/data-access/src/lib/entity/bot.entity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Field, HideField, ObjectType } from '@nestjs/graphql'
2+
import { BotPlatform } from '@prisma/client'
23
import { BotApplication } from '@pubkey-link/api-bot-util'
34
import { PagingResponse } from '@pubkey-link/api-core-data-access'
45
import { GraphQLJSON } from 'graphql-scalars'
@@ -17,6 +18,8 @@ export class Bot {
1718
name!: string
1819
@Field({ nullable: true })
1920
avatarUrl?: string | null
21+
@Field(() => BotPlatform)
22+
platform!: BotPlatform
2023
@Field(() => BotStatus)
2124
status!: BotStatus
2225
@HideField()

libs/api/community/data-access/src/lib/api-community-data-anon.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class ApiCommunityDataAnonService {
88
async getCommunities() {
99
this.core.config.ensureFeature(AppFeature.AnonCommunities)
1010
return this.core.data.community.findMany({
11-
where: { featured: true, bot: { isNot: null } },
11+
where: { featured: true, bots: { some: {} } },
1212
orderBy: { name: 'asc' },
1313
})
1414
}

libs/api/community/data-access/src/lib/provision/api-community-provision-data.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NetworkCluster, NetworkTokenType, Prisma } from '@prisma/client'
1+
import { BotPlatform, NetworkCluster, NetworkTokenType, Prisma } from '@prisma/client'
22

33
const cluster = NetworkCluster.SolanaMainnet
44
const DL_SERVER = '953959331353751632'
@@ -18,6 +18,7 @@ const DL_BOT: Prisma.BotCreateWithoutCommunityInput = {
1818
avatarUrl: 'https://cdn.discordapp.com/avatars/1138462172092039258/2d9f621e44433c97e171bb40ec122b6f.png?size=1024',
1919
id: process.env['DEANSLIST_BOT_CLIENT_ID'] ?? '',
2020
name: "Dean's List Projects LOCAL",
21+
platform: BotPlatform.Discord,
2122
permissions: {
2223
create: [DL_ROLE_ONE_OF_US, DL_ROLE_BV, DL_ROLE_BV_EXPIRED, DL_ROLE_HOLDER].map((serverRoleId) => ({
2324
id: `${DL_SERVER}-${serverRoleId}`,
@@ -86,6 +87,7 @@ const LOS_BOT: Prisma.BotCreateWithoutCommunityInput = {
8687
avatarUrl: 'https://cdn.discordapp.com/avatars/1208445127832637451/babbe2d94cc9058e7a66a844a7b15eb5.png?size=1024',
8788
id: process.env['LOS_BOT_CLIENT_ID'] ?? '',
8889
name: 'Legends of Sol 🅿 Verification',
90+
platform: BotPlatform.Discord,
8991
permissions: {
9092
create: [LOS_ROLE_CERTIFIED].map((serverRoleId) => ({
9193
id: `${LOS_SERVER}-${serverRoleId}`,
@@ -122,6 +124,7 @@ const PK_BOT: Prisma.BotCreateWithoutCommunityInput = {
122124
id: process.env['PUBKEY_BOT_CLIENT_ID'] ?? '',
123125
name: 'PubKey Link Yellow',
124126
status: 'Active',
127+
platform: BotPlatform.Discord,
125128
permissions: {
126129
create: [PK_ROLE_DEANSLIST, PK_ROLE_DL_BV, PK_ROLE_DL_BV_EXPIRED, PK_ROLE_DL_HOLDER].map((serverRoleId) => ({
127130
id: `${PK_SERVER}-${serverRoleId}`,
@@ -185,7 +188,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
185188
{ user: { connect: { id: 'dave' } }, admin: true },
186189
],
187190
},
188-
bot: { create: PK_BOT.clientId ? PK_BOT : undefined },
191+
bots: { create: PK_BOT.clientId ? PK_BOT : undefined },
189192
roles: {
190193
create: [
191194
{
@@ -238,7 +241,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
238241
avatarUrl: 'https://avatars.githubusercontent.com/u/137821488?v=4',
239242
twitterUrl: 'https://twitter.com/deanslistDAO',
240243
websiteUrl: 'https://deanslist.services',
241-
bot: DL_BOT.clientId ? { create: DL_BOT } : undefined,
244+
bots: DL_BOT.clientId ? { create: DL_BOT } : undefined,
242245
roles: {
243246
create: [
244247
{
@@ -316,7 +319,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
316319
{ user: { connect: { id: 'bob' } }, admin: false },
317320
],
318321
},
319-
bot: LOS_BOT.clientId ? { create: LOS_BOT } : undefined,
322+
bots: LOS_BOT.clientId ? { create: LOS_BOT } : undefined,
320323
roles: {
321324
create: [
322325
{

libs/sdk/src/generated/graphql-sdk.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type AdminCreateBotInput = {
3333
clientId: Scalars['String']['input']
3434
clientSecret: Scalars['String']['input']
3535
communityId: Scalars['String']['input']
36+
platform: BotPlatform
3637
token: Scalars['String']['input']
3738
}
3839

@@ -241,6 +242,7 @@ export type Bot = {
241242
inviteUrl: Scalars['String']['output']
242243
name: Scalars['String']['output']
243244
permissions?: Maybe<Array<BotRole>>
245+
platform: BotPlatform
244246
redirectUrl: Scalars['String']['output']
245247
redirectUrlSet?: Maybe<Scalars['Boolean']['output']>
246248
started: Scalars['Boolean']['output']
@@ -256,6 +258,11 @@ export type BotPaging = {
256258
meta: PagingMeta
257259
}
258260

261+
export enum BotPlatform {
262+
Discord = 'Discord',
263+
Telegram = 'Telegram',
264+
}
265+
259266
export type BotRole = {
260267
__typename?: 'BotRole'
261268
botId?: Maybe<Scalars['String']['output']>
@@ -1395,6 +1402,7 @@ export type UserCreateBotInput = {
13951402
clientId: Scalars['String']['input']
13961403
clientSecret: Scalars['String']['input']
13971404
communityId: Scalars['String']['input']
1405+
platform: BotPlatform
13981406
token: Scalars['String']['input']
13991407
}
14001408

@@ -1666,6 +1674,7 @@ export type BotDetailsFragment = {
16661674
id: string
16671675
inviteUrl: string
16681676
name: string
1677+
platform: BotPlatform
16691678
redirectUrl: string
16701679
redirectUrlSet?: boolean | null
16711680
started: boolean
@@ -1756,6 +1765,7 @@ export type AdminFindManyBotQuery = {
17561765
id: string
17571766
inviteUrl: string
17581767
name: string
1768+
platform: BotPlatform
17591769
redirectUrl: string
17601770
redirectUrlSet?: boolean | null
17611771
started: boolean
@@ -1792,6 +1802,7 @@ export type AdminFindOneBotQuery = {
17921802
id: string
17931803
inviteUrl: string
17941804
name: string
1805+
platform: BotPlatform
17951806
redirectUrl: string
17961807
redirectUrlSet?: boolean | null
17971808
started: boolean
@@ -1817,6 +1828,7 @@ export type AdminCreateBotMutation = {
18171828
id: string
18181829
inviteUrl: string
18191830
name: string
1831+
platform: BotPlatform
18201832
redirectUrl: string
18211833
redirectUrlSet?: boolean | null
18221834
started: boolean
@@ -1843,6 +1855,7 @@ export type AdminUpdateBotMutation = {
18431855
id: string
18441856
inviteUrl: string
18451857
name: string
1858+
platform: BotPlatform
18461859
redirectUrl: string
18471860
redirectUrlSet?: boolean | null
18481861
started: boolean
@@ -1874,6 +1887,7 @@ export type UserFindOneBotQuery = {
18741887
id: string
18751888
inviteUrl: string
18761889
name: string
1890+
platform: BotPlatform
18771891
redirectUrl: string
18781892
redirectUrlSet?: boolean | null
18791893
started: boolean
@@ -2052,6 +2066,7 @@ export type UserCreateBotMutation = {
20522066
id: string
20532067
inviteUrl: string
20542068
name: string
2069+
platform: BotPlatform
20552070
redirectUrl: string
20562071
redirectUrlSet?: boolean | null
20572072
started: boolean
@@ -2078,6 +2093,7 @@ export type UserUpdateBotMutation = {
20782093
id: string
20792094
inviteUrl: string
20802095
name: string
2096+
platform: BotPlatform
20812097
redirectUrl: string
20822098
redirectUrlSet?: boolean | null
20832099
started: boolean
@@ -4668,6 +4684,7 @@ export type LogDetailsFragment = {
46684684
id: string
46694685
inviteUrl: string
46704686
name: string
4687+
platform: BotPlatform
46714688
redirectUrl: string
46724689
redirectUrlSet?: boolean | null
46734690
started: boolean
@@ -4865,6 +4882,7 @@ export type UserFindManyLogQuery = {
48654882
id: string
48664883
inviteUrl: string
48674884
name: string
4885+
platform: BotPlatform
48684886
redirectUrl: string
48694887
redirectUrlSet?: boolean | null
48704888
started: boolean
@@ -5072,6 +5090,7 @@ export type UserFindOneLogQuery = {
50725090
id: string
50735091
inviteUrl: string
50745092
name: string
5093+
platform: BotPlatform
50755094
redirectUrl: string
50765095
redirectUrlSet?: boolean | null
50775096
started: boolean
@@ -5270,6 +5289,7 @@ export type AdminFindManyLogQuery = {
52705289
id: string
52715290
inviteUrl: string
52725291
name: string
5292+
platform: BotPlatform
52735293
redirectUrl: string
52745294
redirectUrlSet?: boolean | null
52755295
started: boolean
@@ -5477,6 +5497,7 @@ export type AdminFindOneLogQuery = {
54775497
id: string
54785498
inviteUrl: string
54795499
name: string
5500+
platform: BotPlatform
54805501
redirectUrl: string
54815502
redirectUrlSet?: boolean | null
54825503
started: boolean
@@ -8657,6 +8678,7 @@ export const BotDetailsFragmentDoc = gql`
86578678
id
86588679
inviteUrl
86598680
name
8681+
platform
86608682
redirectUrl
86618683
redirectUrlSet
86628684
started
@@ -13156,6 +13178,8 @@ export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny
1315613178

1315713179
export const AppFeatureSchema = z.nativeEnum(AppFeature)
1315813180

13181+
export const BotPlatformSchema = z.nativeEnum(BotPlatform)
13182+
1315913183
export const BotStatusSchema = z.nativeEnum(BotStatus)
1316013184

1316113185
export const IdentityProviderSchema = z.nativeEnum(IdentityProvider)
@@ -13188,6 +13212,7 @@ export function AdminCreateBotInputSchema(): z.ZodObject<Properties<AdminCreateB
1318813212
clientId: z.string(),
1318913213
clientSecret: z.string(),
1319013214
communityId: z.string(),
13215+
platform: BotPlatformSchema,
1319113216
token: z.string(),
1319213217
})
1319313218
}
@@ -13449,6 +13474,7 @@ export function UserCreateBotInputSchema(): z.ZodObject<Properties<UserCreateBot
1344913474
clientId: z.string(),
1345013475
clientSecret: z.string(),
1345113476
communityId: z.string(),
13477+
platform: BotPlatformSchema,
1345213478
token: z.string(),
1345313479
})
1345413480
}

0 commit comments

Comments
 (0)