Skip to content

Commit 3a1a7bd

Browse files
committed
Initial Mastodon server port
1 parent dca51a0 commit 3a1a7bd

File tree

6 files changed

+4097
-193
lines changed

6 files changed

+4097
-193
lines changed

hashtag.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
3+
const Mastodon = require('mastodon');
4+
const log = require('npmlog');
5+
const fs = require('fs')
6+
7+
8+
require('dotenv').config();
9+
log.level = process.env.LOG_LEVEL || 'verbose';
10+
11+
const config = {
12+
access_token: process.env.ACCESS_TOKEN,
13+
api_url: `https://${process.env.API_HOST}/api/v1/`,
14+
hashtag: process.env.HASHTAG,
15+
};
16+
17+
const client = new Mastodon(config);
18+
log.info("BBC Micro Bot mastodon edition");
19+
log.info(`Running on: ${process.env.API_HOST} #${config.hashtag}`);
20+
21+
22+
// Monitor timeline {timeline
23+
class Timeline {
24+
constructor() {
25+
this.queue = []; // list of mention statuses
26+
}
27+
28+
29+
async update() {
30+
31+
//console.log(`${config.api_url}timelines/public/?access_token=${config.access_token}&tag=${config.hashtag}`)
32+
const response = (await client.get('/timelines/tag/:hashtag',{'hashtag':`${config.hashtag}`})).data;
33+
34+
// List all tagged posts
35+
for (var i = 0; i < response.length; i++) {
36+
37+
// Remove those we've already liked
38+
if (response[i].favourited !== true) {
39+
40+
response[i].text = response[i].content.replace(/<[^>]*>?/gm, '');
41+
console.log(response[i].id,"@"+response[i].account.username+" tagged #bbcmicrobot");
42+
this.queue.push(response[i]);
43+
}
44+
45+
}
46+
47+
}
48+
}
49+
50+
51+
52+
module.exports = Timeline;

mastodon.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[06/11/2022 20:39:39 ] [LOG] Serv: {
2+
id: '109292779039545453',
3+
created_at: '2022-11-05T19:11:01.429Z',
4+
in_reply_to_id: '109292630262682237',
5+
in_reply_to_account_id: '109246658710563854',
6+
sensitive: false,
7+
spoiler_text: '',
8+
visibility: 'public',
9+
language: 'en',
10+
uri: 'https://mastodon.me.uk/users/bbcmicrobot/statuses/109292779039545453',
11+
url: 'https://mastodon.me.uk/@bbcmicrobot/109292779039545453',
12+
replies_count: 1,
13+
reblogs_count: 0,
14+
favourites_count: 2,
15+
edited_at: null,
16+
favourited: false,
17+
reblogged: false,
18+
muted: false,
19+
bookmarked: false,
20+
pinned: false,
21+
content: '<p>Thanks <span class="h-card"><a href="https://social.linux.pizza/@Jaffa" class="u-url mention">@<span>Jaffa</span></a></span> yeah that might be the way. I can have it respond to toots with <a href="https://mastodon.me.uk/tags/bbcmicrobot" class="mention hashtag" rel="tag">#<span>bbcmicrobot</span></a> (I think this is specific enough not to be spammy. I will check with <span class="h-card"><a href="https://mastodon.me.uk/@Floppy" class="u-url mention">@<span>Floppy</span></a></span> once things calm down a bit)</p>',
22+
reblog: null,
23+
application: {
24+
name: 'Mastodon for iOS',
25+
website: 'https://app.joinmastodon.org/ios'
26+
},
27+
account: {
28+
id: '109289826032916877',
29+
username: 'bbcmicrobot',
30+
acct: 'bbcmicrobot',
31+
display_name: 'BBC Micro Bot :mastodon:',
32+
locked: false,
33+
bot: true,
34+
discoverable: true,
35+
group: false,
36+
created_at: '2022-11-05T00:00:00.000Z',
37+
note: '<p>Programs in a single toot of code 👾 1980s BBC Micro Model B 32K 6502. Acorn Computers and ARM stuff. BBC BASIC.

Also building a 3D <a href="https://mastodon.me.uk/tags/retrocomputing" class="mention hashtag" rel="tag">#<span>retrocomputing</span></a> simulator at virtual.bbcmic.ro <a href="https://mastodon.me.uk/tags/bbcmicrobot" class="mention hashtag" rel="tag">#<span>bbcmicrobot</span></a></p><p>⚠️ Bot not online yet... I&#39;m busy porting it!</p><p><a href="https://www.bbcmicrobot.com" target="_blank" rel="nofollow noopener noreferrer"><span class="invisible">https://www.</span><span class="">bbcmicrobot.com</span><span class="invisible"></span></a></p>',
38+
url: 'https://mastodon.me.uk/@bbcmicrobot',
39+
avatar: 'https://cdn.masto.host/mastodonmeuk/accounts/avatars/109/289/826/032/916/877/original/7d1450f49b48a83e.png',
40+
avatar_static: 'https://cdn.masto.host/mastodonmeuk/accounts/avatars/109/289/826/032/916/877/original/7d1450f49b48a83e.png',
41+
header: 'https://cdn.masto.host/mastodonmeuk/accounts/headers/109/289/826/032/916/877/original/b7165f77e4b670b0.png',
42+
header_static: 'https://cdn.masto.host/mastodonmeuk/accounts/headers/109/289/826/032/916/877/original/b7165f77e4b670b0.png',
43+
followers_count: 508,
44+
following_count: 46,
45+
statuses_count: 36,
46+
last_status_at: '2022-11-07',
47+
emojis: [ [Object] ],
48+
fields: [ [Object] ]
49+
},
50+
media_attachments: [],
51+
mentions: [
52+
{
53+
id: '109246658710563854',
54+
username: 'Jaffa',
55+
url: 'https://social.linux.pizza/@Jaffa',
56+
57+
},
58+
{
59+
id: '1',
60+
username: 'Floppy',
61+
url: 'https://mastodon.me.uk/@Floppy',
62+
acct: 'Floppy'
63+
}
64+
],
65+
tags: [
66+
{
67+
name: 'bbcmicrobot',
68+
url: 'https://mastodon.me.uk/tags/bbcmicrobot'
69+
}
70+
],
71+
emojis: [],
72+
card: null,
73+
poll: null
74+
}

mentions.js

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)