Skip to content

Commit 9148060

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

File tree

16 files changed

+89
-17
lines changed

16 files changed

+89
-17
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-admin-feature.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AdminCreateBotInput, AdminFindManyBotInput, AdminUpdateBotInput, Bot } from '@pubkey-link/sdk'
1+
import { AdminCreateBotInput, AdminFindManyBotInput, AdminUpdateBotInput, Bot, BotPlatform } 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

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
{

0 commit comments

Comments
 (0)