Skip to content

Commit

Permalink
feat: small option to Summarizer command (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored May 23, 2023
1 parent ac80ca4 commit 927ed4d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"dependencies": {
"@effect-http/client": "^0.26.1",
"@effect/data": "^0.12.2",
"@effect/io": "^0.25.12",
"@effect/io": "^0.25.13",
"@effect/stream": "^0.21.1",
"dfx": "^0.45.8",
"dfx": "^0.45.9",
"dotenv": "^16.0.3",
"openai": "^3.2.1"
}
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 51 additions & 25 deletions src/Summarizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const make = Effect.gen(function* (_) {
channel: Discord.Channel,
thread: Discord.Channel,
messages: Chunk.Chunk<Discord.Message>,
small: boolean,
) =>
Effect.map(
Effect.forEachParWithIndex(messages, (message, index) => {
Expand All @@ -94,7 +95,7 @@ const make = Effect.gen(function* (_) {
index => [Chunk.unsafeGet(messages, index), index + 1] as const,
),
)
return summarizeMessage(thread, index + 1, message, reply)
return summarizeMessage(thread, index + 1, message, reply, small)
}),
messageContent =>
`# ${thread.name}
Expand All @@ -112,18 +113,27 @@ ${messageContent.join("\n\n")}`,
index: number,
message: Discord.Message,
replyTo: Option.Option<readonly [Discord.Message, number]>,
small: boolean,
) =>
Effect.gen(function* (_) {
const user = message.author
const member = yield* _(members.get(thread.guild_id!, message.author.id))
const username = member.nick ?? user.username
const content = `${index}: **${username}**${Option.match(

const smallOpen = small ? "<small>" : ""
const smallClose = small ? "</small>" : ""

const reply = Option.match(
replyTo,
() => "",
([, index]) => ` (replying to \\#${index})`,
)} <small>&mdash; ${new Date(
)

const header = `${smallOpen}${smallOpen}${index}: **${username}**${reply} ${smallOpen}&mdash; ${new Date(
message.timestamp,
).toUTCString()}</small><br />
).toUTCString()}${smallClose}${smallClose}${smallClose}`

const content = `${header}<br />
${message.content
.replace(/```ts\b/g, "```typescript")
.replace(/^```/, "\n```")
Expand Down Expand Up @@ -156,6 +166,7 @@ ${message.content
const followUpResponse = (
context: Discord.Interaction,
channel: Discord.Channel,
small: boolean,
) =>
pipe(
Effect.all({
Expand All @@ -168,7 +179,7 @@ ${message.content
),
),
Effect.bind("summary", ({ parentChannel, messages }) =>
summarize(parentChannel, channel, messages),
summarize(parentChannel, channel, messages, small),
),
Effect.tap(({ summary }) => {
const formData = new FormData()
Expand Down Expand Up @@ -205,29 +216,44 @@ ${message.content
{
name: "summarize",
description: "Create a summary of the current thread",
options: [
{
type: Discord.ApplicationCommandOptionType.BOOLEAN,
name: "small",
description: "Add <small> tags to the message headers",
required: false,
},
],
},
pipe(
Effect.all({ context: Ix.Interaction }),
Effect.bind("channel", ({ context }) =>
channels.get(context.guild_id!, context.channel_id!),
),
Effect.filterOrFail(
({ channel }) => channel.type === Discord.ChannelType.PUBLIC_THREAD,
() => new NotInThreadError(),
),
Effect.tap(({ context, channel }) =>
Effect.forkIn(followUpResponse(context, channel), scope),
),
Effect.as(
Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Creating summary...",
flags: Discord.MessageFlag.EPHEMERAL,
},
ix =>
pipe(
Effect.all({
context: Ix.Interaction,
small: Effect.map(
ix.optionValueOptional("small"),
Option.getOrElse(() => true),
),
}),
Effect.bind("channel", ({ context }) =>
channels.get(context.guild_id!, context.channel_id!),
),
Effect.filterOrFail(
({ channel }) => channel.type === Discord.ChannelType.PUBLIC_THREAD,
() => new NotInThreadError(),
),
Effect.tap(({ context, channel, small }) =>
Effect.forkIn(followUpResponse(context, channel, small), scope),
),
Effect.as(
Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Creating summary...",
flags: Discord.MessageFlag.EPHEMERAL,
},
}),
),
),
),
)

const ix = Ix.builder
Expand Down

0 comments on commit 927ed4d

Please sign in to comment.