Skip to content

Commit

Permalink
Merge pull request #568 from HDInnovations/analysis-8Kam5A
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
HDVinnie authored Feb 9, 2019
2 parents 9507d07 + f711b76 commit f52e302
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 438 deletions.
1 change: 0 additions & 1 deletion app/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ class Bot extends Model
* @var array
*/
protected $dates = ['deleted_at'];

}
4 changes: 2 additions & 2 deletions app/BotTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BotTransaction extends Model
*/
public $timestamps = true;


/**
* Belongs To A User.
*
Expand Down Expand Up @@ -71,9 +70,10 @@ public function bot()
*/
public function forHumans()
{
if($this->type == 'bon') {
if ($this->type == 'bon') {
return 'BON';
}

return 'Unknown';
}
}
133 changes: 65 additions & 68 deletions app/Bots/CasinoBot.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* NOTICE OF LICENSE
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
Expand All @@ -9,22 +9,22 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author singularity43
*/

namespace App\Bots;

use App\Bot;
use App\User;
use App\UserEcho;
use Carbon\Carbon;
use App\UserAudible;
use App\Bot;
use App\BotTransaction;
use App\UserEcho;
use App\Events\Chatter;
use Carbon\Carbon;
use App\Http\Resources\UserAudibleResource;
use App\Http\Resources\UserEchoResource;
use App\Repositories\ChatRepository;
use App\Http\Resources\UserEchoResource;
use App\Http\Resources\UserAudibleResource;

class CasinoBot
{

private $bot;
private $chat;
private $target;
Expand All @@ -42,47 +42,44 @@ class CasinoBot
*/
public function __construct(ChatRepository $chat)
{
$bot = Bot::where('id','=','3')->firstOrFail();
$bot = Bot::where('id', '=', '3')->firstOrFail();
$this->chat = $chat;
$this->bot = $bot;
$this->expiresAt = Carbon::now()->addMinutes(60);
$this->current = today();
}

/**
* Replace Vars
*
* Replace Vars.
*/
public function replaceVars($output)
{
$output=str_replace("{me}",$this->bot->name,$output);
$output=str_replace("{command}",$this->bot->command,$output);
if(strstr($output,"{bots}")) {
$bot_help = "";
$bots = Bot::where('active','=',1)->where('id','!=',$this->bot->id)->orderBy('position','asc')->get();
foreach($bots as $bot) {
$bot_help.="( ! | / | @)".$bot->command." help triggers help file for ".$bot->name."\n";
$output = str_replace('{me}', $this->bot->name, $output);
$output = str_replace('{command}', $this->bot->command, $output);
if (strstr($output, '{bots}')) {
$bot_help = '';
$bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get();
foreach ($bots as $bot) {
$bot_help .= '( ! | / | @)'.$bot->command.' help triggers help file for '.$bot->name."\n";
}
$output=str_replace("{bots}",$bot_help,$output);
$output = str_replace('{bots}', $bot_help, $output);
}

return $output;
}

/**
* Send Bot Donation
*
* Send Bot Donation.
*/
public function putDonate($amount = 0,$note = '')
public function putDonate($amount = 0, $note = '')
{
$output = implode(" ",$note);
$output = implode(' ', $note);
$v = validator(['bot_id' => $this->bot->id, 'amount'=> $amount, 'note'=> $output], [
'bot_id' => 'required|exists:bots,id|max:999',
'amount' => "required|numeric|min:1|max:{$this->target->seedbonus}",
'note' => 'required|string',
]);
if ($v->passes()) {

$value = $amount;
$this->bot->seedbonus += $value;
$this->bot->save();
Expand All @@ -99,52 +96,50 @@ public function putDonate($amount = 0,$note = '')
$transaction->comment = $output;
$transaction->save();

$donations = BotTransaction::with('user','bot')->where('bot_id','=',$this->bot->id)->where('to_bot','=',1)->latest()->limit(10)->get();
$donations = BotTransaction::with('user', 'bot')->where('bot_id', '=', $this->bot->id)->where('to_bot', '=', 1)->latest()->limit(10)->get();
cache()->put('casinobot-donations', $donations, $this->expiresAt);

return "Your donation to ".$this->bot->name." for ".$amount." BON has been sent!";
return 'Your donation to '.$this->bot->name.' for '.$amount.' BON has been sent!';
}
return "Your donation to ".$output." could not be sent.";

return 'Your donation to '.$output.' could not be sent.';
}

/**
* Get Bot Donations
*
* Get Bot Donations.
*/
public function getDonations($duration = 'default')
{
$donations = cache()->get('casinobot-donations');
if(!$donations|| $donations == null) {
$donations = BotTransaction::with('user','bot')->where('bot_id','=',$this->bot->id)->where('to_bot','=',1)->latest()->limit(10)->get();
if (! $donations || $donations == null) {
$donations = BotTransaction::with('user', 'bot')->where('bot_id', '=', $this->bot->id)->where('to_bot', '=', 1)->latest()->limit(10)->get();
cache()->put('casinobot-donations', $donations, $this->expiresAt);
}
$donation_dump = "";
$donation_dump = '';
$i = 1;
foreach($donations as $donation) {
$donation_dump .= "#" . $i . ". " . $donation->user->username . " sent ".$donation->cost." ".$donation->forHumans()." with note: ".$donation->comment.".\n";
foreach ($donations as $donation) {
$donation_dump .= '#'.$i.'. '.$donation->user->username.' sent '.$donation->cost.' '.$donation->forHumans().' with note: '.$donation->comment.".\n";
$i++;
}

return "The Most Recent Donations To Me Are As Follows:\n\n".trim($donation_dump);
}

/**
* Get Help
*
* Get Help.
*/
public function getHelp()
{
return $this->replaceVars($this->bot->help);
}

/**
* Process Message
*
* Process Message.
*/
public function process($type, User $target, $message = "", $targeted = 0)
public function process($type, User $target, $message = '', $targeted = 0)
{
$this->target = $target;
if($type == 'message') {
if ($type == 'message') {
$x = 0;
$y = 1;
$z = 2;
Expand All @@ -154,45 +149,45 @@ public function process($type, User $target, $message = "", $targeted = 0)
$z = 3;
}

if($message == "") {
$log = "";
if ($message == '') {
$log = '';
} else {
$log = "All ".$this->bot->name." commands must be a private message or begin with /".$this->bot->command." or !".$this->bot->command.". Need help? Type /".$this->bot->command." help and you shall be helped.";
$log = 'All '.$this->bot->name.' commands must be a private message or begin with /'.$this->bot->command.' or !'.$this->bot->command.'. Need help? Type /'.$this->bot->command.' help and you shall be helped.';
}
$command = @explode(" ",$message);
$command = @explode(' ', $message);

$wildcard = null;
$params = null;
if(array_key_exists($y,$command)) {
if (array_key_exists($y, $command)) {
$params = $command[$y];
}

if($params != null) {
if ($params != null) {
$clone = $command;
array_shift($clone);
array_shift($clone);
array_shift($clone);
$wildcard = $clone;
}

if(array_key_exists($x,$command)) {
if($command[$x] == "donations") {
if (array_key_exists($x, $command)) {
if ($command[$x] == 'donations') {
$log = $this->getDonations($params);
}
if($command[$x] == "donate") {
$log = $this->putDonate($params,$wildcard);
if ($command[$x] == 'donate') {
$log = $this->putDonate($params, $wildcard);
}
}
$this->targeted = $targeted;
$this->type = $type;
$this->message = $message;
$this->log = $log;

return $this->pm();
}

/**
* Output Message
*
* Output Message.
*/
public function pm()
{
Expand All @@ -202,15 +197,14 @@ public function pm()
$message = $this->message;
$targeted = $this->targeted;

if($targeted) {
if ($targeted) {
// future holder
}

if($type == 'message' || $type == 'private') {

if ($type == 'message' || $type == 'private') {
$receiver_dirty = 0;
$receiver_echoes = cache()->get('user-echoes' . $target->id);
if (!$receiver_echoes || !is_array($receiver_echoes) || count($receiver_echoes) < 1) {
$receiver_echoes = cache()->get('user-echoes'.$target->id);
if (! $receiver_echoes || ! is_array($receiver_echoes) || count($receiver_echoes) < 1) {
$receiver_echoes = UserEcho::with(['room', 'target', 'bot'])->whereRaw('user_id = ?', [$target->id])->get();
}
$receiver_listening = false;
Expand All @@ -219,7 +213,7 @@ public function pm()
$receiver_listening = true;
}
}
if (!$receiver_listening) {
if (! $receiver_listening) {
$receiver_port = new UserEcho();
$receiver_port->user_id = $target->id;
$receiver_port->bot_id = $this->bot->id;
Expand All @@ -229,12 +223,12 @@ public function pm()
}
if ($receiver_dirty == 1) {
$expiresAt = Carbon::now()->addMinutes(60);
cache()->put('user-echoes' . $target->id, $receiver_echoes, $expiresAt);
event(New Chatter('echo', $target->id, UserEchoResource::collection($receiver_echoes)));
cache()->put('user-echoes'.$target->id, $receiver_echoes, $expiresAt);
event(new Chatter('echo', $target->id, UserEchoResource::collection($receiver_echoes)));
}
$receiver_dirty = 0;
$receiver_audibles = cache()->get('user-audibles' . $target->id);
if (!$receiver_audibles || !is_array($receiver_audibles) || count($receiver_audibles) < 1) {
$receiver_audibles = cache()->get('user-audibles'.$target->id);
if (! $receiver_audibles || ! is_array($receiver_audibles) || count($receiver_audibles) < 1) {
$receiver_audibles = UserAudible::with(['room', 'target', 'bot'])->whereRaw('user_id = ?', [$target->id])->get();
}
$receiver_listening = false;
Expand All @@ -243,7 +237,7 @@ public function pm()
$receiver_listening = true;
}
}
if (!$receiver_listening) {
if (! $receiver_listening) {
$receiver_port = new UserAudible();
$receiver_port->user_id = $target->id;
$receiver_port->bot_id = $this->bot->id;
Expand All @@ -253,30 +247,33 @@ public function pm()
}
if ($receiver_dirty == 1) {
$expiresAt = Carbon::now()->addMinutes(60);
cache()->put('user-audibles' . $target->id, $receiver_audibles, $expiresAt);
event(New Chatter('audible', $target->id, UserAudibleResource::collection($receiver_audibles)));
cache()->put('user-audibles'.$target->id, $receiver_audibles, $expiresAt);
event(new Chatter('audible', $target->id, UserAudibleResource::collection($receiver_audibles)));
}

if ($txt != '') {
$room_id = 0;
$message = $this->chat->privateMessage($target->id, $room_id, $message, 1, $this->bot->id);
$message = $this->chat->privateMessage(1, $room_id, $txt, $target->id, $this->bot->id);
}
return response('success', 200);

} else if($type == 'echo') {
return response('success', 200);
} elseif ($type == 'echo') {
if ($txt != '') {
$room_id = 0;
$message = $this->chat->botMessage($this->bot->id, $room_id, $txt, $target->id);
}

return response('success', 200);
} else if($type == 'public') {
} elseif ($type == 'public') {
if ($txt != '') {
$dumproom = $this->chat->message($target->id, $target->chatroom->id, $message, null, null);
$dumproom = $this->chat->message(1, $target->chatroom->id, $txt, null, $this->bot->id);
}

return response('success', 200);
}

return true;
}
}
}
Loading

0 comments on commit f52e302

Please sign in to comment.