-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,44 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const { OpenAI } = require("openai"); | ||
import 'dotenv/config'; | ||
import { SlashCommandBuilder } from 'discord.js'; | ||
import { OpenAI } from 'openai'; | ||
import { splitString } from '../../utils.js'; | ||
|
||
const openai = new OpenAI({ | ||
apiKey: process.env['OPENAI_API_KEY'], | ||
Check failure on line 7 in commands/core/dump.js GitHub Actions / test (18)
Check failure on line 7 in commands/core/dump.js GitHub Actions / lint
Check failure on line 7 in commands/core/dump.js GitHub Actions / test (20)
|
||
}); | ||
|
||
function splitString(str, length) { | ||
if (length <= 0) { | ||
throw new Error('Length must be greater than 0'); | ||
} | ||
|
||
const segments = []; | ||
for (let i = 0; i < str.length; i += length) { | ||
segments.push(str.slice(i, i + length)); | ||
} | ||
|
||
return segments; | ||
} | ||
export const data = new SlashCommandBuilder().setName('dump').setDescription('Dump messages from an OpenAI thread into a Discord thread.').addStringOption((option) => option.setName('thread').setDescription('OpenAI thread ID.').setRequired(true)); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('dump') | ||
.setDescription('Dump messages from an OpenAI thread.') | ||
.addStringOption((option) => option.setName('thread').setDescription('OpenAI thread ID.').setRequired(true)), | ||
async execute(interaction) { | ||
await interaction.deferReply(); | ||
export async function execute(interaction) { | ||
await interaction.deferReply(); | ||
|
||
const openaiThreadId = interaction.options.getString('thread'); | ||
console.log(openaiThreadId); | ||
const openaiThreadId = interaction.options.getString('thread'); | ||
console.log(openaiThreadId); | ||
|
||
const messagesList = await openai.beta.threads.messages.list(openaiThreadId); | ||
console.log("Messages List:", messagesList); | ||
const messagesList = await openai.beta.threads.messages.list(openaiThreadId); | ||
console.log("Messages List:", messagesList); | ||
|
||
const messages = Array.from(messagesList.data).map(msg => msg.content).reverse(); | ||
console.log(messages); | ||
const messages = Array.from(messagesList.data).map(msg => msg.content).reverse(); | ||
console.log(messages); | ||
|
||
for await (const msg of messages) { | ||
let content = null; | ||
if (msg[0].text) { | ||
content = msg[0].text.value; | ||
console.log("Content:", content); | ||
const replies = splitString(content, 2000); | ||
for (let i = 0; i < replies.length; i++) { | ||
console.log(replies[i]); | ||
await interaction.followUp({ content: replies[i] }); | ||
} | ||
} else if (msg[0].image_file) { | ||
const image = msg[0].image_file; | ||
console.log("Image file:", image); | ||
await interaction.followUp({ content: image }); | ||
} else if (msg[0].image_url) { | ||
const image = msg[0].image_url; | ||
console.log("Image url:", image); | ||
await interaction.followUp({ content: image }); | ||
for await (const msg of messages) { | ||
let content = null; | ||
if (msg[0].text) { | ||
content = msg[0].text.value; | ||
console.log("Content:", content); | ||
const replies = splitString(content, 2000); | ||
for (let i = 0; i < replies.length; i++) { | ||
console.log(replies[i]); | ||
await interaction.followUp({ content: replies[i] }); | ||
} | ||
} else if (msg[0].image_file) { | ||
const image = msg[0].image_file; | ||
console.log("Image file:", image); | ||
await interaction.followUp({ content: image }); | ||
} else if (msg[0].image_url) { | ||
const image = msg[0].image_url; | ||
console.log("Image url:", image); | ||
await interaction.followUp({ content: image }); | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SlashCommandBuilder } from 'discord.js'; | ||
|
||
export const data = new SlashCommandBuilder().setName('info').setDescription('Display app information'); | ||
|
||
export async function execute(interaction) { | ||
await interaction.deferReply({ ephemeral: true }); | ||
const content = "App info."; | ||
await interaction.followUp({ content: content, ephemeral: true }); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const { OpenAI } = require("openai"); | ||
import 'dotenv/config'; | ||
import { SlashCommandBuilder } from 'discord.js'; | ||
import { OpenAI } from 'openai'; | ||
|
||
const openai = new OpenAI({ | ||
apiKey: process.env['OPENAI_API_KEY'], | ||
Check failure on line 6 in commands/core/list.js GitHub Actions / test (18)
Check failure on line 6 in commands/core/list.js GitHub Actions / lint
Check failure on line 6 in commands/core/list.js GitHub Actions / test (20)
|
||
}); | ||
|
||
const getAssistants = async () => { | ||
const payload = await openai.beta.assistants.list(); | ||
return Array.from(payload.data).map(msg => msg.name); | ||
// console.log(payload); | ||
const data = []; | ||
for (let i = 0; i < payload.data.length; i++) { | ||
console.log(payload.data[i]); | ||
const text = payload.data[i].name + " " + "(" + payload.data[i].model + ")"; | ||
data.push(text); | ||
} | ||
return data; | ||
} | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('list') | ||
.setDescription('List all available OpenAI assistants.'), | ||
async execute(interaction) { | ||
await interaction.deferReply(); | ||
export const data = new SlashCommandBuilder().setName('list').setDescription('List all available OpenAI assistants.'); | ||
|
||
const assistants = await getAssistants(); | ||
const reply = assistants.join("\n"); | ||
export async function execute(interaction) { | ||
await interaction.deferReply(); | ||
|
||
await interaction.followUp({ content: reply, ephemeral: true }); | ||
}, | ||
}; | ||
const assistants = await getAssistants(); | ||
console.log(assistants); | ||
const reply = assistants.join("\n"); | ||
|
||
await interaction.followUp({ content: reply, ephemeral: true }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
import { SlashCommandBuilder } from 'discord.js'; | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('ping') | ||
.setDescription('Send a ping.'), | ||
async execute(interaction) { | ||
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true, ephemeral: true }); | ||
export const data = new SlashCommandBuilder().setName('ping').setDescription('Send a ping.'); | ||
|
||
await interaction.editReply(`Round-trip latency: ${sent.createdTimestamp - interaction.createdTimestamp}ms`); | ||
}, | ||
export async function execute(interaction) { | ||
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true, ephemeral: true }); | ||
await interaction.editReply(`Round-trip latency: ${sent.createdTimestamp - interaction.createdTimestamp}ms`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ContextMenuCommandBuilder, ApplicationCommandType } from 'discord.js'; | ||
|
||
export const data = new ContextMenuCommandBuilder().setName('Profile').setType(ApplicationCommandType.User); | ||
|
||
export async function execute(interaction) { | ||
if (!interaction.isUserContextMenuCommand()) return; | ||
|
||
await interaction.deferReply({ ephemeral: true }); | ||
|
||
const username = interaction.user.username; | ||
console.log(username); | ||
|
||
await interaction.followUp({ content: username, ephemeral: true }); | ||
}; |
This file was deleted.