Skip to content

Commit

Permalink
Reblogs if following
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitkick committed Jan 22, 2024
1 parent c576bf5 commit e9b5b85
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
3 changes: 2 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ var clientID = "Cli0";
let tag = (TEST || TRY) ? "test" : await cache(tootData, beebState);

// Post a video toot
mastodon.videoReply(mediaFilename,mediaType,tweet.id,"@"+tweet.account.acct,tweet,checksum,hasAudio,tag);
await mastodon.videoReply(mediaFilename,mediaType,tweet.id,"@"+tweet.account.acct,tweet,checksum,hasAudio,tag);
exec('rm '+mediaFilename);
}

setTimeout(requestTweet, POLL_DELAY);
Expand Down
100 changes: 51 additions & 49 deletions mastodon.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const ENABLE_TEXT_REPLY = false;
const log = require('npmlog');
const log = require('npmlog');
log.level = process.env.LOG_LEVEL || 'verbose';
const Mastodon = require('mastodon');
const Mastodon = require('mastodon');
require('dotenv').config();
const config = {
access_token: process.env.ACCESS_TOKEN,
Expand All @@ -11,78 +11,80 @@ const config = {
};

const mastodon = new Mastodon(config);
const fs = require('fs');
const fs = require('fs');

function post (path, params) {
log.info("Post",path,params)
function post(path, params) {
log.info("Post", path, params)
}

function get (path,params) {
log.info("get",path,params)
function get(path, params) {
log.info("get", path, params)
}


async function videoReply(filename,mediaType,replyTo,text,toot,checksum,hasAudio,tag){
async function videoReply(filename, mediaType, replyTo, text, toot, checksum, hasAudio, tag) {

if (toot.spoiler_text == ""){
if (toot.spoiler_text == "") {
console.log("No CW on bot source post")
}

try {

let resp = await mastodon.post('media', { file: fs.createReadStream(filename), description:"BBC Micro Bot graphics output - "+toot.spoiler_text });
log.info(resp)
let resp = await mastodon.post('media', { file: fs.createReadStream(filename), description: "BBC Micro Bot graphics output - " + toot.spoiler_text });
log.info(JSON.stringify(resp.data.id));
let id = resp.data.id; // Source: https://bbcmic.ro/#"+progData
let params = { status:"I ran "+text+"'s program and got this.\nSource: https://bbcmic.ro/?t="+tag+" #bbcbasic", media_ids: [id],in_reply_to_id:replyTo};
let params = { status: "I ran " + text + "'s program and got this.\nSource: https://bbcmic.ro/?t=" + tag + " #bbcbasic", media_ids: [id], in_reply_to_id: replyTo };
params.visibility = "public";

let response = await mastodon.post('statuses', params);
log.info("Media post DONE ",JSON.stringify(response));

await mastodon.post('statuses/:id/favourite', { id: [toot.id]});
log.info("Favourited "+toot.id);
log.info("Media post DONE ", JSON.stringify(response.data.id));

let user = response.in_reply_to_account_id;
await mastodon.post('statuses/' + response.data.in_reply_to_id + '/favourite');
log.info("Favourited " + toot.id);

let relationship = await mastodon.get('accounts/relationship', {id: [user]});
let user = response.data.in_reply_to_account_id;
log.info("User " + user);
let relationship = await mastodon.get('accounts/relationships', { id: user });
log.info("Relationship " + (relationship.data[0].following ? "following" : "not following"));

if (relationship[0].following) {
// Repost toot resp
log.info("Reposting toot "+response.id);
await mastodon.post('statuses/:id/reblog', { id: [response.id]});
// If we're not following the user, reblog the toot
if (relationship.data[0].following) {
log.info("Reposting toot " + response.data.id);
await mastodon.post('statuses/' + response.data.id + '/reblog');
}


//return {full:"https://bbcmic.ro/"+experimental+"#"+progData,key:short_url}
}

catch(e) {
log.info("Media post FAILED");
log.info(e);
return null;
}
}

function noOutput(toot) {
console.warn("NO VIDEO CAPTURED");
if (!ENABLE_TEXT_REPLY) return;
try {
post('statuses/update', {status: "@"+toot.user.screen_name+" Sorry, no output captured from that program", in_reply_to_status_id: toot.id});
}
catch(e) {
log.info("Non-media post FAILED");
log.info(e);
}
catch (e) {

log.info("Media post FAILED");
log.info(e);
return null;
}
}

function block(toot) {
post('blocks/create',{screen_name: toot.user.screen_name});

function noOutput(toot) {
console.warn("NO VIDEO CAPTURED");
if (!ENABLE_TEXT_REPLY) return;
try {
post('statuses/update', { status: "@" + toot.user.screen_name + " Sorry, no output captured from that program", in_reply_to_status_id: toot.id });
}
catch (e) {
log.info("Non-media post FAILED");
log.info(e);
}
}

module.exports = {
videoReply: videoReply,
noOutput: noOutput,
block: block,
post: post,
get: get
};
function block(toot) {
post('blocks/create', { screen_name: toot.user.screen_name });
}

module.exports = {
videoReply: videoReply,
noOutput: noOutput,
block: block,
post: post,
get: get
};

0 comments on commit e9b5b85

Please sign in to comment.