not workie
This commit is contained in:
parent
8c2760c028
commit
7dfb124ff3
|
@ -716,48 +716,6 @@
|
|||
],
|
||||
"time": "2014-11-20 16:49:30"
|
||||
},
|
||||
{
|
||||
"name": "ircmaxell/password-compat",
|
||||
"version": "v1.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ircmaxell/password_compat.git",
|
||||
"reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/5c5cde8822a69545767f7c7f3058cb15ff84614c",
|
||||
"reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/password.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anthony Ferrara",
|
||||
"email": "ircmaxell@php.net",
|
||||
"homepage": "http://blog.ircmaxell.com"
|
||||
}
|
||||
],
|
||||
"description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash",
|
||||
"homepage": "https://github.com/ircmaxell/password_compat",
|
||||
"keywords": [
|
||||
"hashing",
|
||||
"password"
|
||||
],
|
||||
"time": "2014-11-20 16:49:30"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.22.1",
|
||||
|
@ -1700,7 +1658,7 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/intl",
|
||||
"version": "v3.2.6",
|
||||
"version": "v3.2.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/intl.git",
|
||||
|
@ -1775,16 +1733,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/options-resolver",
|
||||
"version": "v3.2.6",
|
||||
"version": "v3.2.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/options-resolver.git",
|
||||
"reference": "56e3d0a41313f8a54326851f10690d591e62a24c"
|
||||
"reference": "6a19be85237fe8bbd4975f86942b4763bb0da6ca"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/56e3d0a41313f8a54326851f10690d591e62a24c",
|
||||
"reference": "56e3d0a41313f8a54326851f10690d591e62a24c",
|
||||
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/6a19be85237fe8bbd4975f86942b4763bb0da6ca",
|
||||
"reference": "6a19be85237fe8bbd4975f86942b4763bb0da6ca",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1825,7 +1783,7 @@
|
|||
"configuration",
|
||||
"options"
|
||||
],
|
||||
"time": "2017-02-21 09:12:04"
|
||||
"time": "2017-03-21 21:44:32"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -1918,16 +1876,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/translation",
|
||||
"version": "v3.2.6",
|
||||
"version": "v3.2.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/translation.git",
|
||||
"reference": "0e1b15ce8fbf3890f4ccdac430ed5e07fdfe0690"
|
||||
"reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/0e1b15ce8fbf3890f4ccdac430ed5e07fdfe0690",
|
||||
"reference": "0e1b15ce8fbf3890f4ccdac430ed5e07fdfe0690",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/c740eee70783d2af4d3d6b70d5146f209e6b4d13",
|
||||
"reference": "c740eee70783d2af4d3d6b70d5146f209e6b4d13",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1978,7 +1936,7 @@
|
|||
],
|
||||
"description": "Symfony Translation Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2017-03-04 12:23:14"
|
||||
"time": "2017-03-21 21:44:32"
|
||||
},
|
||||
{
|
||||
"name": "team-reflex/discord-php",
|
||||
|
@ -2145,18 +2103,6 @@
|
|||
},
|
||||
{
|
||||
"name": "voku/anti-xss",
|
||||
<<<<<<< HEAD
|
||||
"version": "2.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/voku/anti-xss.git",
|
||||
"reference": "697142eb3cd99e06bc0b0779eaa746a63ed718de"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/voku/anti-xss/zipball/697142eb3cd99e06bc0b0779eaa746a63ed718de",
|
||||
"reference": "697142eb3cd99e06bc0b0779eaa746a63ed718de",
|
||||
=======
|
||||
"version": "2.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
|
@ -2167,7 +2113,6 @@
|
|||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/voku/anti-xss/zipball/c5ef94790d9ed8654f1bccfeb6b397cf1fb87d88",
|
||||
"reference": "c5ef94790d9ed8654f1bccfeb6b397cf1fb87d88",
|
||||
>>>>>>> master
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2175,11 +2120,7 @@
|
|||
"voku/portable-utf8": "~3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
<<<<<<< HEAD
|
||||
"phpunit/phpunit": "~4.0"
|
||||
=======
|
||||
"phpunit/phpunit": "~4.0|~5.0"
|
||||
>>>>>>> master
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
|
@ -2215,11 +2156,7 @@
|
|||
"security",
|
||||
"xss"
|
||||
],
|
||||
<<<<<<< HEAD
|
||||
"time": "2017-01-10 16:48:30"
|
||||
=======
|
||||
"time": "2017-04-04 17:07:59"
|
||||
>>>>>>> master
|
||||
},
|
||||
{
|
||||
"name": "voku/email-check",
|
||||
|
@ -2278,18 +2215,6 @@
|
|||
},
|
||||
{
|
||||
"name": "voku/portable-utf8",
|
||||
<<<<<<< HEAD
|
||||
"version": "3.1.16",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/voku/portable-utf8.git",
|
||||
"reference": "545094026ceefa9247a9a122b191150d7a2e6ba5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/voku/portable-utf8/zipball/545094026ceefa9247a9a122b191150d7a2e6ba5",
|
||||
"reference": "545094026ceefa9247a9a122b191150d7a2e6ba5",
|
||||
=======
|
||||
"version": "3.1.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
|
@ -2300,7 +2225,6 @@
|
|||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/voku/portable-utf8/zipball/7fb737ddebc7801f9572daeec9f64cf7cc111088",
|
||||
"reference": "7fb737ddebc7801f9572daeec9f64cf7cc111088",
|
||||
>>>>>>> master
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2357,11 +2281,7 @@
|
|||
"utf-8",
|
||||
"utf8"
|
||||
],
|
||||
<<<<<<< HEAD
|
||||
"time": "2017-03-25 06:21:29"
|
||||
=======
|
||||
"time": "2017-04-05 02:20:36"
|
||||
>>>>>>> master
|
||||
},
|
||||
{
|
||||
"name": "voku/stringy",
|
||||
|
|
|
@ -5,10 +5,10 @@ use Discord\Discord;
|
|||
use Discord\Parts\User\Game;
|
||||
use Discord\Parts\Embed\Embed;
|
||||
|
||||
use BenBot\SerializedArray;
|
||||
use BenBot\Utils;
|
||||
use BenBot\FontConverter;
|
||||
use BenBot\SerializedArray;
|
||||
use BenBot\Command;
|
||||
use BenBot\DebugCommands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
@ -44,16 +44,18 @@ class BenBot extends Discord {
|
|||
]);
|
||||
|
||||
$this->dir = $dir;
|
||||
$this->help = [];
|
||||
$this->jokes = explode("---", file_get_contents("$dir/miscjokes.txt"));
|
||||
$this->yomamajokes = file("$dir/yomamajokes.txt");
|
||||
|
||||
|
||||
$this->game = $this->factory(Game::class, [
|
||||
'name' => 'type ;help for info',
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->defs = new SerializedArray("$dir/bot_data/defs.mp");
|
||||
$this->imgs = new SerializedArray("$dir/bot_data/defs.mp");
|
||||
$this->imgs = new SerializedArray("$dir/bot_data/img_urls.mp");
|
||||
$this->cities = new SerializedArray("$dir/bot_data/cities.mp");
|
||||
$this->emails = new SerializedArray("$dir/bot_data/emails.mp");
|
||||
} catch (Exception $e) {
|
||||
|
@ -61,6 +63,7 @@ class BenBot extends Discord {
|
|||
}
|
||||
|
||||
$this->on('ready', function () {
|
||||
Utils::init($this);
|
||||
$this->updatePresence($this->game);
|
||||
|
||||
$this->on('message', function ($msg) {
|
||||
|
@ -72,10 +75,10 @@ class BenBot extends Discord {
|
|||
$qu = (string) $cmd;
|
||||
|
||||
if (isset($this->defs[$qu])) {
|
||||
$this->utils->send($msg, "**$qu**: " . $this->defs[$qu]);
|
||||
Utils::send($msg, "**$qu**: " . $this->defs[$qu]);
|
||||
}
|
||||
if (isset($this->imgs[$qu])) {
|
||||
$this->utils->sendFile($msg, "{$this->dir}/uploaded_images/{$this->imgs[$qu]}", $this->imgs[$qu], $qu);
|
||||
Utils::sendFile($msg, "{$this->dir}/uploaded_images/{$this->imgs[$qu]}", $this->imgs[$qu], $qu);
|
||||
}
|
||||
|
||||
if (array_key_exists($qu, $this->cmds)) {
|
||||
|
@ -86,17 +89,20 @@ class BenBot extends Discord {
|
|||
return;
|
||||
}
|
||||
|
||||
foreach ($args as $key => $arg) {
|
||||
$args[$key] = (string) $arg;
|
||||
}
|
||||
$result = $command->handle($msg, $args);
|
||||
|
||||
if (is_string($result)) {
|
||||
$msg->reply($result);
|
||||
Utils::send($msg, $result);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (Utils::isDM($msg)) {
|
||||
$msg->channel->broadcastTyping();
|
||||
$this->utils->askCleverbot($str)->then(function ($result) use ($msg) {
|
||||
$this->utils->send($msg, $result->output);
|
||||
Utils::askCleverbot($str)->then(function ($result) use ($msg) {
|
||||
Utils::send($msg, $result->output);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -111,7 +117,6 @@ class BenBot extends Discord {
|
|||
});
|
||||
|
||||
$this->start_time = Carbon::now();
|
||||
// $this->utils->pingMe("bot started successfully");
|
||||
|
||||
$this->registerCommand('help', function ($msg, $args) {
|
||||
if (count($args) > 0) {
|
||||
|
@ -119,24 +124,48 @@ class BenBot extends Discord {
|
|||
$command = $this->getCommand($cmdstr, true);
|
||||
|
||||
if (is_null($command)) {
|
||||
return "The command $cmdstr does not exist";
|
||||
return "The command `;$cmdstr` does not exist";
|
||||
}
|
||||
|
||||
$help = $command->getHelp()["text"];
|
||||
Utils::ssend($msg, "```$help```");
|
||||
Utils::send($msg, "```$help```");
|
||||
} else {
|
||||
$banner = file_get_contents(__DIR__.'/../banner.txt');
|
||||
$banner = file_get_contents("{$this->dir}/banner.txt");
|
||||
$ret = "```$banner\n- a bot made by benh. avatar by hirose.\n\n";
|
||||
sort($this->help);
|
||||
$ret .= implode("", $this->help);
|
||||
$ret .= "\n;help <command> - get more information about a specific command\ncommands will still work if the first letter is capitalized.```";
|
||||
Utils::ssend($msg, $ret);
|
||||
Utils::send($msg, $ret);
|
||||
}
|
||||
});
|
||||
}, [
|
||||
'description' => 'shows help text',
|
||||
'usage' => '<command>',
|
||||
]);
|
||||
|
||||
// $this->registerAllCommands();
|
||||
// DebugCommands::register($this);
|
||||
if (!class_exists('BenBot\DebugCommands')) {
|
||||
throw new \Exception("DebugCommands not found");
|
||||
} else {
|
||||
echo "DebugCommands found...", PHP_EOL;
|
||||
}
|
||||
DebugCommands::test();
|
||||
DebugCommands::init($this);
|
||||
Utils::ping("bot started successfully");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function registerAllCommands()
|
||||
{
|
||||
DebugCommands::register($this);
|
||||
echo "registering all commands", PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function registerCommand($command, $callable, array $options = [])
|
||||
{
|
||||
if (array_key_exists($command, $this->cmds)) {
|
||||
|
@ -157,6 +186,7 @@ class BenBot extends Discord {
|
|||
return $commandInstance;
|
||||
}
|
||||
|
||||
|
||||
public function unregisterCommand($command)
|
||||
{
|
||||
if (!array_key_exists($command, $this->cmds)) {
|
||||
|
@ -165,11 +195,13 @@ class BenBot extends Discord {
|
|||
unset($this->cmds[$command]);
|
||||
}
|
||||
|
||||
|
||||
public function registerAlias($alias, $command)
|
||||
{
|
||||
$this->aliases[$alias] = $command;
|
||||
}
|
||||
|
||||
|
||||
public function unregisterAlias($alias)
|
||||
{
|
||||
if (!array_key_exist($alias, $this->aliases)) {
|
||||
|
@ -178,6 +210,7 @@ class BenBot extends Discord {
|
|||
unset($this->aliases[$alias]);
|
||||
}
|
||||
|
||||
|
||||
public function getCommand($command, $aliases = true)
|
||||
{
|
||||
if (array_key_exists($command, $this->cmds)) {
|
||||
|
@ -188,6 +221,7 @@ class BenBot extends Discord {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function buildCommand($command, $callable, array $options = [])
|
||||
{
|
||||
if (!is_callable($callable)) {
|
||||
|
@ -201,6 +235,7 @@ class BenBot extends Discord {
|
|||
return [$commandInstance, $options];
|
||||
}
|
||||
|
||||
|
||||
public function resolveCommandOptions(array $options)
|
||||
{
|
||||
$resolver = new OptionsResolver();
|
||||
|
@ -224,6 +259,7 @@ class BenBot extends Discord {
|
|||
return $options;
|
||||
}
|
||||
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
$allowed = ['commands', 'aliases'];
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace BenBot\Commands;
|
||||
|
||||
use BenBot\Utils;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Debug {
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
echo "hi from Debug.php", PHP_EOL;
|
||||
self::$bot = $that;
|
||||
self::$bot->registerCommand('up', ['self', 'up'], [
|
||||
'description' => 'shows uptime',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function up($msg, $args)
|
||||
{
|
||||
return "benbot has been up for " . self::$bot->start_time->diffForHumans(Carbon::now(), true)};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
namespace BenBot;
|
||||
|
||||
use BenBot\Utils;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DebugCommands {
|
||||
// BenBot client instance
|
||||
private static $bot;
|
||||
|
||||
public static function register(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
echo "hi from DebugCommands.php", PHP_EOL;
|
||||
self::$bot->registerCommand('up', [__CLASS__, 'up'], [
|
||||
'description' => 'shows uptime',
|
||||
'registerHelp' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function init(&$that)
|
||||
{
|
||||
self::$bot = $that;
|
||||
print_r(self::$bot);
|
||||
self::$bot->registerCommand('up', [__CLASS__, 'up']);
|
||||
echo "DebugCommands registered.", PHP_EOL;
|
||||
}
|
||||
|
||||
public static function test()
|
||||
{
|
||||
echo "test static function in DebugCommands.php", PHP_EOL;
|
||||
}
|
||||
|
||||
public static function up($msg, $args)
|
||||
{
|
||||
return "benbot has been up for " . self::$bot->start_time->diffForHumans(Carbon::now(), true)};
|
||||
}
|
||||
}
|
|
@ -5,47 +5,68 @@ use Carbon\Carbon;
|
|||
use Discord\Parts\Embed\Embed;
|
||||
use React\Promise\Deferred;
|
||||
|
||||
class Utils extends BenBot {
|
||||
class Utils {
|
||||
|
||||
public function mysend($msg, $txt, $embed = null)
|
||||
private static $bot;
|
||||
|
||||
public static function init(&$that)
|
||||
{
|
||||
return $msg->channel->sendMessage($txt, false, $embed)
|
||||
->otherwise(function($e) use ($msg) {
|
||||
self::$bot = $that;
|
||||
print_r(self::$bot);
|
||||
self::$bot->registerCommand('hi', [__CLASS__, 'hifn']);
|
||||
self::$bot->registerCommand('ping', [__CLASS__, 'pingfn']);
|
||||
echo "Utils initialized.", PHP_EOL;
|
||||
}
|
||||
|
||||
public static function hifn($msg, $args)
|
||||
{
|
||||
return "henlo";
|
||||
}
|
||||
|
||||
public static function pingfn($msg, $args)
|
||||
{
|
||||
self::ping("this is a test")->then(function ($result) use ($msg) {
|
||||
$msg->reply("thanks");
|
||||
}, function ($e) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
$this->pingMe($e->getMessage());
|
||||
$msg->reply("sry, an error occurred. check with <@193011352275648514>.\n```{$e->getMessage()}```");
|
||||
});
|
||||
}
|
||||
|
||||
public static function ssend($msg, $txt, $embed = null)
|
||||
|
||||
public static function send($msg, $txt, $embed = null)
|
||||
{
|
||||
return $msg->channel->sendMessage($txt, false, $embed)
|
||||
->otherwise(function($e) use ($msg) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
$msg->reply("sry, an error occurred. check with <@193011352275648514>.\n```{$e->getMessage()}```");
|
||||
self::ping($e->getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
public function sendFile($msg, $filepath, $filename, $txt)
|
||||
|
||||
public static function sendFile($msg, $filepath, $filename, $txt)
|
||||
{
|
||||
return $msg->channel->sendFile($filepath, $filename, $txt)
|
||||
->otherwise(function($e) use ($msg) {
|
||||
echo $e->getMessage(), PHP_EOL;
|
||||
$this->pingMe($e->getMessage());
|
||||
$msg->reply("sry, an error occurred. check with <@193011352275648514>.\n```{$e->getMessage()}```");
|
||||
self::ping($e->getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static function isDM($msg)
|
||||
{
|
||||
return $msg->channel->is_private;
|
||||
}
|
||||
|
||||
|
||||
public static function timestampFromSnowflake ($snowflake)
|
||||
{
|
||||
return (($snowflake / 4194304) + 1420070400000) / 1000;
|
||||
}
|
||||
|
||||
|
||||
public static function celsiusToFahrenheit($celsius)
|
||||
{
|
||||
return $celsius * 9 / 5 + 32;
|
||||
|
@ -56,10 +77,10 @@ class Utils extends BenBot {
|
|||
return $fahrenheit * 5 / 9 + 32;
|
||||
}
|
||||
|
||||
public function formatWeatherJson($json, $timezone = null)
|
||||
public static function formatWeatherJson($json, $timezone = null)
|
||||
{
|
||||
|
||||
return $this->factory(Embed::class, [
|
||||
return self::$bot->factory(Embed::class, [
|
||||
'title' => "Weather in {$json->name}, {$json->sys->country}",
|
||||
'thumbnail' => ['url' => "http://openweathermap.org/img/w/{$json->weather[0]->icon}.png"],
|
||||
'fields' => [
|
||||
|
@ -103,14 +124,14 @@ class Utils extends BenBot {
|
|||
|
||||
|
||||
|
||||
public function askCleverbot($input)
|
||||
public static function askCleverbot($input)
|
||||
{
|
||||
$deferred = new Deferred();
|
||||
|
||||
$url = "https://www.cleverbot.com/getreply";
|
||||
$key = getenv('CLEVERBOT_API_KEY');
|
||||
$input = rawurlencode($input);
|
||||
$this->discord->http->get("$url?input=$input&key=$key", null, [], false)->then(function ($apidata) use ($deferred) {
|
||||
self::$bot->discord->http->get("$url?input=$input&key=$key", null, [], false)->then(function ($apidata) use ($deferred) {
|
||||
$deferred->resolve($apidata);
|
||||
}, function ($e) {
|
||||
$deferred->reject($e);
|
||||
|
@ -119,11 +140,15 @@ class Utils extends BenBot {
|
|||
return $deferred->promise();
|
||||
}
|
||||
|
||||
public function pingMe($msg)
|
||||
|
||||
public static function ping($msg)
|
||||
{
|
||||
return $this
|
||||
if (is_null(self::$bot)) {
|
||||
throw new \Exception("Utils class not initialized");
|
||||
}
|
||||
return self::$bot
|
||||
->guilds->get('id', '289410862907785216')
|
||||
->channels->get('id','289611811094003715')
|
||||
->channels->get('id','297082205048668160')
|
||||
->sendMessage("<@193011352275648514>, $msg");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue