mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-17 15:15:02 +00:00
Create archives from bulk deletes and cleans. Use GuildSavedMessages for cleans.
This commit is contained in:
parent
4a65b94cc3
commit
2c561afe1a
9 changed files with 176 additions and 145 deletions
|
@ -77,16 +77,54 @@ export class GuildSavedMessages extends BaseRepository {
|
|||
.getOne();
|
||||
}
|
||||
|
||||
getUserMessagesByChannelAfterId(userId, channelId, afterId) {
|
||||
getLatestBotMessagesByChannel(channelId, limit) {
|
||||
return this.messages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.where("user_id = :user_id", { user_id: userId })
|
||||
.where("channel_id = :channel_id", { channel_id: channelId })
|
||||
.where("id > :afterId", { afterId })
|
||||
.andWhere("channel_id = :channel_id", { channel_id: channelId })
|
||||
.andWhere("is_bot = 1")
|
||||
.orderBy("id", "DESC")
|
||||
.limit(limit)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
getLatestByChannelBeforeId(channelId, beforeId, limit) {
|
||||
return this.messages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("channel_id = :channel_id", { channel_id: channelId })
|
||||
.andWhere("id < :beforeId", { beforeId })
|
||||
.orderBy("id", "DESC")
|
||||
.limit(limit)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
getLatestByChannelAndUser(channelId, userId, limit) {
|
||||
return this.messages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("channel_id = :channel_id", { channel_id: channelId })
|
||||
.andWhere("user_id = :user_id", { user_id: userId })
|
||||
.orderBy("id", "DESC")
|
||||
.limit(limit)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
getUserMessagesByChannelAfterId(userId, channelId, afterId, limit = null) {
|
||||
let query = this.messages
|
||||
.createQueryBuilder()
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("user_id = :user_id", { user_id: userId })
|
||||
.andWhere("channel_id = :channel_id", { channel_id: channelId })
|
||||
.andWhere("id > :afterId", { afterId });
|
||||
|
||||
if (limit != null) {
|
||||
query = query.limit(limit);
|
||||
}
|
||||
|
||||
return query.getMany();
|
||||
}
|
||||
|
||||
async create(data) {
|
||||
const isPermanent = this.toBePermanent.has(data.id);
|
||||
if (isPermanent) {
|
||||
|
@ -137,6 +175,23 @@ export class GuildSavedMessages extends BaseRepository {
|
|||
this.events.emit("delete", [deleted]);
|
||||
}
|
||||
|
||||
async markBulkAsDeleted(ids) {
|
||||
await this.messages
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({
|
||||
deleted_at: () => "NOW(3)"
|
||||
})
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("id IN (:ids)", { ids })
|
||||
.execute();
|
||||
|
||||
return this.messages
|
||||
.createQueryBuilder()
|
||||
.where("id IN (:ids)", { ids })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async saveEdit(id, newData: ISavedMessageData) {
|
||||
const oldMessage = await this.messages.findOne(id);
|
||||
const newMessage = { ...oldMessage, data: newData };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue