Store supporters in the database
This commit is contained in:
parent
cb4beacf8a
commit
f9568ab37b
4 changed files with 89 additions and 17 deletions
16
backend/src/data/Supporters.ts
Normal file
16
backend/src/data/Supporters.ts
Normal file
|
@ -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<Supporter>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.supporters = getRepository(Supporter);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAll() {
|
||||||
|
return this.supporters.find();
|
||||||
|
}
|
||||||
|
}
|
14
backend/src/data/entities/Supporter.ts
Normal file
14
backend/src/data/entities/Supporter.ts
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||||
|
|
||||||
|
export class CreateSupportersTable1590616691907 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||||
|
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<any> {
|
||||||
|
await queryRunner.dropTable("supporters");
|
||||||
|
}
|
||||||
|
}
|
|
@ -76,6 +76,7 @@ declare global {
|
||||||
}
|
}
|
||||||
|
|
||||||
import { Url, URL, URLSearchParams } from "url";
|
import { Url, URL, URLSearchParams } from "url";
|
||||||
|
import { Supporters } from "../data/Supporters";
|
||||||
const ConfigSchema = t.type({
|
const ConfigSchema = t.type({
|
||||||
can_roles: t.boolean,
|
can_roles: t.boolean,
|
||||||
can_level: t.boolean,
|
can_level: t.boolean,
|
||||||
|
@ -137,6 +138,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
protected cases: GuildCases;
|
protected cases: GuildCases;
|
||||||
protected savedMessages: GuildSavedMessages;
|
protected savedMessages: GuildSavedMessages;
|
||||||
protected archives: GuildArchives;
|
protected archives: GuildArchives;
|
||||||
|
protected supporters: Supporters;
|
||||||
|
|
||||||
protected lastFullMemberRefresh = 0;
|
protected lastFullMemberRefresh = 0;
|
||||||
protected fullMemberRefreshPromise;
|
protected fullMemberRefreshPromise;
|
||||||
|
@ -199,6 +201,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||||
|
this.supporters = new Supporters();
|
||||||
|
|
||||||
this.lastReload = Date.now();
|
this.lastReload = Date.now();
|
||||||
|
|
||||||
|
@ -1495,38 +1498,41 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
const loadedPlugins = Array.from(this.knub.getGuildData(this.guildId).loadedPlugins.keys());
|
const loadedPlugins = Array.from(this.knub.getGuildData(this.guildId).loadedPlugins.keys());
|
||||||
loadedPlugins.sort();
|
loadedPlugins.sort();
|
||||||
|
|
||||||
const supporters = [
|
|
||||||
["Flokie", 10],
|
|
||||||
["CmdData", 1],
|
|
||||||
["JackDaniel", 1],
|
|
||||||
];
|
|
||||||
supporters.sort(sorter(r => r[1], "DESC"));
|
|
||||||
|
|
||||||
const aboutContent: MessageContent = {
|
const aboutContent: MessageContent = {
|
||||||
embed: {
|
embed: {
|
||||||
title: `About ${this.bot.user.username}`,
|
title: `About ${this.bot.user.username}`,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "Status",
|
name: "Status",
|
||||||
value:
|
value: basicInfoRows
|
||||||
basicInfoRows
|
.map(([label, value]) => {
|
||||||
.map(([label, value]) => {
|
return `${label}: **${value}**`;
|
||||||
return `${label}: **${value}**`;
|
})
|
||||||
})
|
.join("\n"),
|
||||||
.join("\n") + embedPadding,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `Loaded plugins on this server (${loadedPlugins.length})`,
|
name: `Loaded plugins on this server (${loadedPlugins.length})`,
|
||||||
value: loadedPlugins.join(", "),
|
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
|
// 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);
|
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));
|
let botRoles = botMember.roles.map(r => (msg.channel as GuildChannel).guild.roles.get(r));
|
||||||
|
|
Loading…
Add table
Reference in a new issue