Skip to content

Commit 5549717

Browse files
committed
fix: set state to deleted for deleted bots
1 parent 3c3816a commit 5549717

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

pages/bots/[id]/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
8888
) : (
8989
<>
9090
<div className='w-full pb-2'>
91-
{data.state === 'private' ? (
91+
{checkBotFlag(data.flags, 'private') ? (
9292
<Message type='info'>
9393
<h2 className='text-lg font-extrabold'>
9494
해당 봇은 특수목적 봇이므로 초대하실 수 없습니다.
@@ -158,7 +158,7 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
158158
</p>
159159
</div>
160160
<div className='w-full lg:w-1/4'>
161-
{data.state === 'ok' && (
161+
{(data.state === 'ok' && !checkBotFlag(data.flags, 'private')) && (
162162
<LongButton newTab href={`/bots/${router.query.id}/invite`}>
163163
<h4 className='whitespace-nowrap'>
164164
<i className='fas fa-user-plus text-discord-blurple' /> 초대하기

types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export enum BotFlags {
156156
verified = 1 << 4,
157157
premium = 1 << 5,
158158
hackerthon = 1 << 6,
159+
private = 1 << 7,
159160
}
160161

161162
export enum ServerFlags {

utils/Query.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ async function getBot(id: string, topLevel = true): Promise<Bot> {
7676

7777
if (res) {
7878
const discordBot = await get.discord.user.load(res.id)
79-
if (!discordBot || Number(discordBot.discriminator) === 0) return null
79+
if (!discordBot || Number(discordBot.discriminator) === 0) {
80+
knex('bots')
81+
.update({ state: 'deleted' })
82+
.where({ id })
83+
.then((r) => r)
84+
}
8085
const botMember = (await getMainGuild()
8186
?.members?.fetch(res.id)
8287
.catch((e) => e)) as GuildMember
@@ -239,41 +244,41 @@ async function getBotList(type: ListType, page = 1, query?: string): Promise<Lis
239244
let res: { id: string }[]
240245
let count: string | number
241246
if (type === 'VOTE') {
242-
count = (await knex('bots').whereNot({ state: 'blocked' }).count())[0]['count(*)']
247+
count = (await knex('bots').where({ state: 'ok' }).count())[0]['count(*)']
243248
res = await knex('bots')
244249
.orderBy('votes', 'desc')
245250
.orderBy('servers', 'desc')
246251
.limit(16)
247252
.offset(((page ? Number(page) : 1) - 1) * 16)
248253
.select(['id'])
249-
.whereNot({ state: 'blocked' })
254+
.where({ state: 'ok' })
250255
} else if (type === 'TRUSTED') {
251-
count = (await knex('bots').where({ trusted: true }).count().whereNot({ state: 'blocked' }))[0][
256+
count = (await knex('bots').where({ trusted: true }).count().where({ state: 'ok' }))[0][
252257
'count(*)'
253258
]
254259
res = await knex('bots')
255-
.whereNot({ state: 'blocked' })
260+
.where({ state: 'ok' })
256261
.where({ trusted: true })
257262
.orderByRaw('RAND()')
258263
.limit(16)
259264
.offset(((page ? Number(page) : 1) - 1) * 16)
260265
.select(['id'])
261-
.whereNot({ state: 'blocked' })
266+
.where({ state: 'ok' })
262267
} else if (type === 'NEW') {
263-
count = (await knex('bots').whereNot({ state: 'blocked' }).count())[0]['count(*)']
268+
count = (await knex('bots').where({ state: 'ok' }).count())[0]['count(*)']
264269
res = await knex('bots')
265270
.orderBy('date', 'desc')
266271
.limit(16)
267272
.offset(((page ? Number(page) : 1) - 1) * 16)
268273
.select(['id'])
269-
.whereNot({ state: 'blocked' })
274+
.where({ state: 'ok' })
270275
} else if (type === 'PARTNERED') {
271-
count = (
272-
await knex('bots').where({ partnered: true }).andWhereNot({ state: 'blocked' }).count()
273-
)[0]['count(*)']
276+
count = (await knex('bots').where({ partnered: true }).andWhere({ state: 'ok' }).count())[0][
277+
'count(*)'
278+
]
274279
res = await knex('bots')
275280
.where({ partnered: true })
276-
.andWhereNot({ state: 'blocked' })
281+
.andWhere({ state: 'ok' })
277282
.orderByRaw('RAND()')
278283
.limit(16)
279284
.offset(((page ? Number(page) : 1) - 1) * 16)
@@ -284,12 +289,12 @@ async function getBotList(type: ListType, page = 1, query?: string): Promise<Lis
284289
count = (
285290
await knex('bots')
286291
.where('category', 'like', `%${decodeURI(query)}%`)
287-
.andWhereNot({ state: 'blocked' })
292+
.andWhere({ state: 'ok' })
288293
.count()
289294
)[0]['count(*)']
290295
res = await knex('bots')
291296
.where('category', 'like', `%${decodeURI(query)}%`)
292-
.andWhereNot({ state: 'blocked' })
297+
.andWhere({ state: 'ok' })
293298
.orderBy('votes', 'desc')
294299
.orderBy('servers', 'desc')
295300
.limit(16)
@@ -299,13 +304,13 @@ async function getBotList(type: ListType, page = 1, query?: string): Promise<Lis
299304
if (!query) throw new Error('쿼리가 누락되었습니다.')
300305
count = (
301306
await knex.raw(
302-
'SELECT count(*) FROM bots WHERE `state` != "blocked" AND MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode)',
307+
'SELECT count(*) FROM bots WHERE `state` = "ok" AND MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode)',
303308
[decodeURI(query) + '*']
304309
)
305310
)[0][0]['count(*)']
306311
res = (
307312
await knex.raw(
308-
'SELECT id, votes, MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) as relevance FROM bots WHERE `state` != "blocked" AND MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) ORDER BY relevance DESC, votes DESC LIMIT 8 OFFSET ?',
313+
'SELECT id, votes, MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) as relevance FROM bots WHERE `state` = "ok" AND MATCH(`name`, `intro`, `desc`) AGAINST(? in boolean mode) ORDER BY relevance DESC, votes DESC LIMIT 8 OFFSET ?',
309314
[decodeURI(query) + '*', decodeURI(query) + '*', ((page ? Number(page) : 1) - 1) * 8]
310315
)
311316
)[0]

0 commit comments

Comments
 (0)