Skip to content

Commit

Permalink
🚀 release: v2.0.9
Browse files Browse the repository at this point in the history
Merge pull request #89 from thirdweb-dev/v2
  • Loading branch information
warengonzaga authored Mar 11, 2024
2 parents 2d33507 + 983db4d commit 9202e61
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thirdweb-support-discord-bot",
"version": "2.0.8",
"version": "2.0.9",
"description": "A self-hosted dedicated forum-based support Discord bot for the thirdweb community.",
"main": "src/bot.ts",
"author": "Waren Gonzaga",
Expand Down
69 changes: 46 additions & 23 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,57 @@ client.on("messageCreate", async (message) => {
// respond to ask command
if ((message.content.startsWith('!askai') || message.content.startsWith('!ask'))) {
let question = message.content.startsWith('!askai') ? message.content.slice(6) : message.content.slice(4);
if (message.channel.id === ASKAI_CHANNEL) {
let aiMessageLoading = await message.channel.send({
embeds: [
sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + `<a:load:1210497921158619136> thinking...`),
],
});

try {
const query = await context.query({
botId: CONTEXT_ID,
query: question
});
const gettingStartedASKAI = `Hello, kindly use \`!ask\` or \`!askai\` followed by your question to get started.`;

const msg = await message.channel.messages.fetch(aiMessageLoading.id);
await msg.edit({
content: `Hey <@${message.author.id}> 👇`,
// check if there's a question, if not, send the getting started message, if there's a question, send the response
if (!question) {
message.reply({
content: `Hey <@${message.author.id}> 👇`,
embeds: [sendEmbedMessage(gettingStartedASKAI)],
});
} else {
if (message.channel.id === ASKAI_CHANNEL) {
let aiMessageLoading = await message.channel.send({
embeds: [
sendEmbedMessage(`**Response:**\n${query.output.toString()}`),
sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + `<a:load:1210497921158619136> thinking...`),
],
});
} catch (error) {
console.error(error);

try {
const query = await context.query({
botId: CONTEXT_ID,
query: question
});

if (query && query.output) {
const msg = await message.channel.messages.fetch(aiMessageLoading.id);
await msg.edit({
content: `Hey <@${message.author.id}> 👇`,
embeds: [
sendEmbedMessage(`**Response:**\n${query.output.toString()}`),
],
});
} else {
console.error('[Error]: query or query.output is undefined');
console.log(query);
const msg = await message.channel.messages.fetch(aiMessageLoading.id);
await msg.edit({
content: `Hey <@${message.author.id}> 👇`,
embeds: [
sendEmbedMessage(`**Response:**\nI'm sorry, I couldn't find a response to your question. Please try again later.`),
],
});
}
} catch (error) {
console.error(error);
}
} else {
// if the command is not from the channel
message.reply({
content: `Hey <@${message.author.id}> 👇`,
embeds: [sendEmbedMessage(`You can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Just type your question after the command \`!askai\` or \`!ask\` to get started.`)],
});
}
} else {
message.reply({
content: `Hey <@${message.author.id}> 👇`,
embeds: [sendEmbedMessage(`You can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Just type your question after the command \`!askai\` or \`!ask\` to get started.`)],
});
}
}
// respond to user if the bot mentioned specifically not with everyone
Expand Down

0 comments on commit 9202e61

Please sign in to comment.