-
Notifications
You must be signed in to change notification settings - Fork 8
/
LocalSystem.ts
95 lines (83 loc) · 3.33 KB
/
LocalSystem.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
import { pipe } from 'bitecs'
import { client } from '@xrengine/client-core/src/feathers'
import {
getChatMessageSystem,
hasSubscribedToChatSystem,
removeMessageSystem
} from '@xrengine/client-core/src/social/services/utils/chatSystem'
import { accessAuthState } from '@xrengine/client-core/src/user/services/AuthService'
import { isBot } from '@xrengine/engine/src/common/functions/isBot'
import { isClient } from '@xrengine/engine/src/common/functions/isClient'
import { Engine } from '@xrengine/engine/src/ecs/classes/Engine'
import { World } from '@xrengine/engine/src/ecs/classes/World'
import { isPlayerLocal } from '@xrengine/engine/src/networking/utils/isPlayerLocal'
import { handleCommand, isCommand } from './commandHandler'
console.log('loaded local systems')
console.log('loaded chat system')
client.service('message').on('created', (params) => {
const selfUser = accessAuthState().user.value
const { message } = params
let isVoice = false
let isVoiceUrl = false
if (message.text?.startsWith('!voice|')) {
message.text = message.text.replace('!voice|', '')
isVoice = true
} else if (message.text?.startsWith('!voiceUrl|')) {
message.text = message.text.replace('!voiceUrl|', '')
isVoiceUrl = true
}
if (!isVoiceUrl) {
console.log(
'BOT_MESSAGE|',
JSON.stringify({
id: message.id,
sender: message.sender.name,
senderId: message.sender.userId,
channelId: message.channelId,
text: message.text,
updatedAt: message.updatedAt
})
)
}
if (isVoiceUrl) {
console.log('got voice url:', message.text)
//play audio
const audio = new Audio(message.text)
audio.play()
return
}
if (isVoice) {
return
}
if (message != undefined && message.text != undefined) {
if (isPlayerLocal(message.senderId)) {
if (handleCommand(message.text, Engine.instance.currentWorld.localClientEntity, message.senderId)) return
else {
const system = getChatMessageSystem(message.text)
if (system !== 'none') {
message.text = removeMessageSystem(message.text)
if (!isBot(window) && !Engine.instance.isBot && !hasSubscribedToChatSystem(selfUser.id, system)) return
}
}
} else {
const system = getChatMessageSystem(message.text)
if (system !== 'none') {
message.text = removeMessageSystem(message.text)
if (!isBot(window) && !Engine.instance.isBot && !Engine.instance.isBot && !hasSubscribedToChatSystem(selfUser.id, system)) return
} else if (isCommand(message.text) && !Engine.instance.isBot && !isBot(window)) return
}
}
})
export default async function LocalSystem(world: World) {
// TODO: this is temp, until reality packs have browser & node options
if (!isClient) return () => {}
const { ProximitySystem } = await import('./systems/ProximitySystem')
const { WebCamInputSystem } = await import('./systems/WebCamInputSystem')
const { FollowSystem } = await import('./systems/FollowSystem')
const { AfkCheckSystem } = await import('./systems/AfkCheckSystem')
const proximitySystem = await ProximitySystem(world)
const webCamInputSystem = await WebCamInputSystem(world)
const followSystem = await FollowSystem(world)
const afkCheckSystem = await AfkCheckSystem(world)
return pipe(proximitySystem, webCamInputSystem, followSystem, afkCheckSystem)
}