forked from miguel456/luke-bot
Migrated to Gitea
This commit is contained in:
16
src/Bot/Actions/MessageLogger.php
Normal file
16
src/Bot/Actions/MessageLogger.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace nogueiracodes\RaspberryBot\Bot\Actions;
|
||||
|
||||
use nogueiracodes\RaspberryBot\Core\Interfaces\Action;
|
||||
|
||||
class MessageLogger implements Action
|
||||
{
|
||||
public function processAction($message)
|
||||
{
|
||||
|
||||
echo "Sniffed message from " . $message->author->username . ": " . $message->content . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
}
|
81
src/Bot/Commands/MinecraftInfo.php
Normal file
81
src/Bot/Commands/MinecraftInfo.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace nogueiracodes\RaspberryBot\Bot\Commands;
|
||||
|
||||
use Ely\Mojang\Api;
|
||||
use Exception;
|
||||
use nogueiracodes\RaspberryBot\Core\Interfaces\Command;
|
||||
use nogueiracodes\RaspberryBot\Traits\HasSignature;
|
||||
|
||||
// Inspired by Laravel's artisan commands
|
||||
class MinecraftInfo implements Command
|
||||
{
|
||||
use HasSignature;
|
||||
|
||||
/**
|
||||
* Must be included at all times. This describes the command's parameters, which can be used in the run method.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $signature = "minecraft {operation: The The kind of operation; for now, only convert is supported} {subOperationType: The sub operation type} {subOperationArgument: The argument you want to pass to to the sub operation}";
|
||||
|
||||
|
||||
/**
|
||||
* Parrots back whatever the user said. Proof of concept.
|
||||
*
|
||||
* @param string $parameters This is an array of named parameters with values, based on the signature. First value is always the command's name, like how PHP's $argv is organized.
|
||||
* @return void
|
||||
*/
|
||||
public function run(array $parameters)
|
||||
{
|
||||
$mojangAPI = new Api();
|
||||
switch($parameters['operation'])
|
||||
{
|
||||
// convert to username
|
||||
case 'convert':
|
||||
|
||||
switch($parameters['subOperationType'])
|
||||
{
|
||||
case 'username':
|
||||
|
||||
$response = $parameters['subOperationType'] . "\'s UUID is " . $mojangAPI->usernameToUUID($parameters['subOperationArgument'])->getId();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Sorry, but at the moment you can only convert usernames to UUIDs.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'blacklist':
|
||||
|
||||
switch($parameters['subOperationType'])
|
||||
{
|
||||
case 'is-banned':
|
||||
|
||||
$blockedServerCollection = $mojangAPI->blockedServers();
|
||||
|
||||
$response = ($blockedServerCollection->isBlocked($parameters['subOperationArgument']))
|
||||
? 'Sorry! It appears that this server is indeed being blocked by Mojang. Users won\'t be able to join this Minecraft server using the official client.'
|
||||
: 'A little bird told me that this server is NOT blocked by Mojang. Users can freely join this server.';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Sorry, but at the moment you can only check if servers are banned.");
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
throw new Exception("Invalid usage! Please refer to !!rb help for more information.");
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
34
src/Bot/Commands/NumberFact.php
Normal file
34
src/Bot/Commands/NumberFact.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace nogueiracodes\RaspberryBot\Bot\Commands;
|
||||
|
||||
use Exception;
|
||||
use nogueiracodes\RaspberryBot\Core\Interfaces\Command;
|
||||
use nogueiracodes\RaspberryBot\Traits\HasSignature;
|
||||
use Zttp\Zttp;
|
||||
|
||||
class NumberFact implements Command
|
||||
{
|
||||
use HasSignature;
|
||||
|
||||
|
||||
public $signature = "numberfact {number: The number for which you want facts for.}";
|
||||
|
||||
|
||||
public function run(array $parameters)
|
||||
{
|
||||
|
||||
$number = $parameters['number'];
|
||||
$result = Zttp::get('http://numbersapi.com/' . $number . '?json');
|
||||
|
||||
if ($result->isOk())
|
||||
{
|
||||
return $result->json()['text'];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Sorry, but I can\'t fetch number facts right now. Try again later.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
52
src/Bot/Commands/SimplePlayback.php
Normal file
52
src/Bot/Commands/SimplePlayback.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace nogueiracodes\RaspberryBot\Bot\Commands;
|
||||
|
||||
use nogueiracodes\RaspberryBot\Core\Interfaces\Command;
|
||||
use nogueiracodes\RaspberryBot\Traits\HasSignature;
|
||||
|
||||
// Inspired by Laravel's artisan commands
|
||||
class SimplePlayback implements Command
|
||||
{
|
||||
use HasSignature;
|
||||
|
||||
/**
|
||||
* Must be included at all times. This describes the command's parameters, which can be used in the run method.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $signature = "capitalize {word: The word you want to convert} {state: lower or upper}";
|
||||
|
||||
|
||||
/**
|
||||
* Parrots back whatever the user said. Proof of concept.
|
||||
*
|
||||
* @param string $parameters This is an array of named parameters with values, based on the signature. First value is always the command's name, like how PHP's $argv is organized.
|
||||
* @return void
|
||||
*/
|
||||
public function run(array $parameters)
|
||||
{
|
||||
|
||||
// Play with the string first before sending it
|
||||
switch($parameters['state'])
|
||||
{
|
||||
case 'lower':
|
||||
|
||||
$capitalized = strtolower($parameters['word']);
|
||||
|
||||
break;
|
||||
case 'upper':
|
||||
|
||||
$capitalized = strtoupper($parameters['word']);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$capitalized = "Usage: !!rb capitalize [word] [upper|lower]. Use !!rb help for more.";
|
||||
}
|
||||
|
||||
return $capitalized;
|
||||
|
||||
}
|
||||
|
||||
}
|
10
src/Bot/init.php
Normal file
10
src/Bot/init.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require realpath(__DIR__ . '/../../vendor/autoload.php');
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(realpath(__DIR__ . '/../../'));
|
||||
$dotenv->load();
|
||||
|
||||
$dotenv->required('BOT_AUTH_TOKEN')->notEmpty();
|
||||
$dotenv->required('COMMAND_PREFIX')->notEmpty();
|
||||
|
Reference in New Issue
Block a user