Changed mechanism of chosing sex of profile and removed unneded console.logs

This commit is contained in:
leca 2024-08-07 13:09:52 +03:00
parent f79192dc89
commit 573d8ba289
4 changed files with 20 additions and 19 deletions

View File

@ -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!",

View File

@ -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 (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

View File

@ -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')
}

View File

@ -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);