Created Boilerplate
This commit is contained in:
parent
27c51bdd23
commit
a926428437
23
Makefile
23
Makefile
|
@ -13,29 +13,12 @@ build:
|
|||
|
||||
install:
|
||||
# Installs the compiled package to the system
|
||||
ppm --fix-conflict --no-prompt --install="build/net.intellivoid.spam_protection_bot.ppm" --branch="production"
|
||||
ppm --fix-conflict --no-prompt --install="build/net.intellivoid.synical_bot.ppm" --branch="production"
|
||||
|
||||
install_fast:
|
||||
# Installs the compiled package to the system
|
||||
ppm --fix-conflict --no-prompt --skip-dependencies --install="build/net.intellivoid.spam_protection_bot.ppm" --branch="production"
|
||||
ppm --fix-conflict --no-prompt --skip-dependencies --install="build/net.intellivoid.synical_bot.ppm" --branch="production"
|
||||
|
||||
run:
|
||||
# Runs the bot
|
||||
ppm --main="net.intellivoid.spam_protection_bot" --version="latest"
|
||||
|
||||
stop:
|
||||
# Stops the main execution point
|
||||
pkill -f 'main=net.intellivoid.spam_protection_bot'
|
||||
|
||||
stop_workers:
|
||||
# Stops the sub-workers created by BackgroundWorker
|
||||
pkill -f 'worker-name=PublicServerchanBot'
|
||||
|
||||
debug:
|
||||
# Starts the bot, kills all the workers and focuses on one worker in STDOUT
|
||||
# Run with -i to ignore possible errors.
|
||||
make stop
|
||||
screen -dm bash -c 'ppm --main="net.intellivoid.spam_protection_bot" --version="latest"'
|
||||
sleep 3
|
||||
make stop_workers
|
||||
php botsrc/worker.php
|
||||
ppm --main="net.intellivoid.synical_bot" --version="latest"
|
|
@ -5,14 +5,11 @@
|
|||
use acm2\acm2;
|
||||
use acm2\Objects\Schema;
|
||||
use BackgroundWorker\BackgroundWorker;
|
||||
use CoffeeHouse\CoffeeHouse;
|
||||
use DeepAnalytics\DeepAnalytics;
|
||||
use SpamProtection\SpamProtection;
|
||||
use TelegramClientManager\TelegramClientManager;
|
||||
use VerboseAdventure\VerboseAdventure;
|
||||
|
||||
/**
|
||||
* Class SpamProtectionBot
|
||||
* Class SynicalBot
|
||||
*/
|
||||
class SynicalBot
|
||||
{
|
||||
|
@ -65,9 +62,8 @@
|
|||
$TelegramSchema->setDefinition('CustomEndpoint', 'http://127.0.0.1:8081');
|
||||
$TelegramSchema->setDefinition('CustomDownloadEndpoint', '/file/bot{API_KEY}');
|
||||
$TelegramSchema->setDefinition('MainOperators', []);
|
||||
$TelegramSchema->setDefinition('LoggingChannel', 'SpamProtectionLogs');
|
||||
$TelegramSchema->setDefinition('LoggingChannel', 'SynicalLogs');
|
||||
$TelegramSchema->setDefinition('VerboseLogging', false);
|
||||
|
||||
$acm->defineSchema($TelegramSchema);
|
||||
|
||||
$BackgroundWorkerSchema = new Schema();
|
||||
|
@ -77,6 +73,15 @@
|
|||
$BackgroundWorkerSchema->setDefinition('MaxWorkers', 5);
|
||||
$acm->defineSchema($BackgroundWorkerSchema);
|
||||
|
||||
$DatabaseSchema = new Schema();
|
||||
$DatabaseSchema->setName('Database');
|
||||
$DatabaseSchema->setDefinition('Host', '127.0.0.1');
|
||||
$DatabaseSchema->setDefinition('Port', 3306);
|
||||
$DatabaseSchema->setDefinition('Username', 'root');
|
||||
$DatabaseSchema->setDefinition('Password', 'admin');
|
||||
$DatabaseSchema->setDefinition('Database', 'telegram');
|
||||
$acm->defineSchema($DatabaseSchema);
|
||||
|
||||
$RedisSchema = new Schema();
|
||||
$RedisSchema->setName('Redis');
|
||||
$RedisSchema->setDefinition('Host', '127.0.0.1');
|
||||
|
@ -101,16 +106,6 @@
|
|||
return self::autoConfig()->getConfiguration('TelegramService');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database configuration
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getDatabaseConfiguration()
|
||||
{
|
||||
return self::autoConfig()->getConfiguration('Database');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redis configuration
|
||||
|
@ -135,6 +130,17 @@
|
|||
return self::autoConfig()->getConfiguration('BackgroundWorker');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database configuration
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getDatabaseConfiguration()
|
||||
{
|
||||
return self::autoConfig()->getConfiguration('Database');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TelegramClientManager
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
/** @noinspection PhpUnused */
|
||||
/** @noinspection PhpIllegalPsrClassPathInspection */
|
||||
|
||||
namespace Longman\TelegramBot\Commands\SystemCommands;
|
||||
|
||||
use Longman\TelegramBot\Commands\SystemCommand;
|
||||
use Longman\TelegramBot\Entities\ServerResponse;
|
||||
use Longman\TelegramBot\Exception\TelegramException;
|
||||
use Longman\TelegramBot\Request;
|
||||
use SpamProtectionBot;
|
||||
use TelegramClientManager\Abstracts\TelegramChatType;
|
||||
|
||||
/**
|
||||
* Start command
|
||||
*
|
||||
* Gets executed when a user first starts using the bot.
|
||||
*/
|
||||
class StartCommand extends SystemCommand
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'start';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Gets executed when a user first starts using the bot.';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = '/start';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '1.0.0';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $private_only = false;
|
||||
|
||||
/**
|
||||
* The whois command used for finding targets
|
||||
*
|
||||
* @var WhoisCommand|null
|
||||
*/
|
||||
public $WhoisCommand = null;
|
||||
|
||||
/**
|
||||
* Command execute method
|
||||
*
|
||||
* @return ServerResponse
|
||||
* @throws TelegramException
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public function execute(): ServerResponse
|
||||
{
|
||||
// Ignore forwarded commands
|
||||
if($this->getMessage()->getForwardFrom() !== null || $this->getMessage()->getForwardFromChat())
|
||||
{
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
|
||||
switch($this->getMessage()->getChat()->getType())
|
||||
{
|
||||
case TelegramChatType::SuperGroup:
|
||||
case TelegramChatType::Group:
|
||||
return Request::sendMessage([
|
||||
"chat_id" => $this->getMessage()->getChat()->getId(),
|
||||
"reply_to_message_id" => $this->getMessage()->getMessageId(),
|
||||
"parse_mode" => "html",
|
||||
"text" => "Hello World!"
|
||||
]);
|
||||
|
||||
|
||||
case TelegramChatType::Private:
|
||||
return Request::sendMessage([
|
||||
"chat_id" => $this->getMessage()->getChat()->getId(),
|
||||
"reply_to_message_id" => $this->getMessage()->getMessageId(),
|
||||
"parse_mode" => "html",
|
||||
"text" => "Hello User!"
|
||||
]);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
}
|
44
botsrc/main
44
botsrc/main
|
@ -16,19 +16,15 @@
|
|||
use Longman\TelegramBot\Exception\TelegramException;
|
||||
use Longman\TelegramBot\Request;
|
||||
use ppm\ppm;
|
||||
use ProcLib\Abstracts\Types\StdType;
|
||||
use ProcLib\Process;
|
||||
use ProcLib\Utilities\PhpExecutableFinder;
|
||||
use VerboseAdventure\Abstracts\EventType;
|
||||
use VerboseAdventure\Classes\ErrorHandler;
|
||||
use VerboseAdventure\VerboseAdventure;
|
||||
|
||||
// Import all required auto loaders
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require('ppm');
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
ppm::import('net.intellivoid.spam_protection_bot');
|
||||
ppm::import('net.intellivoid.synical_bot');
|
||||
|
||||
VerboseAdventure::setStdout(true); // Enable stdout
|
||||
ErrorHandler::registerHandlers(); // Register error handlers
|
||||
|
@ -37,9 +33,6 @@
|
|||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$TelegramServiceConfiguration = SynicalBot::getTelegramConfiguration();
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$DatabaseConfiguration = SynicalBot::getDatabaseConfiguration();
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$BackgroundWorkerConfiguration = SynicalBot::getBackgroundWorkerConfiguration();
|
||||
|
||||
|
@ -102,37 +95,6 @@
|
|||
exit(255);
|
||||
}
|
||||
|
||||
// Start the verdict thread
|
||||
$phpExecutableFinder = new PhpExecutableFinder();
|
||||
$phpBinLocation = $phpExecutableFinder->find();
|
||||
$VerdictThread = new Process([$phpBinLocation, getcwd() . DIRECTORY_SEPARATOR . 'verdict_worker']);
|
||||
$VerdictCallbackThread = function ($type, $buffer)
|
||||
{
|
||||
$buffer_split = implode("\n", explode("\r\n", $buffer));
|
||||
$buffer_split = explode("\n", $buffer_split);
|
||||
foreach ($buffer_split as $item) {
|
||||
if (strlen($item) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (stripos($item, 'flush(gearman_could_not_connect)'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (strtolower($type)) {
|
||||
case "out":
|
||||
case StdType::STDOUT:
|
||||
SynicalBot::getLogHandler()->log(EventType::INFO, $item, 'Verdict Thread');
|
||||
break;
|
||||
case "err":
|
||||
case StdType::STDERR:
|
||||
SynicalBot::getLogHandler()->log(EventType::ERROR, $item, 'Verdict Thread');
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
$VerdictThread->start($VerdictCallbackThread);
|
||||
|
||||
$next_event_update = time() + 60;
|
||||
$total_update_count = 0;
|
||||
|
||||
|
@ -141,10 +103,6 @@
|
|||
{
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
SynicalBot::$BackgroundWorker->getSupervisor()->monitor(TELEGRAM_BOT_NAME);
|
||||
if($VerdictThread->isRunning() == false)
|
||||
{
|
||||
$VerdictThread->restart($VerdictCallbackThread);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"package": {
|
||||
"package_name": "net.intellivoid.synical_bot",
|
||||
"name": "Telegram SynicalBot",
|
||||
"version": "3.0.0.0",
|
||||
"version": "1.0.0.0",
|
||||
"author": "Zi Xing Narrakas",
|
||||
"organization": "Intellivoid",
|
||||
"description": "A next-generation group management bot",
|
||||
|
@ -20,24 +20,6 @@
|
|||
"source": "default@github/intellivoid/BackgroundWorker",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"package": "net.intellivoid.coffeehouse",
|
||||
"version": "latest",
|
||||
"source": "default@github/intellivoid/coffeehouse",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"package": "net.intellivoid.deepanalytics",
|
||||
"version": "latest",
|
||||
"source": "default@github/intellivoid/DeepAnalytics",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"package": "net.intellivoid.spam_protection",
|
||||
"version": "latest",
|
||||
"source": "default@github/intellivoid/SpamProtection",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"package": "net.intellivoid.telegram_client_manager",
|
||||
"version": "latest",
|
||||
|
@ -101,133 +83,17 @@
|
|||
"components": [
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/AgdemoteCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/AgpromoteCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/AppealCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/BakaMitaiCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/BlacklistCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/BlCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/CallbackqueryCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/CheckAppealCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/CreateInviteCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/FinalVerdictCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/GenericmessageCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/HelpCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/LanguageCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/LCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/LogCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/MsgInfoCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/NewchatmembersCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/OpdemoteCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/OppromoteCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/PredictionsCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/PropCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/ResetCacheCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/ResetPredictionsCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/SettingsCommand.php"
|
||||
"file": "SynicalBot.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/StartCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/StatsCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "commands/WhoisCommand.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "SpamProtectionBot.php"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
".htaccess",
|
||||
"commands/help_docs/blacklist_flags.html",
|
||||
"commands/help_docs/false_detections.html",
|
||||
"commands/help_docs/help.html",
|
||||
"commands/help_docs/help.png",
|
||||
"commands/help_docs/language.html",
|
||||
"commands/help_docs/msginfo.html",
|
||||
"commands/help_docs/settings.html",
|
||||
"commands/help_docs/spam_protection.html",
|
||||
"commands/help_docs/start.html",
|
||||
"commands/help_docs/unwanted_users.html",
|
||||
"commands/help_docs/whois.html",
|
||||
"main",
|
||||
"package.json",
|
||||
"verdict_worker",
|
||||
"worker"
|
||||
"worker",
|
||||
".htaccess",
|
||||
"main"
|
||||
]
|
||||
}
|
|
@ -10,25 +10,21 @@
|
|||
*/
|
||||
|
||||
use BackgroundWorker\BackgroundWorker;
|
||||
use CoffeeHouse\CoffeeHouse;
|
||||
use DeepAnalytics\DeepAnalytics;
|
||||
use Longman\TelegramBot\Entities\ServerResponse;
|
||||
use Longman\TelegramBot\Entities\Update;
|
||||
use Longman\TelegramBot\TelegramLog;
|
||||
use Longman\TelegramBot\Request;
|
||||
use ppm\ppm;
|
||||
use SpamProtection\SpamProtection;
|
||||
use TelegramClientManager\TelegramClientManager;
|
||||
use VerboseAdventure\Abstracts\EventType;
|
||||
use VerboseAdventure\Classes\ErrorHandler;
|
||||
use VerboseAdventure\VerboseAdventure;
|
||||
|
||||
// Import all required auto loaders
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require('ppm');
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
ppm::import('net.intellivoid.spam_protection_bot');
|
||||
ppm::import('net.intellivoid.synical_bot');
|
||||
|
||||
$current_directory = getcwd();
|
||||
VerboseAdventure::setStdout(true); // Enable stdout
|
||||
|
@ -37,13 +33,13 @@
|
|||
|
||||
if(class_exists('SynicalBot') == false)
|
||||
{
|
||||
if(file_exists($current_directory . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php'))
|
||||
if(file_exists($current_directory . DIRECTORY_SEPARATOR . 'SynicalBot.php'))
|
||||
{
|
||||
require_once($current_directory . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php');
|
||||
require_once($current_directory . DIRECTORY_SEPARATOR . 'SynicalBot.php');
|
||||
}
|
||||
elseif(file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php'))
|
||||
elseif(file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'SynicalBot.php'))
|
||||
{
|
||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php');
|
||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'SynicalBot.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -100,11 +96,11 @@
|
|||
);
|
||||
$telegram->setVerboseLogging($TelegramServiceConfiguration['VerboseLogging']);
|
||||
|
||||
if(file_exists($current_directory . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php'))
|
||||
if(file_exists($current_directory . DIRECTORY_SEPARATOR . 'SynicalBot.php'))
|
||||
{
|
||||
$telegram->addCommandsPaths([$current_directory . DIRECTORY_SEPARATOR . 'commands']);
|
||||
}
|
||||
elseif(file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'SpamProtectionBot.php'))
|
||||
elseif(file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'SynicalBot.php'))
|
||||
{
|
||||
$telegram->addCommandsPaths([__DIR__ . DIRECTORY_SEPARATOR . 'commands']);
|
||||
}
|
||||
|
@ -146,9 +142,6 @@
|
|||
exit(255);
|
||||
}
|
||||
|
||||
// Start the worker instance
|
||||
SynicalBot::$DeepAnalytics = new DeepAnalytics();
|
||||
|
||||
// Create the database connections
|
||||
SynicalBot::$TelegramClientManager = new TelegramClientManager();
|
||||
if(SynicalBot::$TelegramClientManager->getDatabase()->connect_error)
|
||||
|
@ -157,20 +150,6 @@
|
|||
exit(255);
|
||||
}
|
||||
|
||||
SynicalBot::$SpamProtection = new SpamProtection();
|
||||
if(SynicalBot::$SpamProtection->getDatabase()->connect_error)
|
||||
{
|
||||
SynicalBot::getLogHandler()->log(EventType::ERROR, 'Failed to initialize SpamProtection, ' . SynicalBot::$SpamProtection->getDatabase()->connect_error, 'Worker');
|
||||
exit(255);
|
||||
}
|
||||
|
||||
SynicalBot::$CoffeeHouse = new CoffeeHouse();
|
||||
if(SynicalBot::$CoffeeHouse->getDatabase()->connect_error)
|
||||
{
|
||||
SynicalBot::getLogHandler()->log(EventType::ERROR, 'Failed to initialize CoffeeHouse, ' . SynicalBot::$CoffeeHouse->getDatabase()->connect_error, 'Worker');
|
||||
exit(255);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$BackgroundWorker = new BackgroundWorker();
|
||||
|
|
Loading…
Reference in New Issue