Store supporters in the database

This commit is contained in:
Dragory 2020-05-28 01:29:51 +03:00
parent cb4beacf8a
commit f9568ab37b
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 89 additions and 17 deletions

View 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();
}
}

View 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;
}

View file

@ -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");
}
}

View file

@ -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<TConfigSchema> {
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<TConfigSchema> {
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<TConfigSchema> {
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));