Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ FEATURE_ANON_COMMUNITIES=true
#FEATURE_BETA_DAS_BURNT=false
# Enable DAS search option (This is a beta feature)
#FEATURE_BETA_DAS_SEARCH=false
# Enable Discord bot platform
FEATURE_BOT_PLATFORM_DISCORD=true
# Enable Telegram bot platform
FEATURE_BOT_PLATFORM_TELEGRAM=false
# Enable community create feature
#FEATURE_COMMUNITY_CREATE=true
# Enable community snapshots feature
Expand Down
10 changes: 10 additions & 0 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ input AdminCreateBotInput {
clientId: String!
clientSecret: String!
communityId: String!
platform: BotPlatform!
token: String!
}

Expand Down Expand Up @@ -200,6 +201,8 @@ type AppConfig {

enum AppFeature {
AnonCommunities
BotPlatformDiscord
BotPlatformTelegram
CommunityCreate
CommunitySnapshots
IdentityCliVerification
Expand All @@ -217,6 +220,7 @@ type Bot {
inviteUrl: String!
name: String!
permissions: [BotRole!]
platform: BotPlatform!
redirectUrl: String!
redirectUrlSet: Boolean
started: Boolean!
Expand All @@ -231,6 +235,11 @@ type BotPaging {
meta: PagingMeta!
}

enum BotPlatform {
Discord
Telegram
}

type BotRole {
botId: String
createdAt: DateTime
Expand Down Expand Up @@ -809,6 +818,7 @@ input UserCreateBotInput {
clientId: String!
clientSecret: String!
communityId: String!
platform: BotPlatform!
token: String!
}

Expand Down
3 changes: 2 additions & 1 deletion apps/api-e2e/src/api/api-bot-admin-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdminCreateBotInput, AdminFindManyBotInput, AdminUpdateBotInput, Bot } from '@pubkey-link/sdk'
import { AdminCreateBotInput, AdminFindManyBotInput, AdminUpdateBotInput, Bot, BotPlatform } from '@pubkey-link/sdk'
import { getAliceCookie, getBobCookie, sdk } from '../support'

const defaultCommunityId = 'pubkey'
Expand All @@ -7,6 +7,7 @@ const defaultInput: AdminCreateBotInput = {
clientId: 'pubkey',
clientSecret: 'pubkey',
token: 'pubkey',
platform: BotPlatform.Discord,
}

// TODO: Figure out how to test this
Expand Down
3 changes: 2 additions & 1 deletion apps/api-e2e/src/api/api-bot-user-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdminCreateBotInput, Bot, UserCreateBotInput, UserUpdateBotInput } from '@pubkey-link/sdk'
import { AdminCreateBotInput, Bot, BotPlatform, UserCreateBotInput, UserUpdateBotInput } from '@pubkey-link/sdk'
import { getAliceCookie, getBobCookie, sdk } from '../support'

const defaultCommunityId = 'pubkey'
Expand All @@ -7,6 +7,7 @@ const defaultInput: AdminCreateBotInput = {
clientId: 'pubkey',
clientSecret: 'pubkey',
token: 'pubkey',
platform: BotPlatform.Discord,
}

// TODO: Figure out how to test this
Expand Down
6 changes: 3 additions & 3 deletions libs/api/bot/data-access/src/lib/api-bot-sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ApiBotSyncService {
return this.core.data.rolePermission
.findMany({
where: {
role: { community: { bot: { id: botId } } },
role: { community: { bots: { some: { id: botId } } } },
},
select: {
roleId: true,
Expand All @@ -153,7 +153,7 @@ export class ApiBotSyncService {
return this.core.data.communityMember
.findMany({
where: {
community: { bot: { id: botId } },
community: { bots: { some: { id: botId } } },
user: {
status: UserStatus.Active,
identities: { some: { provider: IdentityProvider.Discord } },
Expand All @@ -174,7 +174,7 @@ export class ApiBotSyncService {
communities: {
where: {
// The community related to this bot
community: { bot: { id: botId } },
community: { bots: { some: { id: botId } } },
},
include: {
// Get the roles for this member in the community
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, InputType } from '@nestjs/graphql'
import { BotPlatform } from '../entity/bot-platform.enum'

@InputType()
export class AdminCreateBotInput {
Expand All @@ -10,4 +11,6 @@ export class AdminCreateBotInput {
clientSecret!: string
@Field()
communityId!: string
@Field(() => BotPlatform)
platform!: BotPlatform
}
3 changes: 3 additions & 0 deletions libs/api/bot/data-access/src/lib/dto/user-create-bot.input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, InputType } from '@nestjs/graphql'
import { BotPlatform } from '../entity/bot-platform.enum'

@InputType()
export class UserCreateBotInput {
Expand All @@ -10,4 +11,6 @@ export class UserCreateBotInput {
clientSecret!: string
@Field()
communityId!: string
@Field(() => BotPlatform)
platform!: BotPlatform
}
6 changes: 6 additions & 0 deletions libs/api/bot/data-access/src/lib/entity/bot-platform.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { registerEnumType } from '@nestjs/graphql'
import { BotPlatform } from '@prisma/client'

export { BotPlatform }

registerEnumType(BotPlatform, { name: 'BotPlatform' })
3 changes: 3 additions & 0 deletions libs/api/bot/data-access/src/lib/entity/bot.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, HideField, ObjectType } from '@nestjs/graphql'
import { BotPlatform } from '@prisma/client'
import { BotApplication } from '@pubkey-link/api-bot-util'
import { PagingResponse } from '@pubkey-link/api-core-data-access'
import { GraphQLJSON } from 'graphql-scalars'
Expand All @@ -17,6 +18,8 @@ export class Bot {
name!: string
@Field({ nullable: true })
avatarUrl?: string | null
@Field(() => BotPlatform)
platform!: BotPlatform
@Field(() => BotStatus)
status!: BotStatus
@HideField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ApiCommunityDataAnonService {
async getCommunities() {
this.core.config.ensureFeature(AppFeature.AnonCommunities)
return this.core.data.community.findMany({
where: { featured: true, bot: { isNot: null } },
where: { featured: true, bots: { some: {} } },
orderBy: { name: 'asc' },
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkCluster, NetworkTokenType, Prisma } from '@prisma/client'
import { BotPlatform, NetworkCluster, NetworkTokenType, Prisma } from '@prisma/client'

const cluster = NetworkCluster.SolanaMainnet
const DL_SERVER = '953959331353751632'
Expand All @@ -18,6 +18,7 @@ const DL_BOT: Prisma.BotCreateWithoutCommunityInput = {
avatarUrl: 'https://cdn.discordapp.com/avatars/1138462172092039258/2d9f621e44433c97e171bb40ec122b6f.png?size=1024',
id: process.env['DEANSLIST_BOT_CLIENT_ID'] ?? '',
name: "Dean's List Projects LOCAL",
platform: BotPlatform.Discord,
permissions: {
create: [DL_ROLE_ONE_OF_US, DL_ROLE_BV, DL_ROLE_BV_EXPIRED, DL_ROLE_HOLDER].map((serverRoleId) => ({
id: `${DL_SERVER}-${serverRoleId}`,
Expand Down Expand Up @@ -86,6 +87,7 @@ const LOS_BOT: Prisma.BotCreateWithoutCommunityInput = {
avatarUrl: 'https://cdn.discordapp.com/avatars/1208445127832637451/babbe2d94cc9058e7a66a844a7b15eb5.png?size=1024',
id: process.env['LOS_BOT_CLIENT_ID'] ?? '',
name: 'Legends of Sol 🅿 Verification',
platform: BotPlatform.Discord,
permissions: {
create: [LOS_ROLE_CERTIFIED].map((serverRoleId) => ({
id: `${LOS_SERVER}-${serverRoleId}`,
Expand Down Expand Up @@ -122,6 +124,7 @@ const PK_BOT: Prisma.BotCreateWithoutCommunityInput = {
id: process.env['PUBKEY_BOT_CLIENT_ID'] ?? '',
name: 'PubKey Link Yellow',
status: 'Active',
platform: BotPlatform.Discord,
permissions: {
create: [PK_ROLE_DEANSLIST, PK_ROLE_DL_BV, PK_ROLE_DL_BV_EXPIRED, PK_ROLE_DL_HOLDER].map((serverRoleId) => ({
id: `${PK_SERVER}-${serverRoleId}`,
Expand Down Expand Up @@ -185,7 +188,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
{ user: { connect: { id: 'dave' } }, admin: true },
],
},
bot: { create: PK_BOT.clientId ? PK_BOT : undefined },
bots: { create: PK_BOT.clientId ? PK_BOT : undefined },
roles: {
create: [
{
Expand Down Expand Up @@ -238,7 +241,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
avatarUrl: 'https://avatars.githubusercontent.com/u/137821488?v=4',
twitterUrl: 'https://twitter.com/deanslistDAO',
websiteUrl: 'https://deanslist.services',
bot: DL_BOT.clientId ? { create: DL_BOT } : undefined,
bots: DL_BOT.clientId ? { create: DL_BOT } : undefined,
roles: {
create: [
{
Expand Down Expand Up @@ -316,7 +319,7 @@ export const provisionCommunities: Prisma.CommunityCreateInput[] = [
{ user: { connect: { id: 'bob' } }, admin: false },
],
},
bot: LOS_BOT.clientId ? { create: LOS_BOT } : undefined,
bots: LOS_BOT.clientId ? { create: LOS_BOT } : undefined,
roles: {
create: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ export class ApiCoreConfigService {
get featureFlags(): AppFeature[] {
return [
{ flag: this.featureAnonCommunities, feature: AppFeature.AnonCommunities },
{ flag: this.featureBotPlatformDiscord, feature: AppFeature.BotPlatformDiscord },
{ flag: this.featureBotPlatformTelegram, feature: AppFeature.BotPlatformTelegram },
{ flag: this.featureCommunityCreate, feature: AppFeature.CommunityCreate },
{ flag: this.featureCommunitySnapshots, feature: AppFeature.CommunitySnapshots },
{ flag: this.featureIdentityCliVerification, feature: AppFeature.IdentityCliVerification },
Expand All @@ -197,6 +199,14 @@ export class ApiCoreConfigService {
return this.service.get<boolean>('featureBetaDasSearch')
}

get featureBotPlatformDiscord() {
return this.service.get<boolean>('featureBotPlatformDiscord')
}

get featureBotPlatformTelegram() {
return this.service.get<boolean>('featureBotPlatformTelegram')
}

get featurePubkeyProtocol() {
return this.service.get<boolean>('featurePubkeyProtocol')
}
Expand Down
4 changes: 4 additions & 0 deletions libs/api/core/data-access/src/lib/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface ApiCoreConfig {
featureAnonCommunities: boolean
featureBetaDasBurnt: boolean
featureBetaDasSearch: boolean
featureBotPlatformDiscord: boolean
featureBotPlatformTelegram: boolean
featureCommunityCreate: boolean
featureCommunitySnapshots: boolean
featureIdentityCliVerification: boolean
Expand Down Expand Up @@ -119,6 +121,8 @@ export function configuration(): ApiCoreConfig {
featureAnonCommunities: process.env['FEATURE_ANON_COMMUNITIES'] === 'true',
featureBetaDasBurnt: process.env['FEATURE_BETA_DAS_BURNT'] === 'true',
featureBetaDasSearch: process.env['FEATURE_BETA_DAS_SEARCH'] === 'true',
featureBotPlatformDiscord: process.env['FEATURE_BOT_PLATFORM_DISCORD'] === 'true',
featureBotPlatformTelegram: process.env['FEATURE_BOT_PLATFORM_TELEGRAM'] === 'true',
featureCommunityCreate: process.env['FEATURE_COMMUNITY_CREATE'] === 'true',
featureCommunitySnapshots: process.env['FEATURE_COMMUNITY_SNAPSHOTS'] === 'true',
featureIdentityCliVerification: process.env['FEATURE_IDENTITY_CLI_VERIFICATION'] === 'true',
Expand Down
2 changes: 2 additions & 0 deletions libs/api/core/data-access/src/lib/config/validation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const validationSchema = Joi.object({
FEATURE_ANON_COMMUNITIES: Joi.boolean().default(true),
FEATURE_BETA_DAS_BURNT: Joi.boolean().default(false),
FEATURE_BETA_DAS_SEARCH: Joi.boolean().default(false),
FEATURE_BOT_PLATFORM_DISCORD: Joi.boolean().default(true),
FEATURE_BOT_PLATFORM_TELEGRAM: Joi.boolean().default(false),
FEATURE_COMMUNITY_CREATE: Joi.boolean().default(true),
FEATURE_COMMUNITY_SNAPSHOTS: Joi.boolean().default(false),
FEATURE_IDENTITY_CLI_VERIFICATION: Joi.boolean().default(false),
Expand Down
2 changes: 2 additions & 0 deletions libs/api/core/data-access/src/lib/entity/app-config.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class AppConfig {

export enum AppFeature {
AnonCommunities = 'AnonCommunities',
BotPlatformDiscord = 'BotPlatformDiscord',
BotPlatformTelegram = 'BotPlatformTelegram',
CommunityCreate = 'CommunityCreate',
CommunitySnapshots = 'CommunitySnapshots',
IdentityCliVerification = 'IdentityCliVerification',
Expand Down
Loading
Loading