forked from skyra-project/skyra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Moderation): added image support (skyra-project#1019)
* feat(Moderation): added image support * chore(Version): bump to 5.4.1
- Loading branch information
Showing
33 changed files
with
200 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
import type { CustomCommand } from '@lib/types/settings/GuildSettings'; | ||
import type { RawGuildSettings } from '@lib/types/settings/raw/RawGuildSettings'; | ||
import type { AnyObject } from '@lib/types/util'; | ||
import { Pool, PoolClient } from 'pg'; | ||
/** | ||
* import type { CustomCommand } from '@lib/types/settings/GuildSettings'; | ||
* import type { RawGuildSettings } from '@lib/types/settings/raw/RawGuildSettings'; | ||
* import type { AnyObject } from '@lib/types/util'; | ||
* import { Pool, PoolClient } from 'pg'; | ||
* | ||
* export default async function main(PGSQL_DATABASE_OPTIONS: any) { | ||
* const pgsql = new Pool(PGSQL_DATABASE_OPTIONS) | ||
* .on('error', console.error); | ||
* const guilds = (await pgsql.query(`SELECT * FROM guilds;`)).rows as RawGuildSettings[]; | ||
* await pgsql.query(`ALTER TABLE guilds RENAME COLUMN "tags" TO "custom-commands";`); | ||
* | ||
* const connection = await pgsql.connect(); | ||
* await connection.query('BEGIN;'); | ||
* await Promise.all(guilds.map(guild => migrateGuild(connection, guild))); | ||
* await connection.query('COMMIT;'); | ||
* connection.release(); | ||
* await pgsql.end(); | ||
* } | ||
* | ||
* async function migrateGuild(connection: PoolClient, guild: RawGuildSettings) { | ||
* const customCommands = (Reflect.get(guild, 'tags') as [string, string][]).map((v): CustomCommand => ({ | ||
* id: v[0], | ||
* content: v[1], | ||
* embed: false, | ||
* color: 0, | ||
* args: [] | ||
* })); | ||
* if (customCommands.length === 0) return; | ||
* | ||
* await connection.query(` | ||
* UPDATE guilds | ||
* SET "custom-commands" = ${cArrayJson(customCommands)} | ||
* WHERE id = ${cString(guild.id)}; | ||
* `); | ||
* } | ||
* | ||
* function cString(value: string) { | ||
* const escaped = value.replace(/'/g, "''"); | ||
* return `'${escaped}'`; | ||
* } | ||
* | ||
* function cArrayJson(value: AnyObject[]) { | ||
* return `ARRAY[${value.map(json => cString(JSON.stringify(json)))}]::JSON[]`; | ||
* } | ||
*/ | ||
|
||
export default async function main(PGSQL_DATABASE_OPTIONS: any) { | ||
const pgsql = new Pool(PGSQL_DATABASE_OPTIONS) | ||
.on('error', console.error); | ||
const guilds = (await pgsql.query(`SELECT * FROM guilds;`)).rows as RawGuildSettings[]; | ||
await pgsql.query(`ALTER TABLE guilds RENAME COLUMN "tags" TO "custom-commands";`); | ||
|
||
const connection = await pgsql.connect(); | ||
await connection.query('BEGIN;'); | ||
await Promise.all(guilds.map(guild => migrateGuild(connection, guild))); | ||
await connection.query('COMMIT;'); | ||
connection.release(); | ||
await pgsql.end(); | ||
} | ||
|
||
async function migrateGuild(connection: PoolClient, guild: RawGuildSettings) { | ||
const customCommands = (Reflect.get(guild, 'tags') as [string, string][]).map((v): CustomCommand => ({ | ||
id: v[0], | ||
content: v[1], | ||
embed: false, | ||
color: 0, | ||
args: [] | ||
})); | ||
if (customCommands.length === 0) return; | ||
|
||
await connection.query(` | ||
UPDATE guilds | ||
SET "custom-commands" = ${cArrayJson(customCommands)} | ||
WHERE id = ${cString(guild.id)}; | ||
`); | ||
} | ||
|
||
function cString(value: string) { | ||
const escaped = value.replace(/'/g, "''"); | ||
return `'${escaped}'`; | ||
} | ||
|
||
function cArrayJson(value: AnyObject[]) { | ||
return `ARRAY[${value.map(json => cString(JSON.stringify(json)))}]::JSON[]`; | ||
} | ||
|
||
export const DEPRECATED = false; | ||
export const DEPRECATED = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Pool } from 'pg'; | ||
|
||
export default async function main(PGSQL_DATABASE_OPTIONS: any) { | ||
const pgsql = new Pool(PGSQL_DATABASE_OPTIONS) | ||
.on('error', console.error); | ||
await pgsql.query(`ALTER TABLE moderation ADD COLUMN image_url VARCHAR(2000);`); | ||
await pgsql.end(); | ||
} | ||
|
||
export const DEPRECATED = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.