3
0
Fork 0
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:
Dragory 2020-08-19 00:19:12 +03:00
parent cffb0dbd6b
commit 4ae8cf85a3
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
67 changed files with 543 additions and 177 deletions

View 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,
});
}
});
}
}