-
Notifications
You must be signed in to change notification settings - Fork 1
/
church.js
77 lines (68 loc) · 2.54 KB
/
church.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
/// <reference path="index.d.ts" />
scriptNesting(Promise.all([
require('./backend-connection'),
require('./zoned-popup'),
require('./user-update')
]), async imps => {
const [{ message, ws }, { popupInZone }] = await imps;
popupInZone({
zone: 'friendship-explanation-zone',
popupText: 'stand in there together to become friends 😊',
objectLayerName: 'freindship popup',
popupOptions: [{
label: 'ok',
callback: popup => popup.close()
}]
});
/**
* @type {NodeJS.Timeout}
*/
let friendshipInterval;
/**
* @type {Array<string>}
*/
let friends = null;
WA.room.onEnterZone('friendship', async () => {
let readyFriends = await message({
type: 'readyfriendship'
});
readyFriends.new.forEach(id => {
WA.chat.sendChatMessage(`you have become friends with ${id}`, 'amor');
});
if(readyFriends.new.length === readyFriends.friends.length && readyFriends.friends.length > 0) {
WA.chat.sendChatMessage(`you can list your friends with !friends in chat`, 'amor');
WA.chat.sendChatMessage(`you can direct message a friend with !message (index) message`, 'amor');
WA.chat.sendChatMessage(`you can tp to a friend with !visit (index)`, 'amor');
}
friends = readyFriends.friends;
friendshipInterval = setInterval(async () => {
/**
* @type {Array<string>}
*/
const newFriends = await message({
type: 'friendscheck'
});
newFriends.filter(newFriend => !friends.includes(newFriend))
.forEach(friend => {
WA.chat.sendChatMessage(`you have become friends with ${friend}`, 'amor');
});
if(friends.length === 0 && newFriends.length) {
WA.chat.sendChatMessage(`you can list your friends with !friends in chat`, 'amor');
WA.chat.sendChatMessage(`you can direct message a friend with !message (index) message`, 'amor');
WA.chat.sendChatMessage(`you can tp to a friend with !visit (index)`, 'amor');
}
friends = newFriends;
}, 1000);
});
WA.room.onLeaveZone('friendship', () => {
message({
type: 'unreadyfriendship'
});
clearInterval(friendshipInterval);
});
WA.onChatMessage(msg => {
if(msg === '!friends') {
message({ type: 'friendstatus' });
}
});
})