Skip to content

Commit

Permalink
Merge pull request #24 from Wiibleyde/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Wiibleyde authored Oct 10, 2024
2 parents c99a8c9 + 31fcc62 commit 21636f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/commands/fun/quiz/quiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,8 @@ export async function reportQuestionModal(interaction: ModalSubmitInteraction) {

await channel.send({ content: `<@${config.OWNER_ID}>, report de : <@${user.id}>`, embeds: [embed] })
await interaction.reply({ embeds: [successEmbed(interaction, "Question signalée")], ephemeral: true })
}

export function isMessageQuizQuestion(messageId: string) {
return quizes.has(messageId)
}
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActivityType, Client, EmbedBuilder, Events, GatewayIntentBits, Partials } from "discord.js"
import { ActivityType, Client, EmbedBuilder, Events, GatewayIntentBits, MessageType, Partials } from "discord.js"
import { deployCommands, deployDevCommands } from "./deploy-commands"
import { errorEmbed } from "./utils/embeds"
import { config } from "./config"
Expand All @@ -10,6 +10,7 @@ import { initAi, generateWithGoogle } from "./utils/intelligence"
import { maintenance } from "./commands/dev/maintenance"
import { PermissionUtils } from "./utils/permissionTester"
import { backSpace } from "./utils/textUtils"
import { isMessageQuizQuestion } from "./commands/fun/quiz/quiz"

export const client = new Client({
intents: [
Expand Down Expand Up @@ -98,11 +99,15 @@ client.on(Events.MessageCreate, async (message) => {
return
}

if (message.mentions.has(client.user?.id as string)) {
// if(message.type === MessageType.Reply) {
// const contentOfReply = message.reference?.messageId ? await message.channel.messages.fetch(message.reference.messageId).then(msg => msg.content) : ''
// message.content = contentOfReply + message.content
// }
if (message.mentions.has(client.user?.id as string) && !message.mentions.everyone) {
if(message.type === MessageType.Reply) {
if(isMessageQuizQuestion(message.reference?.messageId as string)) {
return
}
// const contentOfReply = message.reference?.messageId ? await message.channel.messages.fetch(message.reference.messageId).then(msg => msg.content) : ''
// message.content = contentOfReply + message.content
}
message.channel.sendTyping()
const aiReponse = await generateWithGoogle(channelId, message.content.replace(`<@${client.user?.id}> `, ''), message.author.id).catch(async (error) => {
return `Je ne suis pas en mesure de répondre à cette question pour le moment. ||(${error.message})|| (Conversation réinitialisée)`
}).then(async (response) => {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/intelligence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export function generateWithGoogle(channelId:string, prompt: string, userAsking:
try {
currentChatSession?.sendMessage(`<@${userAsking}> écrit : ${prompt}`).then((response) => {
resolve(response.response.text())
}).catch((error) => {
chats.delete(channelId)
reject("Je ne suis pas en mesure de répondre à cette question pour le moment. ||(" + error.message + ")|| (Conversation réinitialisée)")
if (response && response.response && response.response.candidates) {
logger.error(response.response.candidates[0].safetyRatings)
}
})
} catch (error) {
if (response && response.response && response.response.candidates) {
Expand Down

0 comments on commit 21636f6

Please sign in to comment.