Ejemplo n.º 1
0
 /**
  * Create a new Redis connection instance.
  *
  * @param  array  $servers
  * @return void
  */
 public function __construct(array $servers = [])
 {
     Arr::forget($servers, 'cluster');
     Arr::forget($servers, 'options');
     $this->clients = $this->createClient($servers);
     $this->database = $this->saveDatabase($servers);
 }
Ejemplo n.º 2
0
 /**
  * Get all of the input except for a specified array of items.
  *
  * @param  array  $keys
  * @return array
  */
 public function except($keys)
 {
     $keys = is_array($keys) ? $keys : func_get_args();
     $results = self::all();
     Arr::forget($results, $keys);
     return $results;
 }
Ejemplo n.º 3
0
 public static final function onDeletedResource($response)
 {
     $data = (array) json_decode($response->getBody(), true);
     Arr::forget($data, ['code', 'message']);
     $data = json_encode($data);
     return $response->withBody(Psr7\stream_for($data));
 }
Ejemplo n.º 4
0
 /**
  * Remove index
  *
  * @param $index
  * @return $this
  */
 public function remove($index)
 {
     if ($this->has($index)) {
         Arr::forget($this->data, $index);
         Arr::forget($this->metas, $this->firstIndex($index));
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Remove an item from the configuration
  *
  * @param  string $key
  * @return boolean
  */
 public function forget($key)
 {
     if ($this->has($key)) {
         $this->arrHelper->forget($this->data, $key);
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Starts the bot.
  *
  * @return void 
  */
 public function start()
 {
     set_error_handler(function ($errno, $errstr) {
         if (!(error_reporting() & $errno)) {
             return;
         }
         echo "[Error] {$errno} {$errstr}\r\n";
         throw new \Exception($errstr, $errno);
     }, E_ALL);
     foreach ($this->commands as $command => $data) {
         $this->websocket->on(Event::MESSAGE_CREATE, function ($message, $discord, $new) use($command, $data) {
             $content = explode(' ', $message->content);
             $config = Config::getConfig($this->configfile);
             if ($content[0] == $config['prefix'] . $command) {
                 Arr::forget($content, 0);
                 $user_perms = @$config['perms']['perms'][$message->author->id];
                 if (empty($user_perms)) {
                     $user_perms = $config['perms']['default'];
                 }
                 if ($user_perms >= $data['perms']) {
                     try {
                         $data['class']::handleMessage($message, $content, $discord, $config, $this);
                     } catch (\Exception $e) {
                         $message->reply("There was an error running the command. `{$e->getMessage()}`");
                     }
                 } else {
                     $message->reply('You do not have permission to do this!');
                     echo "[Auth] User {$message->author->username} blocked from running {$config['prefix']}{$command}, <@{$message->author->id}>\r\n";
                 }
             }
         });
     }
     $this->websocket->on('ready', function ($discord) {
         $discord->updatePresence($this->websocket, 'DiscordPHP ' . Discord::VERSION, false);
     });
     $this->websocket->on('error', function ($error, $ws) {
         echo "[Error] {$error}\r\n";
     });
     $this->websocket->on('close', function () {
         echo "[Close] WebSocket was closed.\r\n";
         die;
     });
     $this->websocket->run();
 }
 /**
  * Unset a single item in a given Request’s input using dot-notation
  * @param Request $request to modify
  * @param string $key in dot-notation
  */
 protected function unsetRequestInput(Request $request, $key)
 {
     if (strpos($key, '.')) {
         // The data to unset is deeper than 1 level down
         // meaning the final value of the input's first level key is expected to be an array
         list($first_level_key, $key_rest) = explode('.', $key, 2);
         // Pull out the input's existing first level value to modify it as an array
         $first_level_value = $request->input($first_level_key);
         //Request::input() pulls from all input data using dot-notation (ArrayAccess on Request would also pull out files which is undesirable here).
         if (!is_array($first_level_value)) {
             $first_level_value = [];
         }
         Arr::forget($first_level_value, $key_rest);
         $request->merge([$first_level_key => $first_level_value]);
         // The only current alternatives for modifying Request input data are merge() and replace(), the latter replacing the whole input data.
     } else {
         // The data to unset is in the first level
         unset($request[$key]);
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     A::forget($this->expressions, $key);
     $this->reload();
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Get all of the origin input except for a specified array of items.
  *
  * @param array|mixed $keys item keys
  * @return array
  */
 public function originExcept($keys)
 {
     $keys = is_array($keys) ? $keys : func_get_args();
     $results = $this->originAll();
     Arr::forget($results, $keys);
     return $results;
 }
Ejemplo n.º 10
0
 /**
  * Remove an item from the session.
  *
  * @param string $key
  *
  * @return void
  */
 public static function forget($key)
 {
     Arr::forget($_SESSION, $key);
 }
Ejemplo n.º 11
0
 /**
  * Remove an item from the session.
  *
  * @param  string  $key
  * @return void
  */
 public function forget($key)
 {
     Arr::forget($this->attributes, $key);
 }
Ejemplo n.º 12
0
 /**
  * Remove validation option.
  *
  * @param string $type
  * @param string $key
  *
  * @throws ValidateException
  *
  * @return array
  */
 protected function removeValidationOption($type, $key)
 {
     $this->checkValidationTypes($type);
     Arr::forget($this->validationOptions, "{$type}.{$key}");
     return $this->validationOptions;
 }
Ejemplo n.º 13
0
 /**
  * Forget meta value.
  *
  * @param  string  $key
  *
  * @return void
  */
 public function forget($key)
 {
     Arr::forget($this->meta, $key);
 }
Ejemplo n.º 14
0
 /**
  * Unset the item at a given offset.
  *
  * @param  string  $key
  * @return void
  */
 public function offsetUnset($key)
 {
     $result = $this->convert();
     Arr::forget($result, $key);
     $this->items = Arr::dot($result);
 }
Ejemplo n.º 15
0
 /**
  * Forget a value from the repository file.
  *
  * @param string $key
  */
 public function forget($key)
 {
     $contents = $this->getContents();
     Arr::forget($contents, $key);
     $this->saveContents($contents);
 }
Ejemplo n.º 16
0
 /**
  * Forget setting
  *
  * @param $key string
  */
 public function forget($key)
 {
     $this->load();
     if ($this->has($key)) {
         $this->dirt[$key] = ['type' => 'deleted'];
         Arr::forget($this->settings, $key);
     }
 }
Ejemplo n.º 17
0
 /**
  * Remove a key from all language files.
  *
  * @param string $fileName
  * @param string $key
  * @return void
  */
 public function removeKey($fileName, $key)
 {
     foreach ($this->languages() as $language) {
         $filePath = $this->path . "/{$language}/{$fileName}.php";
         $fileContent = $this->getFileContent($filePath);
         Arr::forget($fileContent, $key);
         $this->writeFile($filePath, $fileContent);
     }
 }
 /**
  * Converts result_array number indexed array and consider excess columns
  *
  * @return null
  * @throws \Exception
  */
 protected function regulateArray()
 {
     foreach ($this->result_array as $key => $value) {
         foreach ($this->removed_columns as $remove_col_name) {
             if ($this->dataFullSupport) {
                 Arr::forget($value, $remove_col_name);
             } else {
                 unset($value[$remove_col_name]);
             }
         }
         if ($this->mDataSupport || $this->dataFullSupport) {
             $row = $value;
         } else {
             $row = array_values($value);
         }
         if ($this->index_column !== null) {
             if (array_key_exists($this->index_column, $value)) {
                 $row['DT_RowId'] = $value[$this->index_column];
             } else {
                 $row['DT_RowId'] = $this->getContent($this->index_column, $value, $this->result_object[$key]);
             }
         }
         if ($this->row_class_tmpl !== null) {
             $row['DT_RowClass'] = $this->getContent($this->row_class_tmpl, $value, $this->result_object[$key]);
         }
         if (count($this->row_data_tmpls)) {
             $row['DT_RowData'] = array();
             foreach ($this->row_data_tmpls as $tkey => $tvalue) {
                 $row['DT_RowData'][$tkey] = $this->getContent($tvalue, $value, $this->result_object[$key]);
             }
         }
         $this->result_array_return[] = $row;
     }
 }
Ejemplo n.º 19
0
 /**
  * Remove setting from the database
  *
  * @param $key
  */
 public function forget($key)
 {
     $this->prepare();
     if ($this->has($key)) {
         Arr::forget($this->data, $key);
         $this->deleted[$key] = null;
     }
 }
Ejemplo n.º 20
0
 /**
  * Create a new customer.
  *
  * @param array $properties
  * 
  * @return Customer
  */
 public function create(array $properties = array())
 {
     if (Arr::get($properties, 'card_token')) {
         $properties = array_merge($properties, ['paymentMethodNonce' => Arr::get($properties, 'card_token')]);
         Arr::forget($properties, 'card_token');
     }
     $result = Braintree_Customer::create(array_filter($properties));
     //Check if success or not before continue !! throw exception
     if ($result->success) {
         $this->braintree_customer = $result->customer;
     } else {
         $verification = $result->creditCardVerification;
         $error = "";
         if ($verification->status == 'processor_declined') {
             $error = $verification->processorResponseText;
         }
         if ($verification->status == 'gateway_rejected') {
             $error = $verification->gatewayRejectionReason;
         }
         // return Response::json($result, 422);
         throw new Exception($error);
     }
     $this->id = $this->braintree_customer->id;
     return $this;
 }
Ejemplo n.º 21
0
 /**
  * Remove item form Collection.
  *
  * @param string $key
  */
 public function forget($key)
 {
     Arr::forget($this->items, $key);
 }
Ejemplo n.º 22
0
 /**
  * Forget setting key
  *
  * @param $key
  */
 public function forget($key)
 {
     $this->prepare();
     $this->isDirty = true;
     Arr::forget($this->data, $key);
 }
Ejemplo n.º 23
0
 /**
  * Remove one or many array items from a given array using "dot" notation.
  *
  * @param  array $array
  * @param  array|string $keys
  * @return void
  */
 function array_forget(&$array, $keys)
 {
     return Arr::forget($array, $keys);
 }
Ejemplo n.º 24
0
 /**
  * Starts the bot.
  *
  * @return void 
  */
 public function start()
 {
     // set_error_handler(function ($errno, $errstr) {
     // 	if (!(error_reporting() & $errno)) {
     // 		return;
     // 	}
     // 	echo "[Error] {$errno} {$errstr}\r\n";
     // 	throw new \Exception($errstr, $errno);
     // }, E_ALL);
     $this->websocket->on(Event::MESSAGE_CREATE, function ($message, $discord, $new) {
         $config = Config::getConfig($this->configfile);
         if (substr($message->content, 0, strlen($config['prefix'])) == $config['prefix']) {
             foreach ($this->commands as $command => $data) {
                 $parts = [];
                 $content = explode(' ', $message->content);
                 foreach ($content as $index => $c) {
                     foreach (explode("\n", $c) as $p) {
                         $parts[] = $p;
                     }
                 }
                 $content = $parts;
                 if ($content[0] == $config['prefix'] . $command) {
                     array_shift($content);
                     $user_perms = @$config['perms']['perms'][$message->author->id];
                     if (empty($user_perms)) {
                         $user_perms = $config['perms']['default'];
                     }
                     if ($user_perms >= $data['perms']) {
                         try {
                             $data['class']::handleMessage($message, $content, $new, $config, $this);
                             $this->log->addInfo("{$message->author->username}#{$message->author->discriminator} ({$message->author}) ran command {$config['prefix']}{$command}", $content);
                         } catch (\Throwable $e) {
                             try {
                                 $this->log->addError("Error running the command {$config['prefix']}{$command}", ['message' => $e->getMessage()]);
                                 $message->reply("There was an error running the command. `{$e->getMessage()}`");
                             } catch (\Throwable $e2) {
                             }
                         }
                     } else {
                         try {
                             $message->reply('You do not have permission to do this!');
                         } catch (\Throwable $e2) {
                         }
                         $this->log->addWarning("{$message->author->username}#{$message->author->discriminator} ({$message->author}) attempted to run command {$config['prefix']}{$command}", $content);
                     }
                 }
             }
         }
     });
     $this->websocket->on(Event::MESSAGE_CREATE, function ($message, $discord, $new) {
         $triggers = ['bless up', ':pray:', '🙏'];
         if (Str::contains(strtolower($message->content), $triggers) && $message->author->id != $discord->id) {
             $config = Config::getConfig($this->configfile);
             $content = explode(' ', $message->content);
             Arr::forget($content, 0);
             Khaled::handleMessage($message, $content, $new, $config, $this);
         }
     });
     $this->websocket->on(Event::MESSAGE_CREATE, function ($message, $discord, $new) {
         if ($message->author->id == '81726071573061632' && strtolower($message->content) == 'we dem') {
             $message->channel->sendMessage('BOIZ');
         }
     });
     $this->websocket->on('ready', function ($discord) {
         $this->log->addInfo('WebSocket is ready.');
         $discord->updatePresence($this->websocket, 'DiscordPHP ' . Discord::VERSION, false);
     });
     $this->websocket->on('error', function ($error, $ws) {
         $this->log->addError("WebSocket encountered an error", [$error->getMessage()]);
     });
     // $this->websocket->on('heartbeat', function ($epoch) {
     // 	echo "Heartbeat at {$epoch}\r\n";
     // });
     $this->websocket->on('close', function ($op, $reason) {
         $this->log->addWarning("WebSocket closed.", ['code' => $op, 'reason' => $reason]);
     });
     $this->websocket->on('reconnecting', function () {
         $this->log->addInfo('WebSocket is reconnecting...');
     });
     $this->websocket->on('reconnected', function () {
         $this->log->addInfo('WebSocket has reconnected.');
     });
     $config = Config::getConfig($this->configfile);
     if (isset($config['cache']) && $config['cache'] == 'redis') {
         Cache::setCache(new RedisCacheDriver('localhost'));
     }
     if (isset($config['carbon_bot']) && $config['carbon_bot']['enabled']) {
         $guzzle = new Client(['http_errors' => false]);
         $body = ['key' => $config['carbon_bot']['key']];
         $this->log->addInfo('Enabling Carbon server count updates...');
         $carbonHeartbeat = function () use($guzzle, &$body) {
             $body['servercount'] = $this->discord->guilds->count();
             $this->log->addDebug('Sending Carbon server count update...');
             $request = new Request('POST', 'https://www.carbonitex.net/discord/data/botdata.php', ['Content-Type' => 'application/json'], json_encode($body));
             $response = $guzzle->send($request);
             if ($response->getStatusCode() !== 200) {
                 $this->log->addWarning('Carbon server count update failed.', ['status' => $response->getStatusCode(), 'reason' => $response->getReasonPhrase()]);
             } else {
                 $this->log->addDebug('Sent Carbon server count update successfully.');
             }
         };
         $carbonHeartbeat();
         $this->websocket->loop->addPeriodicTimer(60, $carbonHeartbeat);
     }
     $this->websocket->run();
 }