You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
95 lines
2.8 KiB
import {Snowflake} from "discord-api-types";
|
|
import {PrismaClient} from "./Prisma.js";
|
|
|
|
export class ChannelManager {
|
|
readonly client: PrismaClient
|
|
|
|
constructor(client: PrismaClient) {
|
|
this.client = client
|
|
}
|
|
|
|
async getGameCommandGuildIds(): Promise<Snowflake[]> {
|
|
return (await this.client.discordChannel.findMany({
|
|
where: {
|
|
acceptGameCommands: true,
|
|
guildId: {
|
|
not: null
|
|
}
|
|
},
|
|
distinct: ["guildId"],
|
|
select: {
|
|
guildId: true,
|
|
},
|
|
})).map((item) => item.guildId as string)
|
|
// We know that the guild ID is not null because of the where condition.
|
|
}
|
|
|
|
async canUseGameCommandsInChannel(channelId: Snowflake): Promise<boolean> {
|
|
return ((await this.client.discordChannel.findUnique({
|
|
where: {
|
|
discordId: channelId,
|
|
},
|
|
select: {
|
|
acceptGameCommands: true,
|
|
},
|
|
rejectOnNotFound: false,
|
|
})) ?? {acceptGameCommands: false}).acceptGameCommands
|
|
}
|
|
|
|
async canUseGameCommandsInGuild(guildId: Snowflake): Promise<boolean> {
|
|
return (await this.client.discordChannel.findFirst({
|
|
where: {
|
|
guildId: guildId,
|
|
acceptGameCommands: true,
|
|
},
|
|
select: {
|
|
discordId: true
|
|
}
|
|
})) !== null
|
|
}
|
|
|
|
async getAdminCommandGuildIds(): Promise<Snowflake[]> {
|
|
return (await this.client.discordChannel.findMany({
|
|
where: {
|
|
acceptAdminCommands: true,
|
|
guildId: {
|
|
not: null
|
|
}
|
|
},
|
|
distinct: ["guildId"],
|
|
select: {
|
|
guildId: true,
|
|
},
|
|
})).map((item) => item.guildId as string)
|
|
// We know that the guild ID is not null because of the where condition.
|
|
}
|
|
|
|
async canUseAdminCommandsInChannel(channelId: Snowflake): Promise<boolean> {
|
|
return ((await this.client.discordChannel.findUnique({
|
|
where: {
|
|
discordId: channelId,
|
|
},
|
|
select: {
|
|
acceptAdminCommands: true,
|
|
},
|
|
rejectOnNotFound: false,
|
|
})) ?? {acceptAdminCommands: false}
|
|
).acceptAdminCommands
|
|
}
|
|
|
|
async canUseAdminCommandsInGuild(guildId: Snowflake): Promise<boolean> {
|
|
return (await this.client.discordChannel.findFirst({
|
|
where: {
|
|
guildId: guildId,
|
|
acceptAdminCommands: true,
|
|
},
|
|
select: {
|
|
discordId: true,
|
|
}
|
|
})) !== null
|
|
}
|
|
|
|
async isGameReady() {
|
|
return false;
|
|
}
|
|
} |