mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add reminders
This commit is contained in:
parent
b5c55f9510
commit
6491c48289
9 changed files with 384 additions and 10 deletions
46
src/data/GuildReminders.ts
Normal file
46
src/data/GuildReminders.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { Reminder } from "./entities/Reminder";
|
||||
|
||||
export class GuildReminders extends BaseRepository {
|
||||
private reminders: Repository<Reminder>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.reminders = getRepository(Reminder);
|
||||
}
|
||||
|
||||
async getDueReminders(): Promise<Reminder[]> {
|
||||
return this.reminders
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guildId", { guildId: this.guildId })
|
||||
.andWhere("remind_at <= NOW()")
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async getRemindersByUserId(userId: string): Promise<Reminder[]> {
|
||||
return this.reminders.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
await this.reminders.delete({
|
||||
guild_id: this.guildId,
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
||||
async add(userId: string, channelId: string, remindAt: string, body: string) {
|
||||
await this.reminders.insert({
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
channel_id: channelId,
|
||||
remind_at: remindAt,
|
||||
body,
|
||||
});
|
||||
}
|
||||
}
|
18
src/data/entities/Reminder.ts
Normal file
18
src/data/entities/Reminder.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Entity, Column, PrimaryColumn } from "typeorm";
|
||||
|
||||
@Entity("reminders")
|
||||
export class Reminder {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column() guild_id: string;
|
||||
|
||||
@Column() user_id: string;
|
||||
|
||||
@Column() channel_id: string;
|
||||
|
||||
@Column() remind_at: string;
|
||||
|
||||
@Column() body: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue