mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add Tags plugin
This commit is contained in:
parent
54b79ca51f
commit
4a1a14be59
6 changed files with 158 additions and 5 deletions
48
src/data/GuildTags.ts
Normal file
48
src/data/GuildTags.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import knex from "../knex";
|
||||
import moment from "moment-timezone";
|
||||
import Tag from "../models/Tag";
|
||||
|
||||
export class GuildTags {
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
async find(tag): Promise<Tag> {
|
||||
const result = await knex("tags")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("tag", tag)
|
||||
.first();
|
||||
|
||||
return result ? new Tag(result) : null;
|
||||
}
|
||||
|
||||
async createOrUpdate(tag, body, userId) {
|
||||
const existingTag = await this.find(tag);
|
||||
if (existingTag) {
|
||||
await knex("tags")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("tag", tag)
|
||||
.update({
|
||||
body,
|
||||
user_id: userId,
|
||||
created_at: knex.raw("NOW()")
|
||||
});
|
||||
} else {
|
||||
await knex("tags").insert({
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
tag,
|
||||
body
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async delete(tag) {
|
||||
await knex("tags")
|
||||
.where("guild_id", this.guildId)
|
||||
.where("tag", tag)
|
||||
.delete();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue