-
Notifications
You must be signed in to change notification settings - Fork 0
/
RouterService.ts
226 lines (182 loc) · 6.01 KB
/
RouterService.ts
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import AppConfig from '../../lib/AppConfig'
import yaml from 'js-yaml'
import Game from '../models/Game'
import { GameManager } from '../models/GameManager'
import { MakeLogger } from '../../lib/LogLib'
import Util from '../../lib/Util'
import { Pal } from '../pal/base/Pal'
import { RexParser, ParserResult } from '../parser/RexParser'
import { SynManager } from '../parser/Synonyms'
import { SceneEvent } from '../MupTypes'
const logger = new MakeLogger('Router.svc')
const RouterService = {
// found: {route, parsed}
goto: async (evt: SceneEvent) => {
if (!evt.pal.isAdmin()) {
return
}
const roomName = evt.pres.parsed?.groups.roomName
logger.logObj('goto', roomName)
await evt.game?.story.gotoRoom(roomName, evt)
},
install: async (evt: SceneEvent) => {
await evt.pal.showInstallUrl()
},
lookRoom: async (evt: SceneEvent) => {
return await evt.game?.story.room.lookRoom(evt)
},
lookRoomThing: async (evt: SceneEvent) => {
return await evt.game?.story.room.lookRoomThing(evt)
},
takeRoomThing: async (evt: SceneEvent) => {
return await evt.game?.story.room.takeItemCommand(evt)
},
useRoomThingAlone: async (evt: SceneEvent) => {
return await evt.game?.story.room.useRoomThingAlone(evt)
},
useRoomThingOn: async (evt: SceneEvent) => {
return await evt.game?.story.room.useRoomThingOn(evt)
},
echoTest: async (evt: SceneEvent) => {
const input = evt.pres.clean.replace('echo', '')
const echo = '> ' + input
logger.log('echo', echo)
await evt.pal.sendText(echo)
},
getActionMatchesList(actions) {
let lines = actions?.map(thing => {
return { [thing.cname]: this.getActionMatchesThing(thing) }
})
return lines
},
getActionMatchesThing(thing) {
const line = thing.doc?.actions?.map(action => action.match)
return line || ''
},
handleCheat: async (evt: SceneEvent) => {
const game = await GameManager.findGame({ pal: evt.pal })
const info = {
room: game.story.room.name,
roomActions: RouterService.getActionMatchesThing(game.story.room),
// itemEvents: RouterService.getActionMatchesList(game.story.currentRoom.items),
actors: RouterService.getActionMatchesList(game.story.room.actors)
}
logger.logObj('cheatInfo', info)
const blob = yaml.dump(info)
await evt.pal.sendText(Util.quoteCode(blob))
return info
},
handleHelp: async (evt: SceneEvent) => {
const help = evt.game?.story.doc.help.basic
await evt.pal.sendText(help)
},
// admin commands
reload: async (evt: SceneEvent) => {
await evt.game?.reload(evt)
await evt.pal.sendText('reloaded')
},
clear: async (evt: SceneEvent) => {
await evt.pal.clearChannel()
// return await evt.game?.story.room.enterRoom(evt.pal)
},
voice: async (evt: SceneEvent) => {
await evt.pal.showVoiceChannel(evt.pal)
},
resetGame: async (evt: SceneEvent) => {
if (!evt.pal.isAdmin()) {
return
}
await evt.game?.reset(evt.pal)
// await evt.pal.sendText('reset to room:' + evt.game?.story.room.name)
await evt.pal.sendText('\:eye: ')
return await evt.game?.story.room.enterRoom(evt.pal)
},
showStatus: async (evt: SceneEvent) => {
if (!evt.pal.isAdmin()) {
return
}
await evt.game?.showStatus(evt)
},
showThingStatus: async (evt: SceneEvent) => {
await evt.game?.showThingStatus(evt)
},
showLog: async (evt: SceneEvent) => {
await evt.pal.sendText('-- sent log')
await evt.pal.showLog()
},
// for quicker parsing
// cacheNames: async (evt: SceneEvent) => {
// const itemList = evt.game?.story.room.roomItems!
// await SynManager.cacheNames(itemList)
// await evt.pal.sendText('rebuilt cache')
// },
showInventory: async (evt: SceneEvent) => {
return await evt.game?.player.showInventory(evt)
},
showTask: async (evt: SceneEvent) => {
return await evt.game.story.room.showTask(evt)
},
// jumpTask: async (evt: SceneEvent) => {
// return await evt.game.story.room.showNotes(evt)
// },
showHint: async (evt: SceneEvent) => {
return await evt.game.story.room.showHint(evt)
},
showChannels: async (evt: SceneEvent) => {
await evt.pal.showChannels()
},
showSurvey: async (evt: SceneEvent) => {
const link = AppConfig.read('SURVEY_LINK')
const text = `Please help us improve the gameplay with this little survey!\n${link}`
return await evt.pal.sendText(text)
},
userJoined: async (evt: SceneEvent) => {
return await evt.pal.sendText('Welcome new person!')
},
userLeft: async (evt: SceneEvent) => {
return await evt.pal.sendText('Goodbye!')
},
inviteLink: async (evt: SceneEvent) => {
const invite = await evt.pal.showInvite('invite your friends')
await evt.pal.sendText(invite)
},
// sendImageFooter: async (evt: SceneEvent) => {
// await evt.pal.sendImage('https://cbg.rik.ai/cdn/storydata/asylum/items/album.jpg')
// await evt.pal.sendText(':mag: <https://cbg.rik.ai/items/album|examine>')
// },
// sendUnfurl: async (evt: SceneEvent) => {
// await evt.pal.sendUnfurl('<https://cbg.rik.ai/items/album| :mag: examine>')
// // await evt.pal.sendText('<https://cbg.rik.ai/items/album|examine>')
// },
// sendImageLink: async (evt: SceneEvent) => {
// const title = "Album"
// const blocks = [
// {
// "type": "image",
// "title": {
// "type": "plain_text",
// "text": title,
// "emoji": true
// },
// "image_url": "https://cbg.rik.ai/cdn/storydata/asylum/items/album.jpg",
// "alt_text": "marg"
// },
// {
// "type": "actions",
// "elements": [
// {
// "type": "button",
// "text": {
// "type": "plain_text",
// "text": ":mag: Examine",
// "emoji": true
// },
// "url": "https://cbg.rik.ai/items/album"
// }
// ]
// }
// ]
// await evt.pal.sendBlocks(blocks)
// },
}
export { RouterService, SceneEvent }