Twitter raffles in the command line, with PHP and minicli

Overview

Rafflebird

Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli.

Rafflebird giveaway for most liked reply on the given tweet

Disclaimer: The recent search endpoint available via the Twitter API v2 will not return results older than 1 week. This application is intended for quick raffles that don't require much setup or data persistence. Just pick a random reply, or the most liked reply, and that's it.

Installation

You can run Rafflebird using Docker Compose, or in a local PHP environment.

Requirements

  • If you're running Rafflebird with the included Docker Compose environment, you'll need:
    • Docker and Docker Compose installed on your local system. On Linux, depending on which version of Docker you're using, you may need to install both as separate packages. Windows and macOS users need to install Docker Desktop instead.
  • If you're running Rafflebird on an existing PHP environment, you'll need:
    • PHP 7.4+ (CLI only)
    • Composer
    • ext-json

Obtaining the Code

Start by cloning this repository and accessing the project folder with:

git clone https://github.com/erikaheidi/rafflebird.git
cd rafflebird

Running the Docker Environment

Bring the Docker Compose environment up with:

docker-compose up -d

Installing Dependencies Via Composer

docker-compose exec app composer install

Or, if you are running this on a local PHP environment:

composer install

Running Rafflebird

docker-compose exec app php rafflebird

Or, if you are running this on a local PHP environment:

php rafflebird

Configuring Rafflebird

When you executed composer install, a new config file was generated based on a sample config included in the project. You'll need to edit this file to set you your Twitter API credentials. You'll need valid Twitter credentials from a registered application in order to use this application.

V2 API

We use the new Twitter V2 API for pulling in the content via the search endpoints, obtaining all replies and their authors as well as information about likes and retweets. That requires the App Bearer token.

V1 API

The traditional Twitter V1.1 API is required for validating participation, such as to verify if a user follows another, or other criteria that might be developed in the future. For these we use the TwitterOAuth Library. It requires the 4 traditional OAuth keys:

  • API Token / Consumer Token: The application consumer key or APP Key.
  • API Secret / Consummer Secret: The application consumer key secret or App Secret.
  • User Access Token: The user access token.
  • User Access Token Secret: The user access token secret.

All these tokens are available in the application settings page on your Twitter Developer Portal.

Setting Up config.php File

Once you have your credentials, you can set them up in your config.php file:

<?php
#########################
## Configuration File
#########################

return [
    'app_path' => __DIR__ . '/app/Command',
    'debug' => true,

    # App Settings
    'ignore_usernames' => ['twitter', 'your_username'],
    'raffle_admin' => 'your_username', //the MustFollow criteria checks for this info to validate participation
    'raffle_rules' => [ 'App\\Rules\\DefaultRule' ],

    # Twitter API v2 Bearer Token
    'twitter_bearer_token' => 'TWITTER_BEARER_TOKEN',

    # Twitter API v1 Tokens
    'twitter_api_key' => 'TWITTER_API_KEY',
    'twitter_api_secret' => 'TWITTER_API_SECRET',
    'twitter_access_token' => 'USER_ACCESS_TOKEN',
    'twitter_token_secret' => 'USER_ACCESS_TOKEN_SECRET',
];

You should also configure the ignore_usernames and raffle_admin settings to include your own Twitter username.

The raffle_rules array defines which rules will be applied to validate a user's participation. The DefaultRule is a dummy rule and will allow anyone to participate. To enforce only followers, you should change this to MustFollow.

Don't forget to save the file when you're done.

Running Rafflebird

At the moment, there are two main commands: fetch and pick. Both will require you to provide a valid tweet ID as parameter.

To get a Tweet's ID, open the tweet in a dedicated browser window and check the URL, you'll find the tweet ID as the last numeric portion of it right after /status/:

https://twitter.com/erikaheidi/status/1405904174634651649

You can fetch the replies for a tweet with:

docker-compose exec app php rafflebird fetch replies id=1405904174634651649

Fetching replies

To pick a random winner from the participants, run:

docker-compose exec app php rafflebird pick random id=1405904174634651649

To pick the reply with the most likes, run:

docker-compose exec app php rafflebird pick best id=1405904174634651649

Rafflebird giveaway for most liked reply on the given tweet

You might also like...
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps

Deployer Simple command-line tool that aims to facilitate the continous delivery of PHP apps, particularly Laravel apps. Imagine you want to update yo

🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.

Termwind Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS

php command line script to DCA crypto from Coinbase Pro

dca.php A simple php script designed to be run via the command line via a cron job. This will connect to coinbase pro and buy the crypto coins specifi

A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 7.1 and above. Releases For an overview of the releas

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.
BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀 Quick start Requires PHP 7.4+ # First, instal

A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

Owner
Erika Heidi
Creative developer & content creator passionate about open source, Linux, and PHP. Senior Technical Writer @digitalocean. GitHub Star ⭐
Erika Heidi
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

Happy Medium 2 Nov 12, 2021
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt

EasyEngine v4 EasyEngine makes it greatly easy to manage nginx, a fast web-server software that consumes little memory when handling increasing volume

EasyEngine 2k Jan 4, 2023
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Nuno Maduro 32 Dec 26, 2022
Console - The Console component eases the creation of beautiful and testable command line interfaces.

Console Component The Console component eases the creation of beautiful and testable command line interfaces. Sponsor The Console component for Symfon

Symfony 9.4k Jan 7, 2023
Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface

Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and an independent Help object for describing commands.

Aura for PHP 103 Sep 28, 2022
Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

James Hall 745 Dec 30, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

null 324 Dec 8, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
A PHP command line tool used to install shlink

Shlink installer A PHP command line tool used to install shlink. Installation Install this tool using composer.

null 8 Nov 3, 2022
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

PHP Toolkit 23 Nov 13, 2022