Skip to content

Add Reset Function #41

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const lineClient: line.Client = new line.Client(<line.ClientConfig>lineConfig);
let db: any = {};
try {
const credential: Credentials = await client.authorize();

db = await gsrun(client);
console.log(db);
logger.info("DB listed successful");
Expand All @@ -57,11 +56,10 @@ const lineClient: line.Client = new line.Client(<line.ClientConfig>lineConfig);
new router.LegacyPassthru(db)
);

setInterval(async () => {
const runDb = async () => {
let db: any = {};
try {
const credential: Credentials = await client.authorize();

db = await gsrun(client);
console.log(db);
logger.info("DB listed successful");
Expand All @@ -77,7 +75,9 @@ const lineClient: line.Client = new line.Client(<line.ClientConfig>lineConfig);
},
new router.LegacyPassthru(db)
);
}, 1000 * 60 * 60 * 24);
}

setInterval(runDb, 1000 * 60 * 60 * 24);

const handleEvent = async (event: line.WebhookEvent) => {
if (event.type !== "message" || event.message.type !== "text") {
Expand All @@ -87,6 +87,34 @@ const lineClient: line.Client = new line.Client(<line.ClientConfig>lineConfig);
const userId = event.source.userId;
const theReply = messageRouter.reply(msg);

if(msg == "reset1234"){
let db: any = {};
let message : string = "Wow"
try {
const credential: Credentials = await client.authorize();
db = await gsrun(client);
console.log(db);
logger.info("DB listed successful");
message = "You have successfully Reset The Menu :)"
} catch (err) {
message = "Some Error Occured :("
logger.error(err);
}
messageRouter = new router.MessageRouter(
{
week: new router.LegacyWeekOverview(db),
},
{
week: ["week", "wk", "summary", "sum", "overview"],
},
new router.LegacyPassthru(db)
);
return lineClient.replyMessage(event.replyToken, {
type: "text",
text: message
});
}

if (userId) {
const profile = await lineClient.getProfile(userId);
// logger.info(`[${new Date().toISOString()}] "${profile.displayName}" said ${msg}`);
Expand Down