diff --git a/backend/src/data/Supporters.ts b/backend/src/data/Supporters.ts new file mode 100644 index 00000000..26c294c7 --- /dev/null +++ b/backend/src/data/Supporters.ts @@ -0,0 +1,16 @@ +import { BaseRepository } from "./BaseRepository"; +import { getRepository, Repository } from "typeorm"; +import { Supporter } from "./entities/Supporter"; + +export class Supporters extends BaseRepository { + private supporters: Repository; + + constructor() { + super(); + this.supporters = getRepository(Supporter); + } + + getAll() { + return this.supporters.find(); + } +} diff --git a/backend/src/data/entities/Supporter.ts b/backend/src/data/entities/Supporter.ts new file mode 100644 index 00000000..4189b087 --- /dev/null +++ b/backend/src/data/entities/Supporter.ts @@ -0,0 +1,14 @@ +import { Entity, Column, PrimaryColumn } from "typeorm"; + +@Entity("supporters") +export class Supporter { + @Column() + @PrimaryColumn() + user_id: string; + + @Column() + name: string; + + @Column() + amount: string | null; +} diff --git a/backend/src/migrations/1590616691907-CreateSupportersTable.ts b/backend/src/migrations/1590616691907-CreateSupportersTable.ts new file mode 100644 index 00000000..16273fbf --- /dev/null +++ b/backend/src/migrations/1590616691907-CreateSupportersTable.ts @@ -0,0 +1,36 @@ +import { MigrationInterface, QueryRunner, Table } from "typeorm"; + +export class CreateSupportersTable1590616691907 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: "supporters", + columns: [ + { + name: "user_id", + type: "bigint", + unsigned: true, + isPrimary: true, + }, + { + name: "name", + type: "varchar", + length: "255", + }, + { + name: "amount", + type: "decimal", + precision: 6, + scale: 2, + isNullable: true, + default: null, + }, + ], + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropTable("supporters"); + } +} diff --git a/backend/src/plugins/Utility.ts b/backend/src/plugins/Utility.ts index b2802682..d65a2cef 100644 --- a/backend/src/plugins/Utility.ts +++ b/backend/src/plugins/Utility.ts @@ -76,6 +76,7 @@ declare global { } import { Url, URL, URLSearchParams } from "url"; +import { Supporters } from "../data/Supporters"; const ConfigSchema = t.type({ can_roles: t.boolean, can_level: t.boolean, @@ -137,6 +138,7 @@ export class UtilityPlugin extends ZeppelinPlugin { protected cases: GuildCases; protected savedMessages: GuildSavedMessages; protected archives: GuildArchives; + protected supporters: Supporters; protected lastFullMemberRefresh = 0; protected fullMemberRefreshPromise; @@ -199,6 +201,7 @@ export class UtilityPlugin extends ZeppelinPlugin { this.cases = GuildCases.getGuildInstance(this.guildId); this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId); this.archives = GuildArchives.getGuildInstance(this.guildId); + this.supporters = new Supporters(); this.lastReload = Date.now(); @@ -1495,38 +1498,41 @@ export class UtilityPlugin extends ZeppelinPlugin { const loadedPlugins = Array.from(this.knub.getGuildData(this.guildId).loadedPlugins.keys()); loadedPlugins.sort(); - const supporters = [ - ["Flokie", 10], - ["CmdData", 1], - ["JackDaniel", 1], - ]; - supporters.sort(sorter(r => r[1], "DESC")); - const aboutContent: MessageContent = { embed: { title: `About ${this.bot.user.username}`, fields: [ { name: "Status", - value: - basicInfoRows - .map(([label, value]) => { - return `${label}: **${value}**`; - }) - .join("\n") + embedPadding, + value: basicInfoRows + .map(([label, value]) => { + return `${label}: **${value}**`; + }) + .join("\n"), }, { name: `Loaded plugins on this server (${loadedPlugins.length})`, value: loadedPlugins.join(", "), }, - { - name: "Zeppelin supporters 🎉", - value: supporters.map(s => `**${s[0]}** ${s[1]}€/mo`).join("\n"), - }, ], }, }; + const supporters = await this.supporters.getAll(); + supporters.sort( + multiSorter([ + [r => r.amount, "DESC"], + [r => r.name.toLowerCase(), "ASC"], + ]), + ); + + if (supporters.length) { + aboutContent.embed.fields.push({ + name: "Zeppelin supporters 🎉", + value: supporters.map(s => `**${s.name}** ${s.amount && `${s.amount}€/mo`}`).join("\n"), + }); + } + // For the embed color, find the highest colored role the bot has - this is their color on the server as well const botMember = await resolveMember(this.bot, this.guild, this.bot.user.id); let botRoles = botMember.roles.map(r => (msg.channel as GuildChannel).guild.roles.get(r));