
Since voice mutes cannot be re-applied unless the member is in voice, we can't re-apply the voice mute automatically on join and would have to do it later when they first join voice, which could get messy if they were not supposed to be voice muted anymore after all (if they e.g. don't use voice for a long time).
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { PersistedData } from "./entities/PersistedData";
|
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
|
import { getRepository, Repository } from "typeorm";
|
|
|
|
export interface IPartialPersistData {
|
|
roles?: string[];
|
|
nickname?: string;
|
|
}
|
|
|
|
export class GuildPersistedData extends BaseGuildRepository {
|
|
private persistedData: Repository<PersistedData>;
|
|
|
|
constructor(guildId) {
|
|
super(guildId);
|
|
this.persistedData = getRepository(PersistedData);
|
|
}
|
|
|
|
async find(userId: string) {
|
|
return this.persistedData.findOne({
|
|
where: {
|
|
guild_id: this.guildId,
|
|
user_id: userId,
|
|
},
|
|
});
|
|
}
|
|
|
|
async set(userId: string, data: IPartialPersistData = {}) {
|
|
const finalData: any = {};
|
|
if (data.roles) finalData.roles = data.roles.join(",");
|
|
if (data.nickname) finalData.nickname = data.nickname;
|
|
|
|
const existing = await this.find(userId);
|
|
if (existing) {
|
|
await this.persistedData.update(
|
|
{
|
|
guild_id: this.guildId,
|
|
user_id: userId,
|
|
},
|
|
finalData,
|
|
);
|
|
} else {
|
|
await this.persistedData.insert({
|
|
...finalData,
|
|
guild_id: this.guildId,
|
|
user_id: userId,
|
|
});
|
|
}
|
|
}
|
|
|
|
async clear(userId: string) {
|
|
await this.persistedData.delete({
|
|
guild_id: this.guildId,
|
|
user_id: userId,
|
|
});
|
|
}
|
|
}
|