mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add time_and_date plugin. Use it for timezones and date formats around the bot.
This commit is contained in:
parent
cffb0dbd6b
commit
4ae8cf85a3
67 changed files with 543 additions and 177 deletions
48
backend/src/data/GuildMemberTimezones.ts
Normal file
48
backend/src/data/GuildMemberTimezones.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { MemberTimezone } from "./entities/MemberTimezone";
|
||||
import { getRepository, Repository } from "typeorm/index";
|
||||
import { connection } from "./db";
|
||||
|
||||
export class GuildMemberTimezones extends BaseGuildRepository {
|
||||
protected memberTimezones: Repository<MemberTimezone>;
|
||||
|
||||
constructor(guildId: string) {
|
||||
super(guildId);
|
||||
this.memberTimezones = getRepository(MemberTimezone);
|
||||
}
|
||||
|
||||
get(memberId: string) {
|
||||
return this.memberTimezones.findOne({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
});
|
||||
}
|
||||
|
||||
async set(memberId, timezone: string) {
|
||||
await connection.transaction(async entityManager => {
|
||||
const repo = entityManager.getRepository(MemberTimezone);
|
||||
const existingRow = await repo.findOne({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
});
|
||||
|
||||
if (existingRow) {
|
||||
await repo.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
},
|
||||
{
|
||||
timezone,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await repo.insert({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
timezone,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue