Skip to content

Commit 5b7f354

Browse files
committed
Added chioce node choice removal
1 parent 85c58e1 commit 5b7f354

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

js/Akun.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ class Akun {
221221
return this._closeNode(readerPostNodeId);
222222
}
223223

224+
removeChoiceNodeChoice(choiceNodeId, choiceId, reason) {
225+
const data = {
226+
'_id': choiceNodeId,
227+
'update': {
228+
'$addToSet': {
229+
'xOut': choiceId
230+
},
231+
'$set': {
232+
[`choices.${choiceId}`]: 'permanentlyRemoved',
233+
[`xOutReasons.${choiceId}`]: reason
234+
}
235+
}
236+
};
237+
return this.core.post(`/api/anonkun/editChapter`, {data: data, json: false});
238+
}
239+
224240
ban(storyId, chatNodeId) {
225241
const data = {
226242
blockFor: chatNodeId,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "akun-api",
3-
"version": "5.0.2",
3+
"version": "5.1.0",
44
"description": "A module intended to enable easy interactions with Anonkun",
55
"main": "index.js",
66
"type": "module",

test.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ async function testStory(akun, storyId) {
107107
});
108108
client.storyThread.on('subscriptionSucceeded', onSubscriptionSucceeded);
109109

110-
// const resTestPost1 = await client.post('Test post 1');
110+
// const resTestPost1 = await client.postChat('Test post 1');
111111
// console.log(`post response: ${resTestPost1}`);
112112

113113
const resLogin = await akun.login(credentials['username'], credentials['password']);
114114
console.log(`Logged in as ${resLogin['username']}!`);
115115

116-
// const resTestPost2 = await client.post('Test post 2');
116+
// const resTestPost2 = await client.postChat('Test post 2');
117117
// console.log(`post response: ${resTestPost2}`);
118118

119119
// console.log(client.latestChapter());
@@ -125,7 +125,7 @@ async function testStory(akun, storyId) {
125125
// });
126126

127127
return new Promise(res => {
128-
client.storyThread.on('chat', (node) => {
128+
client.chatThread.on('chat', (node) => {
129129
if (node.body === 'exit') {
130130
res();
131131
}
@@ -174,7 +174,7 @@ async function testPut(akun, chatId) {
174174
const postData = await client.post('Test post');
175175
const data = await akun.getNode(postData['_id']);
176176
data.b = 'edited text';
177-
console.log(await akun.put('/api/node', { data }));
177+
console.log(await akun.put('/api/node', {data}));
178178
}
179179

180180
async function testAnonToggle(akun, chatId) {
@@ -201,21 +201,65 @@ async function testBan(akun) {
201201
let res;
202202
res = await akun.login(credentials['username'], credentials['password']);
203203
console.log(res);
204-
res = await akun.unban('iRoYFFCDCZnB2QvEq', '53zAELYaC8RkkMpcn');
204+
res = await akun.ban('iRoYFFCDCZnB2QvEq', '53zAELYaC8RkkMpcn');
205205
console.log(res);
206206
res = await akun.unban('iRoYFFCDCZnB2QvEq', 'B5cqvTk3kMgRNPesr');
207207
console.log(res);
208208
}
209209

210+
async function testPollOpenClose(akun) {
211+
await akun.login(credentials['username'], credentials['password']);
212+
213+
while (true) {
214+
console.log(await akun.closeChoice('58BfMER3GZg48LbYm'));
215+
await setTimeoutPromise(1000);
216+
console.log(await akun.openChoice('58BfMER3GZg48LbYm'));
217+
await setTimeoutPromise(1000);
218+
}
219+
}
220+
221+
async function testPollChoiceRemoval(akun) {
222+
let res;
223+
res = await akun.login(credentials['username'], credentials['password']);
224+
console.log(res);
225+
const client = await akun.join('vhHhMfskRnNDbxwzo');
226+
client.storyThread.on('choice', (node) => {
227+
onChoice(akun, client, node);
228+
for (let choiceId = 0; choiceId < node.choiceValues.length; choiceId++) {
229+
if (node.choiceValues[choiceId] === 'test') {
230+
akun.removeChoiceNodeChoice(node.id, choiceId).then(res => console.log(res))
231+
}
232+
}
233+
});
234+
client.storyThread.on('choiceUpdated', (node) => {
235+
onChoiceUpdated(akun, client, node);
236+
for (let choiceId = 0; choiceId < node.choiceValues.length; choiceId++) {
237+
if (node.choiceValues[choiceId] === 'test') {
238+
akun.removeChoiceNodeChoice(node.id, choiceId, 'sample reason').then(res => console.log(res))
239+
}
240+
}
241+
});
242+
243+
return new Promise(res => {
244+
client.chatThread.on('chat', (node) => {
245+
if (node.body === 'exit') {
246+
res();
247+
}
248+
});
249+
})
250+
}
251+
210252
async function runTests(akun) {
211253
// await testAnonToggle(akun, 'vhHhMfskRnNDbxwzo');
212254
// await testPost(akun, 'vhHhMfskRnNDbxwzo');
213255
await testStory(akun, 'vhHhMfskRnNDbxwzo');
214-
// await testChat(akun, 'oQ2fkvRS4nxjLfSmA');
256+
// await testChat(akun, 'oQ2fkvRS4nxjLfSmA');
215257
// await testChat(akun, 'oWC3WhFDMXqZkAG69');
216258
// await testPut(akun, 'vhHhMfskRnNDbxwzo');
217259
// await testVote(akun, 'TziTddJsppEfr82nh');
260+
// await testPollOpenClose(akun);
218261
// await testBan(akun);
262+
// await testPollChoiceRemoval(akun);
219263
}
220264

221265
async function setup(withRealtime = true) {

0 commit comments

Comments
 (0)