allows replybot to post regular statuses too

This commit is contained in:
matty 2023-02-10 08:12:07 -05:00
parent fcc56236d4
commit 6601b853b7
2 changed files with 19 additions and 4 deletions

View File

@ -19,7 +19,7 @@ const emoteChoice = async () =>{ // pulls current emojis from the instance
return emoteArray[Math.floor(Math.random() * emoteArray.length)];
};
const replyChoice = async () =>{
const statusChoice = async () =>{
const replyArr = [ // add desired replies here - it's just a big ass array
"example1",
"example 2",
@ -28,6 +28,18 @@ const replyChoice = async () =>{
return replyArr[Math.floor(Math.random() * replyArr.length)];
};
export const postRegularStatus = async () =>{
const headers = {Authorization: `Bearer ${process.env.REPLYBOT_BEARER}`, "Content-Type": "application/json"};
const emoji = await emoteChoice();
const word = await statusChoice();
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/statuses`, {
method: "POST",
headers: headers,
body: JSON.stringify({status: `${word} :${emoji}:`}),
});
if (res.status === 200) {console.log('Replybot posted regular status!')} else {console.log('Replybot failed (regular status):', res.status, res.statusText, res.url, word, emoji)}
};
export const postReply = async () =>{
const headers = {Authorization: `Bearer ${process.env.REPLYBOT_BEARER}`, "Content-Type": "application/json"};
const mentions = [];
@ -39,7 +51,7 @@ export const postReply = async () =>{
}
};
const emoji = await emoteChoice();
const word = await replyChoice();
const word = await statusChoice();
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/statuses`, {
method: "POST",
headers: headers,

View File

@ -3,15 +3,18 @@
'use strict';
import 'dotenv/config';
import { postReply } from './lib/replybot.js';
import { postRegularStatus, postReply } from './lib/replybot.js';
const choice = process.argv[2]; // command line switch
try{
switch (choice.toLowerCase()){
case 'replybot':
case 'replybot reply': // you can choose "reply" or "status" from here when calling in Crontab
await postReply();
break;
case 'replybot status':
await postRegularStatus();
break;
default:
console.log('Something went wrong with nice-bot (ya dun goof\'d)');
break;