Coder Social home page Coder Social logo

everyhourbot's Introduction

EveryHourBot

A Twitter bot written in NodeJS that powers @PossumEveryHour, using Twitter 1.1 API and cryptographic functionality for quality randomness.

Dependencies

NodeJS 16 Twitter Developer Account with evelated permissions and access to Twitter V1 API

How to use

These instructions are for running the bot on a Linux/Windows server system. Code not designed to run on serverless infrastructure like AWS Lambda, Azure Functions or running on Heroku.

  1. Clone the repository into a location you want it to run from
  2. Enter the directory where index.js is located and run npm install to install the required dependencies
  3. Populate the media folder with pictures of your choosing that follow the Twitter API Media Best Practices.
  4. Apply for a Twitter developer account and obtain the v1 API and Access tokens from the account you want to run the bot from
  5. Create a new .env file and add the required API keys. Use .env-example as an example file.
  6. Use a NodeJS daemon process like PM2 to start the bot. As an example, cd to the directory and run pm2 start -f index.js --name "PossumEveryHour"

If you are confused on where to start or you have no experience with Linux or servers in general, I'd suggest using something like a Raspberry Pi, or using an old computer to install Ubuntu Linux onto and run your own bot from that.

Rocky Linux/RHEL8 requirements

Rocky/RHEL8 ships with NodeJS 10 by default. Execute these commands to disable the NodeJS 10 DNF module, enable NodeJS 16 module and install NodeJS 16:

sudo dnf module disable nodejs:10 -y
sudo dnf module enable nodejs:16 -y
sudo dnf install @nodejs:16

Then verify:

$ node -v
v16.13.1

How does it work?

  1. If executed from index.js, it will utilize Node Schedule, to execute maincore.js every hour, simulating cron job scheduling
  2. Code loads all the files in the media folder into an array
  3. Code verifies how many media files are in the media folder, and if it detects 2 or less images, it will refuse to run to prevent the code to be used for spamming
  4. createPost() function calls getRandomFile() that looks up how many entries are in the usednumbers.txt file depending on the count of files in media folder and if the file needs to be cleaned up.
  5. genRandomNumber() function gets called, generating a number between 1 to count of files in media and checks against usednumbers.txt to see if that specific number was used in a specific timeframe. If it was used, repeat until a number that wasn't used is found.
  6. Write the used number into usednumbers.txt

Tested with Rocky Linux 8.5, npm 8.1.2 and nodejs v16.13.1

everyhourbot's People

Contributors

thunderysteak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.