From 573d8ba289733fc1ab3c09a75de4978a86f74e16 Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 7 Aug 2024 13:09:52 +0300 Subject: [PATCH] Changed mechanism of chosing sex of profile and removed unneded console.logs --- messages.json | 4 ++-- src/db.js | 13 ++++++++----- src/index.js | 18 ++++++++++-------- src/interactions.js | 4 ---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/messages.json b/messages.json index bd35328..5abc236 100644 --- a/messages.json +++ b/messages.json @@ -1,7 +1,7 @@ { "general": { - "welcome": "Hello! I am a bot for new meetings in Matrix!\nI'll ask some questions to fill your profile. You can change that info later, if you will.\nThen, I'll start showing you another people's profiles.\nYou can like other profile, skip or send a message to the person.\nIf you mutually liked each other, you'll be given each other's MXID to start a DM.\nMy source code can be found on gitea: https://git.foxarmy.org/leca/heart2heart.\n\nGood luck!", - "rate": "Decide wether you like (👍️ or ❤️), dislike (👎️ or 💔) or wanna send a messsage (💌). Write '🏠️' to quit to menu. Any other response counts as dislike.", + "welcome": "Hello! I am a bot for new meetings in Matrix!\nTo start, please, type \"!start\"\nI'll ask some questions to fill your profile. You can change that info later, if you will.\nThen, I'll start showing you another people's profiles.\nYou can like other profile, skip or send a message to the person.\nIf you mutually liked each other, you'll be given each other's MXID to start a DM.\nMy source code can be found on gitea: https://git.foxarmy.org/leca/heart2heart.\n\nGood luck!", + "rate": "Decide wether you like (👍️, ❤️ or 1), dislike (👎️, 💔 or 2) or wanna send a messsage (💌 or 3). Write '🏠️' or 4 to quit to menu. Any other response counts as dislike.", "menu": "Pick an action:\n1) Start watching profiles\n2) Check for mutual likes\n3) Check for messages", "newlikes": "You have new mutual like(s)! Go into menu (🏠️) to see!", "showalike": "This person and you mutually liked each other!", diff --git a/src/db.js b/src/db.js index 19d99ae..e136a7d 100644 --- a/src/db.js +++ b/src/db.js @@ -50,18 +50,20 @@ const eraseUserMedia = async (roomId) => { } const selectProfilesForUser = async (roomId) => { - let interest = (await db.query("SELECT interest FROM users WHERE room_id = $1", [roomId])).rows[0].interest + let myInterest = (await db.query("SELECT interest FROM users WHERE room_id = $1", [roomId])).rows[0].interest + let mySex = (await db.query("SELECT sex FROM users WHERE room_id = $1", [roomId])).rows[0].sex let userAge = (await db.query("SELECT age FROM users WHERE room_id = $1", [roomId])).rows[0].age //Selecting profiles other than user's and with difference in age +-2. let user - if (interest === 'b') // both, no matter what sex + if (myInterest === 'b') // both, no matter what sex user = (await db.query(`SELECT room_id, name, age, sex, description, country, city FROM users WHERE age::numeric <@ ANY(ARRAY[numrange($1 - 2, $1 + 2)]) - AND room_id != $2 + AND room_id != $2 + AND (interest = $3 OR interest = 'b') ORDER BY RANDOM() - LIMIT 1`, [userAge, roomId]) + LIMIT 1`, [userAge, roomId, mySex]) ).rows[0] else { user = (await db.query(`SELECT @@ -70,8 +72,9 @@ const selectProfilesForUser = async (roomId) => { age::numeric <@ ANY(ARRAY[numrange($1 - 2, $1 + 2)]) AND room_id != $2 AND sex = $3 + AND (interest = $4 OR interest = 'b') ORDER BY RANDOM() - LIMIT 1`, [userAge, roomId, interest]) + LIMIT 1`, [userAge, roomId, myInterest, mySex]) ).rows[0] } if (!user) return null diff --git a/src/index.js b/src/index.js index ca819bc..42d621c 100644 --- a/src/index.js +++ b/src/index.js @@ -54,6 +54,12 @@ client.on("room.message", async (roomId, event) => { let answer = event.content.body; switch (current_action) { + case "wait_start": + if (answer !== "!start") return; + await setUserState(roomId, "country"); + await client.sendText(roomId, messages.setup.country); + + break; case "country": await processRequest(client, roomId, current_action, answer, 'city'); break; @@ -111,8 +117,6 @@ client.on("room.message", async (roomId, event) => { } else { const message = new MessageEvent(event); const fileEvent = new MessageEvent(message.raw); - console.log(event) - console.log(fileEvent) const decrypted = await client.crypto.decryptMedia(fileEvent.content.file); const mxc = await client.uploadContent(decrypted); let type; @@ -135,18 +139,17 @@ client.on("room.message", async (roomId, event) => { } break; case "view_profiles": - if (answer == '👍️' || answer == '❤️') { + if (answer == '👍️' || answer == '❤️' || answer == '1') { let currently_viewing = await getUserCurrentlyViewingProfile(roomId) await appendUserLikes(roomId, currently_viewing); let value = await checkForMutualLike(roomId, currently_viewing); - console.log(value) if (value) { await client.sendText(roomId, messages.general.newlikes); await client.sendText(currently_viewing, messages.general.newlikes); } - } else if (answer == '💌') { + } else if (answer == '💌' || answer == '3') { await client.sendText(roomId, messages.errors.notimplemented); - } else if (answer == '🏠️') { + } else if (answer == '🏠️' || answer == '4') { await client.sendText(roomId, messages.general.menu); await setUserState(roomId, 'menu') return @@ -204,10 +207,9 @@ client.on("room.invite", async (roomId, event) => { let is_profile_exists = (await db.query("SELECT * FROM users WHERE room_id = $1", [roomId])).rowCount > 0; if (!is_profile_exists) { - await db.query("INSERT INTO users(mx_id, room_id, current_action) VALUES ($1, $2, $3)", [mx_id, roomId, "country"]) + await db.query("INSERT INTO users(mx_id, room_id, current_action) VALUES ($1, $2, $3)", [mx_id, roomId, "wait_start"]) await client.sendText(roomId, messages.general.welcome); - await client.sendText(roomId, messages.setup.country); } else { setUserState(roomId, 'view_profiles') } diff --git a/src/interactions.js b/src/interactions.js index 9ac78b0..97784b6 100644 --- a/src/interactions.js +++ b/src/interactions.js @@ -52,7 +52,6 @@ ${chosenProfile.description}` if (chosenProfile.media) { for (let media of chosenProfile.media) { - console.log(media) let msgtype if (media.type == 'p') { msgtype = "m.image" @@ -73,7 +72,6 @@ ${chosenProfile.description}` const showProfileToUser = async (client, roomId, profileId) => { let profileInfo = await getProfileInfo(profileId); - console.log(profileInfo) let message = `${profileInfo.country}, ${profileInfo.city}. ${profileInfo.name}, ${profileInfo.sex == 'm' ? 'male' : 'female'}, ${profileInfo.age}. @@ -84,7 +82,6 @@ ${profileInfo.description}` if (profileInfo.media) { for (let media of profileInfo.media) { - console.log(media) let msgtype if (media.type == 'p') { msgtype = "m.image" @@ -105,7 +102,6 @@ ${profileInfo.description}` const showNewLikes = async (client, roomId) => { let likes = (await getAllLikesForUser(roomId)); for (let liked of likes) { - console.log(await checkForMutualLike(liked.sender, roomId)) if (await checkForMutualLike(liked.sender, roomId)) { await showProfileToUser(client, roomId, liked.sender); await markLikeAsRead(liked.sender, roomId);