wafrn instance bluesky labeler (mirror of https://git.jbc.lol/jbcrn/wadge)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix issues regarding on multipost thingys

+89 -83
+89 -83
index.js
··· 88 88 const firstNotif = notifs.notifications[0]; 89 89 if (this._recentPosts.length === 0) this._recentPosts.push(`${firstNotif.userId}${firstNotif.postId}`); 90 90 if (this._recentPosts.includes(`${firstNotif.userId}${firstNotif.postId}`)) return; 91 - else this._recentPosts.push(`${firstNotif.userId}${firstNotif.postId}`); 92 - console.log(this._recentPosts); 93 - const postNotif = await this.getPost(firstNotif.postId); 94 91 95 - const mdContent = postNotif.posts[0].markdownContent ?? stripHtml(postNotif.posts[0].content).result; 96 - const contSpl = mdContent.split(' '); 97 - const mention = contSpl[0]; 98 - const rest = '' + contSpl.slice(1).join(' ').toLowerCase(); 99 - const restSpl = rest.split(' '); 100 - const command = '' + restSpl[0]; 101 - const args = '' + restSpl.slice(1).join(' ').toLowerCase(); 92 + for (let i = 0; i < notifs.notifications.length; i++) { 93 + console.log(this._recentPosts); 94 + const thisNotif = notifs.notifications[i]; 95 + if (this._recentPosts.includes(`${thisNotif.userId}${thisNotif.postId}`)) return; 96 + else this._recentPosts.push(`${firstNotif.userId}${firstNotif.postId}`); 97 + const postNotif = await this.getPost(thisNotif.postId); 102 98 103 - let user = firstNotif.user.url; 104 - let u2 = user; 105 - if (!user.startsWith('@')) user = '@' + user; 106 - if (!user.replace(/^\@/, '').includes('@')) user = user + '@wf.jbc.lol' 99 + const mdContent = postNotif.posts[0].markdownContent ?? stripHtml(postNotif.posts[0].content).result; 100 + const contSpl = mdContent.split(' '); 101 + const mention = contSpl[0]; 102 + const rest = '' + contSpl.slice(1).join(' ').toLowerCase(); 103 + const restSpl = rest.split(' '); 104 + const command = '' + restSpl[0]; 105 + const args = '' + restSpl.slice(1).join(' ').toLowerCase(); 107 106 108 - console.log(contSpl, mention, rest); 109 - console.log(postNotif); 110 - console.log(firstNotif); 107 + let user = thisNotif.user.url; 108 + let u2 = user; 109 + if (!user.startsWith('@')) user = '@' + user; 110 + if (!user.replace(/^\@/, '').includes('@')) user = user + '@wf.jbc.lol' 111 111 112 - if (postNotif.posts[0].privacy !== 10) { 113 - return; 114 - } 115 - 116 - console.log(mention, command, args); 117 - 118 - if (command === 'is-wafrn') { 119 - const ifWafrn = await this.checkIfWafrn(!!args ? args : user); 120 - await this.send("", `${!!args ? args + ' is' : 'You are'} ${ifWafrn.isWafrn ? 'in' : 'not in'} a Wafrn instance (${ifWafrn.httpError ? 'either not a Fediverse instance or HTTP/fetch error getting nodeinfo, try again later' : `${ifWafrn.software.name} ${ifWafrn.software.version}`})`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 112 + console.log(contSpl, mention, rest); 113 + console.log(postNotif); 114 + console.log(thisNotif); 121 115 122 - console.log(`sent post in woot ${postNotif.posts[0].id}`); 123 - return; 124 - } else if (command === 'setup') { 125 - const ifWafrn = await this.checkIfWafrn(user); 126 - if (!ifWafrn.isWafrn) { 127 - await this.send("", 'You are not in a Wafrn instance.', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 116 + if (postNotif.posts[0].privacy !== 10) { 128 117 return; 129 118 } 130 119 131 - const res = await fetch(`https://${ifWafrn.instHost}/api/user?id=${ifWafrn.name}`, { 132 - method: 'GET' 133 - }) 120 + console.log(mention, command, args); 121 + 122 + if (command === 'is-wafrn') { 123 + const ifWafrn = await this.checkIfWafrn(!!args ? args : user); 124 + await this.send("", `${!!args ? args + ' is' : 'You are'} ${ifWafrn.isWafrn ? 'in' : 'not in'} a Wafrn instance (${ifWafrn.httpError ? 'either not a Fediverse instance or HTTP/fetch error getting nodeinfo, try again later' : `${ifWafrn.software.name} ${ifWafrn.software.version}`})`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 134 125 135 - if (!res.ok) { 136 - console.log(await res.text()); 137 - await this.send("", 'There is an error while getting your user info. You might want to wait a bit. You also need to make sure your profile is visible to public as it\'s the only way Wadge can detect it, sadly, but you can just reinstate it later.', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 126 + console.log(`sent post in woot ${postNotif.posts[0].id}`); 138 127 return; 139 - } 128 + } else if (command === 'setup') { 129 + const ifWafrn = await this.checkIfWafrn(user); 130 + if (!ifWafrn.isWafrn) { 131 + await this.send("", 'You are not in a Wafrn instance.', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 132 + return; 133 + } 140 134 141 - const resJson = await res.json(); 142 - console.log(resJson); 143 - const bskyDid = await resJson.bskyDid; 135 + const res = await fetch(`https://${ifWafrn.instHost}/api/user?id=${ifWafrn.name}`, { 136 + method: 'GET' 137 + }) 144 138 145 - if (!bskyDid) { 146 - await this.send("", `You don't have Bluesky enabled. Enable it on https://${ifWafrn.instHost}/settings/account or import your existing one on https://${ifWafrn.instHost}/profile/migrate-bluesky`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 147 - return; 148 - } 139 + if (!res.ok) { 140 + console.log(await res.text()); 141 + await this.send("", 'There is an error while getting your user info. You might want to wait a bit. You also need to make sure your profile is visible to public as it\'s the only way Wadge can detect it, sadly, but you can just reinstate it later.', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 142 + return; 143 + } 149 144 150 - function onlyUnique(value, index, array) { 151 - return array.indexOf(value) === index; 152 - } 145 + const resJson = await res.json(); 146 + console.log(resJson); 147 + const bskyDid = await resJson.bskyDid; 153 148 154 - try { 155 - const extLabels = await getLabelerLabelDefinitions(credentials); 156 - if (!extLabels.find(x => x.identifier === ifWafrn.instHost?.toLowerCase().replaceAll('.', '-'))) { 157 - const labels = [ 158 - ...(extLabels ?? []), 159 - { 160 - identifier: ifWafrn.instHost?.toLowerCase().replaceAll('.', '-'), 161 - name: ifWafrn.instHost, 162 - description: `Main account of this Bluesky user is on ${ifWafrn.instHost} Wafrn instance`, 163 - adultOnly: false, 164 - severity: 'inform', 165 - blurs: "none", 166 - defaultSetting: "warn", 167 - locales: [{ lang: "en", name: ifWafrn.instHost, description: `Main account of this Bluesky user is on ${ifWafrn.instHost} Wafrn instance` }] 168 - } 169 - ] 149 + if (!bskyDid) { 150 + await this.send("", `You don't have Bluesky enabled. Enable it on https://${ifWafrn.instHost}/settings/account or import your existing one on https://${ifWafrn.instHost}/profile/migrate-bluesky`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 151 + return; 152 + } 170 153 171 - await declareLabeler( 172 - credentials, 173 - labels.filter(onlyUnique), 174 - true 175 - ) 154 + function onlyUnique(value, index, array) { 155 + return array.indexOf(value) === index; 176 156 } 177 157 178 - let label = await server.createLabel({ 179 - uri: bskyDid, 180 - val: ifWafrn.instHost?.toLowerCase().replaceAll('.', '-') 181 - }) 158 + try { 159 + const extLabels = await getLabelerLabelDefinitions(credentials); 160 + if (!extLabels.find(x => x.identifier === ifWafrn.instHost?.toLowerCase().replaceAll('.', '-'))) { 161 + const labels = [ 162 + ...(extLabels ?? []), 163 + { 164 + identifier: ifWafrn.instHost?.toLowerCase().replaceAll('.', '-'), 165 + name: ifWafrn.instHost, 166 + description: `Main account of this Bluesky user is on ${ifWafrn.instHost} Wafrn instance`, 167 + adultOnly: false, 168 + severity: 'inform', 169 + blurs: "none", 170 + defaultSetting: "warn", 171 + locales: [{ lang: "en", name: ifWafrn.instHost, description: `Main account of this Bluesky user is on ${ifWafrn.instHost} Wafrn instance` }] 172 + } 173 + ] 182 174 183 - console.log(label); 175 + await declareLabeler( 176 + credentials, 177 + labels.filter(onlyUnique), 178 + true 179 + ) 180 + } 181 + 182 + let label = await server.createLabel({ 183 + uri: bskyDid, 184 + val: ifWafrn.instHost?.toLowerCase().replaceAll('.', '-') 185 + }) 186 + 187 + console.log(label); 184 188 185 - await this.send("", `Done! Added your instance on your account label list! Next up is to like the bot to actually see it!`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 186 - console.log('added user to list'); 187 - return; 188 - } catch (e) { 189 - console.error(e); 190 - await this.send("", `An error occured, pinging @jbcrn\n\`\`\`\n${e}\n\`\`\``, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 191 - return; 189 + await this.send("", `Done! Added your instance on your account label list! Next up is to like the bot to actually see it!`, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 190 + console.log('added user to list'); 191 + return; 192 + } catch (e) { 193 + console.error(e); 194 + await this.send("", `An error occured, pinging @jbcrn\n\`\`\`\n${e}\n\`\`\``, postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 195 + return; 196 + } 192 197 } 198 + 199 + await this.send("", 'Set up by mentioning this bot and adding `setup`!', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 193 200 } 194 201 195 - await this.send("", 'Set up by mentioning this bot and adding `setup`!', postNotif.posts[0].privacy, "", postNotif.users.map(t => t.id), postNotif.posts[0].id); 196 202 } 197 203 198 204 async saveMembers() {