Skip to content

Commit

Permalink
add stop and resume
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarshubin committed Jul 21, 2024
1 parent df06c41 commit b39c9cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/firebase/shabbas-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const getUserRef = async (msg: Message) => {
export const addUser = async (msg: Message) => {
const shabbas = await getShabbasDoc();
const userRef = await getUserRef(msg);

console.log(shabbas.data())
if (shabbas.data().isClos) {
await client.sendMessage(msg.from, "הרישום דרך הבוט סגור, תדבר עם איתמר שובין (051-2665020).");
return;
}

if (
shabbas
Expand Down Expand Up @@ -330,4 +336,18 @@ export const resetSubscribedYears = async (
);
};

const alertSubscribers = async (msg: Message) => {};

export const closeShabbas = async (msg: Message) => {
const shabbas = await getShabbasDoc();
await updateDoc(shabbas.ref, { isClose: true });
client.sendMessage(msg.from, `הרישום נעצר`);
};

export const resumeShabbas = async (msg: Message) => {
const shabbas = await getShabbasDoc();
await updateDoc(shabbas.ref, { isClose: false });
client.sendMessage(msg.from, `הרישום ממשיך`);
};


const alertSubscribers = async (msg: Message) => { };
12 changes: 12 additions & 0 deletions src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
addAlcoholic,
removeAlcoholic,
getAlcoholics,
closeShabbas,
resumeShabbas,
} from "./firebase/shabbas-manage";
import { HELP_MESSAGE } from "./constants/help-message";
import { sendSpecialMessages } from "./constants/special-response";
Expand Down Expand Up @@ -108,6 +110,16 @@ export const messageHandler = async (msg: Message) => {
return;
}

if (msg.body.startsWith("!stop") && (await isAdmin(msg))) {
await closeShabbas(msg);
return;
}

if (msg.body.startsWith("!resume") && (await isAdmin(msg))) {
await resumeShabbas(msg);
return;
}

switch (msg.body) {
case "כן":
await addUser(msg);
Expand Down

0 comments on commit b39c9cd

Please sign in to comment.