-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.js
64 lines (45 loc) · 1.33 KB
/
session.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { session } from 'grammy';
import { keyBy, mapValues } from 'lodash-es';
import { articlesNames, guildJoiningArticles } from './store/articles.js';
// import Database from '@replit/database';
// const db = new Database();
// const sessionStorageAdapter = {
// async read(key) {
// },
// async write(key, value) {
// },
// async delete(key) {
// }
// }
const getInitialSessionData = () => ({
introStatus: {
guild: false,
pms: false,
ranks: false,
project: false
},
articlesStatuses: mapValues(keyBy(articlesNames), () => false),
rank: 0
});
export const guildSession = session({
initial: getInitialSessionData,
// storage: sessionStorageAdapter
});
export const setIntroStatus = (ctx, introName, status = true) => {
ctx.session.introStatus[introName] = status;
}
export const setArticleStatus = (ctx, articleKey, value) => {
ctx.session.articlesStatuses[articleKey] = value;
}
export const setRank = (ctx, rankIndex) => {
ctx.session.rank = rankIndex;
}
export const getCurrentRankIndex = (ctx) => {
return ctx.session.rank;
}
export const getArticleStatus = (ctx, articleKey) => {
return Boolean(ctx.session.articlesStatuses[articleKey]);
}
export const getGuildJoiningArticlesStatus = (ctx) => {
return guildJoiningArticles.every((articleKey) => getArticleStatus(ctx, articleKey));
}