Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lechat): Add new presence #9271

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions websites/L/Le Chat/Le Chat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"leChat.startingPrompt": {
"description": "Displayed when the user is on the page to start a new prompt.",
"message": "Phrasing a new prompt..."
},
"leChat.talkingWithAi": {
"description": "Displayed when the user is engaging in a conversation with the AI and the Chat title is not shown",
"message": "Talking with AI about something"
},
"leChat.readingResponse": {
"description": "Displayed when the user is reading the response of the AI.",
"message": "Reading the AI's response"
},
"leChat.askingQuestion": {
"description": "Displayed when the user is asking a question.",
"message": "Asking a question..."
}
}
37 changes: 37 additions & 0 deletions websites/L/Le Chat/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://schemas.premid.app/metadata/1.13",
"apiVersion": 1,
"author": {
"id": "1167417152664522764",
"name": "kaktuswerk"
},
"service": "Le Chat",
"description": {
"en": "Le Chat is a conversational entry point to interact with the various models from Mistral AI. It offers a pedagogical and fun way to explore Mistral AI’s technology."
},
"url": "chat.mistral.ai",
"version": "1.0.0",
"logo": "https://i.imgur.com/CzKaHyo.png",
"thumbnail": "https://i.imgur.com/GYS9A0f.png",
"color": "#fc7703",
"category": "other",
"tags": [
"lechat",
"mistral",
"ai",
"chat",
"conversations"
],
"settings": [
{
"id": "lang",
"multiLanguage": true
},
{
"id": "showTitle",
"title": "Show chat title",
"icon": "fa-solid fa-message-quote",
"value": true
}
]
}
61 changes: 61 additions & 0 deletions websites/L/Le Chat/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const presence = new Presence({
clientId: '1338859356497641503',
})
async function getStrings() {
return presence.getStrings({
play: 'presence.playback.playing',
pause: 'presence.playback.paused',
newPrompt: 'leChat.startingPrompt',
talkingWithAi: 'leChat.talkingWithAi',
readingResponse: 'leChat.readingResponse',
askingQuestion: 'leChat.askingQuestion',
})
}
const browsingTimestamp = Math.floor(Date.now() / 1000)

enum Assets {
Logo = 'https://i.imgur.com/CzKaHyo.png',
}

presence.on('UpdateData', async () => {
const { pathname } = document.location
const showTitle = await presence.getSetting<boolean>('showTitle')

let presenceDetail: string, presenceState: string

const strings = await getStrings()

if (pathname === '/chat') {
presenceDetail = strings.newPrompt
}
else if (pathname.includes('/chat/')) {
presenceDetail = showTitle
? document.querySelector('a[aria-label="Open chat"]>div').textContent
: strings.talkingWithAi
}
else {
presenceDetail = strings.talkingWithAi
}

// Checking if the user is currently typing a question
if (document.querySelector('textarea').textContent !== '') {
presenceState = strings.askingQuestion
}
else if (
document.querySelector(
'div[class=\'flex h-fit w-full flex-col\'] > div:last-child[style*=\'transform:none\']',
)
) {
presenceState = strings.readingResponse
}
else {
presenceState = null
}

presence.setActivity({
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
details: presenceDetail,
state: presenceState,
})
})
Loading