-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
355 additions
and
27 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
import { | ||
Cache, | ||
Data, | ||
Duration, | ||
Effect, | ||
Layer, | ||
Request, | ||
RequestResolver, | ||
Tag, | ||
pipe, | ||
} from "bot/_common" | ||
import { Discord, DiscordREST } from "dfx" | ||
import { DiscordRESTError, ResponseDecodeError } from "dfx/DiscordREST" | ||
|
||
export class GetMember extends Data.TaggedClass("GetMember")<{ | ||
readonly guildId: Discord.Snowflake | ||
readonly userId: Discord.Snowflake | ||
}> {} | ||
|
||
const make = Effect.gen(function* (_) { | ||
const rest = yield* _(DiscordREST) | ||
|
||
interface GetMember | ||
extends Request.Request< | ||
DiscordRESTError | ResponseDecodeError, | ||
Discord.GuildMember | ||
> { | ||
readonly _tag: "GetMember" | ||
readonly guildId: Discord.Snowflake | ||
readonly userId: Discord.Snowflake | ||
} | ||
const GetMember = Request.tagged<GetMember>("GetMember") | ||
|
||
const resolver = RequestResolver.fromFunctionEffect( | ||
({ guildId, userId }: GetMember) => | ||
Effect.flatMap(rest.getGuildMember(guildId, userId), _ => _.json), | ||
) | ||
|
||
const cache = yield* _(Request.makeCache(1000, Duration.days(1))) | ||
|
||
return { | ||
get: (guildId: Discord.Snowflake, userId: Discord.Snowflake) => | ||
pipe( | ||
Effect.request(GetMember({ guildId, userId }), resolver), | ||
Effect.withRequestCache(cache), | ||
Effect.withRequestCaching("on"), | ||
), | ||
} as const | ||
}) | ||
|
||
export interface MemberCache extends Effect.Effect.Success<typeof make> {} | ||
export const MemberCache = Tag<MemberCache>() | ||
export const MemberCacheLive = Layer.effect(MemberCache, make) |
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
Oops, something went wrong.