handling nonexistent profiles
This commit is contained in:
parent
89a38be5d3
commit
dc6c438c73
10
db.drawio
10
db.drawio
|
@ -1,6 +1,6 @@
|
|||
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.7.6">
|
||||
<diagram id="R2lEEEUBdFMjLlhIrx00" name="Page-1">
|
||||
<mxGraphModel dx="752" dy="787" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0" extFonts="Permanent Marker^https://fonts.googleapis.com/css?family=Permanent+Marker">
|
||||
<mxGraphModel dx="1594" dy="712" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0" extFonts="Permanent Marker^https://fonts.googleapis.com/css?family=Permanent+Marker">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
|
@ -50,7 +50,7 @@
|
|||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-3" value="likes" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="680" y="140" width="140" height="120" as="geometry" />
|
||||
<mxGeometry x="480" y="130" width="140" height="120" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-4" value="sender VARCHAR(64)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" vertex="1" parent="ncYoQrePTnOtlZKuZZqN-3">
|
||||
<mxGeometry y="30" width="140" height="30" as="geometry" />
|
||||
|
@ -62,7 +62,7 @@
|
|||
<mxGeometry y="90" width="140" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-7" value="media" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="550" y="280" width="400" height="150" as="geometry" />
|
||||
<mxGeometry x="350" y="270" width="400" height="150" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-8" value="owner VARCHAR(64)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" vertex="1" parent="ncYoQrePTnOtlZKuZZqN-7">
|
||||
<mxGeometry y="30" width="400" height="30" as="geometry" />
|
||||
|
@ -95,7 +95,7 @@
|
|||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-18" value="messages" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="600" y="460" width="300" height="180" as="geometry" />
|
||||
<mxGeometry x="400" y="450" width="300" height="180" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-19" value="sender VARCHAR(64)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" vertex="1" parent="ncYoQrePTnOtlZKuZZqN-18">
|
||||
<mxGeometry y="30" width="300" height="30" as="geometry" />
|
||||
|
@ -125,7 +125,7 @@
|
|||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-27" value="cities" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="680" y="670" width="140" height="180" as="geometry" />
|
||||
<mxGeometry x="480" y="660" width="140" height="180" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ncYoQrePTnOtlZKuZZqN-28" value="ID SERIAL" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" vertex="1" parent="ncYoQrePTnOtlZKuZZqN-27">
|
||||
<mxGeometry y="30" width="140" height="30" as="geometry" />
|
||||
|
|
12
src/db.js
12
src/db.js
|
@ -205,6 +205,14 @@ const getCountryNameByID = async (id) => {
|
|||
return (await db.query(`SELECT country FROM cities WHERE ID = $1`, [id])).rows[0].country;
|
||||
}
|
||||
|
||||
const doesUserExist = async (roomId) => {
|
||||
return (await db.query("SELECT EXISTS (SELECT * FROM users WHERE room_id = $1)", [roomId])).rows[0].exists;
|
||||
}
|
||||
|
||||
const createUser = async (mx_id, roomId) => {
|
||||
await db.query("INSERT INTO users(mx_id, room_id, current_action) VALUES ($1, $2, $3)", [mx_id, roomId, "wait_start"]);
|
||||
}
|
||||
|
||||
export {
|
||||
fullEraseUser,
|
||||
appendUserPictures,
|
||||
|
@ -228,5 +236,7 @@ export {
|
|||
getUserLanguage,
|
||||
findCity,
|
||||
getCityNameByID,
|
||||
getCountryNameByID
|
||||
getCountryNameByID,
|
||||
doesUserExist,
|
||||
createUser
|
||||
};
|
26
src/index.js
26
src/index.js
|
@ -31,7 +31,9 @@ import {
|
|||
uploadMediaAsMessage,
|
||||
setUserLanguage,
|
||||
getUserLanguage,
|
||||
findCity
|
||||
findCity,
|
||||
doesUserExist,
|
||||
createUser
|
||||
} from './db.js';
|
||||
|
||||
import { processRequest, showRandomProfileToUser, showNewLikes } from "./interactions.js";
|
||||
|
@ -60,9 +62,21 @@ const client = new MatrixClient(homeserverUrl, accessToken, storage, crypto);
|
|||
|
||||
client.on("room.message", async (roomId, event) => {
|
||||
try {
|
||||
if (event.content?.msgtype !== 'm.text' && event.content?.msgtype !== 'm.image' && event.content?.msgtype !== 'm.video') return;
|
||||
if (event.sender === await client.getUserId()) return;
|
||||
|
||||
if (!await doesUserExist(roomId)) {
|
||||
i18n.locale = 'en'
|
||||
await client.sendText(roomId, i18n.t(["errors", "usernotexists"]));
|
||||
i18n.locale = 'ru'
|
||||
await client.sendText(roomId, i18n.t(["errors", "usernotexists"]));
|
||||
let mx_id = event.sender;
|
||||
await createUser(mx_id, roomId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.content?.msgtype !== 'm.text' && event.content?.msgtype !== 'm.image' && event.content?.msgtype !== 'm.video') return;
|
||||
|
||||
let current_action = await getCurrentUserAction(roomId);
|
||||
let answer = event.content.body;
|
||||
let msgtype = event.content.msgtype
|
||||
|
@ -299,7 +313,7 @@ client.on("room.event", async (roomId, event) => {
|
|||
} catch (e) {
|
||||
logError(e);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
client.on("room.invite", async (roomId, event) => {
|
||||
try {
|
||||
|
@ -317,10 +331,8 @@ client.on("room.invite", async (roomId, event) => {
|
|||
|
||||
let mx_id = event.sender;
|
||||
|
||||
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, "wait_start"]);
|
||||
if (!await doesUserExist(roomId)) {
|
||||
await createUser(mx_id, roomId);
|
||||
|
||||
i18n.locale = "en";
|
||||
await client.sendText(roomId, i18n.t(["general", "welcome"]));
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"notimplemented": "This feature is not yet implemented! Please, keep track of my updates at https://git.foxarmy.org/leca/heart2heart. Bother your admins to update, if released! ;)",
|
||||
"noprofiles": "There are no profiles left for you! I'm sorry. Please, come back later!",
|
||||
"alreadymessaged": "You have already messaged that person. Your message was not sent!",
|
||||
"wrongcity": "There is no such city. Perhaps, you meant %{first}, %{second}, %{third}, %{fourth} or %{fifth}?"
|
||||
"wrongcity": "There is no such city. Perhaps, you meant %{first}, %{second}, %{third}, %{fourth} or %{fifth}?",
|
||||
"usernotexists": "I cannot find your profile in my database. Perhaps, your profile was erased for some reason: ban, database reset or some other similar reason. Please, write !start <language>, where language is either en or ru."
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@
|
|||
"notimplemented": "Эта возможность ещё не добавлена! Пожалуйста, следите за обновлениями на моём git'е: https://git.foxarmy.org/leca/heart2heart. Доставайте своих админов, чтобы обновлялись, когда новая версия выходит ;)",
|
||||
"noprofiles": "Не могу найти профили, которые подходят вашим критериям! Извините. Попробуйте позже!",
|
||||
"alreadymessaged": "Вы уже отправляли сообщение этому человеку. Ваше сообщение не было отправлено!",
|
||||
"wrongcity": "Не знаю такого города. Возможно, вы имели в виду %{first}, %{second}, %{third}, %{fourth} или %{fifth}?"
|
||||
"wrongcity": "Не знаю такого города. Возможно, вы имели в виду %{first}, %{second}, %{third}, %{fourth} или %{fifth}?",
|
||||
"usernotexists": "Не могу найти ваш профиль в своей базе данных. Возможно, ваш профиль был удалён по какой-то причине: блокировка, сброс базы данных, или другая похожая причина. Пожалуйста, напишите !start <язык>, где язык или \"en\", или \"ru\"."
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue