mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add persist plugin
This commit is contained in:
parent
e7734c558c
commit
ad6afdfac1
10 changed files with 199 additions and 4 deletions
|
@ -13,7 +13,7 @@
|
|||
"MEMBER_ROLE_REMOVE": "🔑 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) role removed **{role.name}** by {mod.username}#{mod.discriminator}",
|
||||
"MEMBER_NICK_CHANGE": "✏ **{member.user.username}#{member.user.discriminator}** (`{member.id}`) changed their nickname from **{oldNick}** to **{newNick}**",
|
||||
"MEMBER_USERNAME_CHANGE": "✏ **{member.user.username}#{member.user.discriminator}** (`{member.id}`) changed their username from **{oldName}** to **{newName}**",
|
||||
"MEMBER_ROLES_RESTORE": "💿 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) roles were restored",
|
||||
"MEMBER_RESTORE": "💿 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) was restored",
|
||||
|
||||
"CHANNEL_CREATE": "🖊 Channel **#{channel.name}** was created",
|
||||
"CHANNEL_DELETE": "🗑 Channel **#{channel.name}** was deleted",
|
||||
|
|
53
src/data/GuildPersistedData.ts
Normal file
53
src/data/GuildPersistedData.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import knex from "../knex";
|
||||
import PersistedData from "../models/PersistedData";
|
||||
|
||||
export interface IPartialPersistData {
|
||||
roles?: string[];
|
||||
nickname?: string;
|
||||
is_voice_muted?: boolean;
|
||||
}
|
||||
|
||||
export class GuildPersistedData {
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
async find(userId: string) {
|
||||
const result = await knex("persisted_data")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("user_id", userId)
|
||||
.first();
|
||||
|
||||
return result ? new PersistedData(result) : null;
|
||||
}
|
||||
|
||||
async set(userId: string, data: IPartialPersistData = {}) {
|
||||
const finalData: any = {};
|
||||
if (data.roles) finalData.roles = data.roles.join(",");
|
||||
if (data.nickname) finalData.nickname = data.nickname;
|
||||
if (data.is_voice_muted) finalData.is_voice_muted = data.is_voice_muted ? 1 : 0;
|
||||
|
||||
const existing = await this.find(userId);
|
||||
if (existing) {
|
||||
await knex("persisted_data")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("user_id", userId)
|
||||
.update(finalData);
|
||||
} else {
|
||||
await knex("persisted_data").insert({
|
||||
...finalData,
|
||||
guild_id: this.guildId,
|
||||
user_id: userId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async clear(userId: string) {
|
||||
await knex("persisted_data")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("user_id", userId)
|
||||
.delete();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ export enum LogType {
|
|||
MEMBER_ROLE_REMOVE,
|
||||
MEMBER_NICK_CHANGE,
|
||||
MEMBER_USERNAME_CHANGE,
|
||||
MEMBER_ROLES_RESTORE,
|
||||
MEMBER_RESTORE,
|
||||
|
||||
CHANNEL_CREATE,
|
||||
CHANNEL_DELETE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue