3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Add post scheduling. Add cleaner post_embed syntax.

This commit is contained in:
Dragory 2019-05-04 18:41:50 +03:00
parent a761a4e550
commit e18193c1a2
7 changed files with 489 additions and 52 deletions

View file

@ -52,5 +52,8 @@
"CASE_UPDATE": "✏ {userMention(mod)} updated case #{caseNumber} ({caseType}) with note:\n```{note}```",
"MEMBER_MUTE_REJOIN": "⚠ Reapplied active mute for {userMention(member)} on rejoin"
"MEMBER_MUTE_REJOIN": "⚠ Reapplied active mute for {userMention(member)} on rejoin",
"SCHEDULED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {date} at {time} (UTC)",
"POSTED_SCHEDULED_MESSAGE": "\uD83D\uDCE8 Posted scheduled message (`{messageId}`) to {channelMention(channel)} as scheduled by {userMention(author)}"
}

View file

@ -0,0 +1,41 @@
import { BaseRepository } from "./BaseRepository";
import { getRepository, Repository } from "typeorm";
import { ScheduledPost } from "./entities/ScheduledPost";
export class GuildScheduledPosts extends BaseRepository {
private scheduledPosts: Repository<ScheduledPost>;
constructor(guildId) {
super(guildId);
this.scheduledPosts = getRepository(ScheduledPost);
}
all(): Promise<ScheduledPost[]> {
return this.scheduledPosts
.createQueryBuilder()
.where("guild_id = :guildId", { guildId: this.guildId })
.getMany();
}
getDueScheduledPosts(): Promise<ScheduledPost[]> {
return this.scheduledPosts
.createQueryBuilder()
.where("guild_id = :guildId", { guildId: this.guildId })
.andWhere("post_at <= NOW()")
.getMany();
}
async delete(id) {
await this.scheduledPosts.delete({
guild_id: this.guildId,
id,
});
}
async create(data: Partial<ScheduledPost>) {
await this.scheduledPosts.insert({
...data,
guild_id: this.guildId,
});
}
}

View file

@ -53,4 +53,7 @@ export enum LogType {
CASE_UPDATE,
MEMBER_MUTE_REJOIN,
SCHEDULED_MESSAGE,
POSTED_SCHEDULED_MESSAGE,
}

View file

@ -0,0 +1,26 @@
import { Entity, Column, PrimaryColumn } from "typeorm";
import { Attachment } from "eris";
import { StrictMessageContent } from "../../utils";
@Entity("scheduled_posts")
export class ScheduledPost {
@Column()
@PrimaryColumn()
id: number;
@Column() guild_id: string;
@Column() author_id: string;
@Column() author_name: string;
@Column() channel_id: string;
@Column("simple-json") content: StrictMessageContent;
@Column("simple-json") attachments: Attachment[];
@Column() post_at: string;
@Column() enable_mentions: boolean;
}