-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: Refactor with RAS Architecture (#42)
* Reform with RAS * Fix tests * Remove condition of not replying * Fix incorrect handling * Short catch callback * Bump version * Move SayingLoader * Add Scheduler * Move SubscriptionNotifier * Refactor around notification system * Fix tests * Fix and Add kilAll * Fix to kill
- Loading branch information
1 parent
0782204
commit 9c28dae
Showing
80 changed files
with
1,497 additions
and
1,443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable new-cap */ | ||
|
||
import fauna, { query as q } from "faunadb"; | ||
import type { DiscordId } from "../model/discord-id"; | ||
import type { GitHubUser } from "../model/github-user"; | ||
import type { NotificationId } from "../model/github-notification"; | ||
import type { SubscriberRepository } from "../services/notify"; | ||
|
||
export class FaunaDB implements SubscriberRepository { | ||
private client: fauna.Client; | ||
|
||
constructor(secret: string) { | ||
this.client = new fauna.Client({ secret }); | ||
} | ||
|
||
async updateNotifications( | ||
id: DiscordId, | ||
notificationIds: readonly NotificationId[], | ||
): Promise<void> { | ||
await this.client.query( | ||
q.Update(q.Ref(q.Collection("users"), id), { | ||
data: { currentNotificationIds: notificationIds }, | ||
}), | ||
); | ||
} | ||
|
||
async register(id: DiscordId, user: GitHubUser): Promise<void> { | ||
try { | ||
await this.client.query( | ||
q.Create(q.Ref(q.Collection("users"), id), { data: { ...user } }), | ||
); | ||
} catch (ignore) { | ||
// Ignore | ||
} | ||
} | ||
|
||
async unregister(id: DiscordId): Promise<boolean> { | ||
try { | ||
await this.client.query(q.Delete(q.Ref(q.Collection("users"), id))); | ||
} catch (_err) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
async user(discordId: DiscordId): Promise<GitHubUser | null> { | ||
try { | ||
const { data } = (await this.client.query( | ||
q.Get(q.Ref(q.Collection("users"), discordId)), | ||
)) as { data: GitHubUser }; | ||
return data; | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { EmbedMessage } from "../model/message"; | ||
import { MessageEmbed } from "discord.js"; | ||
|
||
export const intoMessageEmbed = ({ | ||
author, | ||
color, | ||
description, | ||
fields, | ||
footer, | ||
title, | ||
url, | ||
}: EmbedMessage): MessageEmbed => { | ||
const embed = new MessageEmbed(); | ||
if (author) { | ||
embed.setAuthor(author.name, author.iconUrl, author.url); | ||
} | ||
if (color) { | ||
embed.setColor(color); | ||
} | ||
if (description) { | ||
embed.setDescription(description); | ||
} | ||
if (fields) { | ||
embed.setFields(fields); | ||
} | ||
if (footer) { | ||
embed.setFooter(footer); | ||
} | ||
if (title) { | ||
embed.setTitle(title); | ||
} | ||
if (url) { | ||
embed.setURL(url); | ||
} | ||
return embed; | ||
}; |
Oops, something went wrong.