-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage-maker.js
192 lines (162 loc) · 5.43 KB
/
message-maker.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import * as fs from 'node:fs';
import { format, utcToZonedTime } from 'date-fns-tz';
// eslint-disable-next-line import/extensions
import ja from 'date-fns/locale/ja/index.js';
/**
* Class to generate message.
* @since v1.0.0
* @param { Object } shift - Shift object.
* @param { int } [restOfHours = 40] - Rest of hours of this shift.
* @param { boolean } [isCountDown = false] - Flag of count down.
* @param { boolean } [isNext = false] - Flag of Next shift.
* @param { boolean } [isBigRun = false] - Flag of BigRun.
* @param { boolean } [isContest = false] - Flag of Contest.
* @param { boolean } [isFutureBigRun = false] - Flag of Future shift of Big Run.
*/
const MessageMaker = class {
constructor(shift, restOfHours = 40, isCountDown = false, isNext = false, isBigRun = false, isContest = false, isFutureBigRun = false) {
this.shift = shift;
this.restOfHours = restOfHours;
this.isCountDown = isCountDown;
this.isNext = isNext;
this.isBigRun = isBigRun;
this.isContest = isContest;
this.isFutureBigRun = isFutureBigRun;
// ステージのバッジを選べるように
/**
* Object of stage badges.
* @since v1.0.0
* @type {Object}
*/
this.stageBadges = JSON.parse(fs.readFileSync('./JSON/stages.json'));
// ブキのバッジを選べるように
/**
* Object of weapon badges.
* @since v1.0.0
* @type {Object}
*/
this.weaponBadges = JSON.parse(fs.readFileSync('./JSON/weapons.json'));
}
// ステージバッジ存在チェック
/**
* Getter: Get stage badge tag.
* @since v1.0.0
* @returns {string} - Badge image tag or blank string
*/
get stageBadgeId() {
let result;
if (Reflect.has(this.stageBadges, this.shift.stage.name)) {
result = this.stageBadges[this.shift.stage.name];
} else {
result = "";
}
return result;
}
// ステージ名返却
/**
* Getter: Cleaned up stage name.
* @since v1.0.0
* @returns {string} - Stage name or undef-text.
*/
get stageName() {
let stage = "不明"
if (this.shift.stage !== "") {
stage = this.shift.stage.name;
}
return stage;
}
// ブキバッジ存在チェック
/**
* Generate weapon badge tag.
* @since v1.0.0
* @param {string} name - Weapon name
* @returns {string} - Badge image tag or blank string
*/
weaponBadgeIdMaker = (name) => {
let result;
if (Reflect.has(this.weaponBadges, name)) {
result = this.weaponBadges[name];
} else {
result = name;
}
return result;
}
// マルチにしたもの
/**
* Make message to send.
* @since v1.0.0
* @returns {string} - Message to send
*/
maker() {
console.log('func: message.maker');
/** @type {string} */
let msg = "";
/** @type {boolean} */
let random = false;
if (this.isBigRun) {
msg += ":big_run: ";
}
if (this.isCountDown) {
msg += "$[shake まもなく終了!]";
msg += "\n";
}
if (this.isBigRun) {
msg += ":big_run_badge_gold:";
} else if (this.isContest) {
msg += ":btc_gold:";
} else {
msg += ":grizzco_bronze:";
}
msg += " ";
if (this.isNext && this.isContest) {
msg += ":eggstra_work:**のお知らせ**";
msg += ":btc_gold:";
} else if (this.isNext && !this.isContest) {
msg += "**次のシフト**";
} else if (this.isFutureBigRun) {
msg += "**ビッグランのお知らせ**";
} else if (this.isBigRun) {
msg += "**ただいまのビッグラン**";
} else if (this.isContest) {
msg += "**開催中の**:eggstra_work:"
msg += ":btc_gold:";
} else {
msg += "**ただいまのシフト**";
}
msg += "\n";
if (this.isNext || this.isFutureBigRun) {
msg += `${format(utcToZonedTime(new Date(this.shift.start_time), 'Asia/Tokyo'), 'M月d日(E) HH:mm', { locale: ja })}スタート!`;
} else {
msg += `残りおよそ **${this.restOfHours}時間**`;
}
msg += "\n";
msg += "ステージ: ";
if (!this.isBigRun) {
msg += `${this.stageBadgeId}`;
}
msg += ` **${this.stageName}**`;
msg += "\n";
// ブキを並べる
msg += "支給ブキ: ";
const { weapons } = this.shift;
// eslint-disable-next-line no-restricted-syntax
for (const weapon of weapons) {
const weaponBadge = this.weaponBadgeIdMaker(weapon.name);
msg += weaponBadge;
msg += " ";
if (weapon.name === 'ランダム') {
random = true;
}
}
if (random) {
msg += "\n";
msg += '<small>ランダムはクマブキランダムの場合があります。</small>';
}
if (this.isNext || this.isFutureBigRun) {
msg += "\n";
msg += `${format(utcToZonedTime(new Date(this.shift.end_time), 'Asia/Tokyo'), 'M月d日(E) HH:mm', { locale: ja })}まで`;
}
return msg;
}
}
export default MessageMaker;