initial commit
This commit is contained in:
commit
f2be2b8982
3
.env.example
Normal file
3
.env.example
Normal file
@ -0,0 +1,3 @@
|
||||
ADMIN_BEARER=""
|
||||
NIGGER_BEARER=""
|
||||
INSTANCE_NAME="example.tld"
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.env
|
||||
node_modules/
|
||||
lib/media/
|
9
README.MD
Normal file
9
README.MD
Normal file
@ -0,0 +1,9 @@
|
||||
This project requires NodeJS 18.14.0 and will probably only run effectively on a Linux machine.
|
||||
|
||||
1. Clone repository to directory
|
||||
2. Enter `yarn` into terminal and press enter
|
||||
3. Copy/move `.env.example` to `.env` in the root directory
|
||||
4. Fill out the necessary information (_BEARER entries require BEARER tokens for authentication)
|
||||
5. Run script by entering in to console "node nice-bot.js <SELECTION> <OPTIONS (if applicable)>"
|
||||
|
||||
I'll update this and add more features as times goes on. Yes, it is retarded spaghetti code but it works. I would recommend using `crontab` (see [CrontabGuru](https://crontab.guru/#*/_*_*_*_*)) to run the script every however long you'd like, if you want it to be automated. At the moment, this script does not support replying to mentions as they come, like how the `ebooks` accounts do.
|
33
lib/api.js
Normal file
33
lib/api.js
Normal file
@ -0,0 +1,33 @@
|
||||
// API reference: https://api.pleroma.social/ and https://docs-develop.pleroma.social/backend/development/API/pleroma_api/
|
||||
|
||||
'use strict';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export const getLatestStatuses = async (count) =>{
|
||||
const headers = {Authorization: `Bearer ${process.env.ADMIN_BEARER}`};
|
||||
const statusUrlArr = [];
|
||||
if (!count){
|
||||
count = 1;
|
||||
}
|
||||
try{
|
||||
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/pleroma/admin/statuses?page_size=${count}&godmode=false&local_only=false`, {
|
||||
method: "GET",
|
||||
headers: headers,
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
for (let account in data){
|
||||
statusUrlArr.push([
|
||||
data[account].id,
|
||||
data[account].account.username,
|
||||
data[account].pleroma.conversation_id,
|
||||
data[account].mentions,
|
||||
]);
|
||||
};
|
||||
|
||||
} catch (error){
|
||||
throw new Error(error);
|
||||
};
|
||||
//console.log(statusUrlArr);
|
||||
return statusUrlArr;
|
||||
};
|
49
lib/replybot.js
Normal file
49
lib/replybot.js
Normal file
@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
import fetch from 'node-fetch';
|
||||
import { getLatestStatuses } from './api.js';
|
||||
|
||||
const chooseStatusID = (array) => {
|
||||
return array[Math.floor(Math.random() * array.length)];
|
||||
};
|
||||
|
||||
const emoteChoice = async () =>{ // pulls current emojis from the instance
|
||||
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/pleroma/emoji`, {
|
||||
method: "GET",
|
||||
});
|
||||
const data = await res.json();
|
||||
let emoteArray = [];
|
||||
for (let e in data){
|
||||
emoteArray.push(e);
|
||||
}
|
||||
return emoteArray[Math.floor(Math.random() * emoteArray.length)];
|
||||
};
|
||||
|
||||
const replyChoice = async () =>{
|
||||
const replyArr = [ // add desired replies here - it's just a big ass array
|
||||
"example1",
|
||||
"example 2",
|
||||
"EXAMPLE 3",
|
||||
];
|
||||
return replyArr[Math.floor(Math.random() * replyArr.length)];
|
||||
};
|
||||
|
||||
export const postReply = async () =>{
|
||||
const headers = {Authorization: `Bearer ${process.env.REPLYBOT_BEARER}`, "Content-Type": "application/json"};
|
||||
const mentions = [];
|
||||
const statusIDArr = await getLatestStatuses(20);
|
||||
const target = chooseStatusID(statusIDArr);
|
||||
if (target[3]) {
|
||||
for (let i = 0; i < target[3].length; i++){
|
||||
mentions.push(target[3][i].acct);
|
||||
}
|
||||
};
|
||||
const emoji = await emoteChoice();
|
||||
const word = await replyChoice();
|
||||
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/statuses`, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify({status: `${word} :${emoji}:`, in_reply_to_id: target[0], to: mentions}),
|
||||
});
|
||||
if (res.status === 200) {console.log('Replybot posted!')} else {console.log('Replybot failed:', res.status, res.statusText, res.url, word, emoji)}
|
||||
};
|
21
nice-bot.js
Executable file
21
nice-bot.js
Executable file
@ -0,0 +1,21 @@
|
||||
#!/home/bot/.nvm/versions/node/v18.14.0/bin/node
|
||||
|
||||
'use strict';
|
||||
|
||||
import 'dotenv/config';
|
||||
import { postReply } from './lib/replybot.js';
|
||||
|
||||
const choice = process.argv[2]; // command line switch
|
||||
|
||||
try{
|
||||
switch (choice.toLowerCase()){
|
||||
case 'replybot':
|
||||
await postReply();
|
||||
break;
|
||||
default:
|
||||
console.log('Something went wrong with nice-bot (ya dun goof\'d)');
|
||||
break;
|
||||
};
|
||||
} catch (error){
|
||||
throw Error(error);
|
||||
}
|
26
package.json
Normal file
26
package.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.1",
|
||||
"download-file": "^0.1.5",
|
||||
"express": "^4.18.1",
|
||||
"form-data": "^4.0.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"google-images-url": "^1.0.2",
|
||||
"mime": "^3.0.0",
|
||||
"node-fetch": "2",
|
||||
"path": "^0.12.7",
|
||||
"pexels": "^1.4.0",
|
||||
"sqlite3": "^5.0.11",
|
||||
"yarn": "^1.22.19"
|
||||
},
|
||||
"name": "nice-poll",
|
||||
"version": "1.0.0",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"type": "module",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
Loading…
Reference in New Issue
Block a user