204 lines
6.5 KiB
PHP
204 lines
6.5 KiB
PHP
<?php
|
|
require 'token.php';
|
|
function isvalid($hor){
|
|
switch($hor){
|
|
case "kos":
|
|
return "Kos";
|
|
case "bika":
|
|
return "Bika";
|
|
case "ikrek":
|
|
return "ikrek";
|
|
case "rák":
|
|
case "rak":
|
|
return "Rák";
|
|
case "oroszlán":
|
|
case "oroszlan":
|
|
case "zlán":
|
|
return "Oroszlán";
|
|
case "szűz":
|
|
case "szuz":
|
|
case "zuz":
|
|
return "szűz";
|
|
case "mérleg":
|
|
case "merleg":
|
|
return "Mérleg";
|
|
case "skorpió":
|
|
case "skorpio":
|
|
return "Skorpió";
|
|
case "nyilas":
|
|
return "Nyilas";
|
|
case "bak":
|
|
return "Bak";
|
|
case "vízöntő":
|
|
case "vizonto":
|
|
return "Vízöntő";
|
|
case "halak":
|
|
return "Halak";
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
function error($message){
|
|
$msg = "";
|
|
$r = rand(0,11);
|
|
switch($r){
|
|
case 0:
|
|
$msg ="Bizonyára megtréfált az univerzum!";
|
|
break;
|
|
case 1:
|
|
$msg ="Ne haragudj,de az univerzum ilyen csúnya szavakra nem reagál!";
|
|
break;
|
|
case 2:
|
|
$msg ="Bocsáss meg az univerzum most nem szeretné hogy segítsek!";
|
|
break;
|
|
case 3:
|
|
$msg ="Bocsáss meg lemerült az univerzum. Most nem tud segíteni.";
|
|
break;
|
|
case 4:
|
|
$msg ="Amint feltöltődik az univerzum segítek!";
|
|
break;
|
|
case 5:
|
|
$msg ="Az univerzum nem akar jósolni neked!Gondolom bűnös lélek vagy!";
|
|
break;
|
|
case 6:
|
|
$msg ="Ilyen csúnya szavakra nem vagyok hajlandó reagálni!";
|
|
break;
|
|
case 7:
|
|
$msg ="Nem kaptam tőled pénzt,így az univerzum nem tud segíteni neked!";
|
|
break;
|
|
case 8:
|
|
$msg ="Az univerzum elutasított téged.7 éven belül balszerencse fog érni.";
|
|
break;
|
|
case 9:
|
|
$msg ="Az univerzum megsértődött magára.";
|
|
break;
|
|
case 10:
|
|
$msg ="Az univerzum nem szereti az ilyen fajta gúnyolódást.";
|
|
break;
|
|
case 11:
|
|
$msg ="Takarodjon innen ".$message->author."!!Ne becsmérelje az univerzumot!!";
|
|
break;
|
|
}
|
|
$message->channel->sendMessage($msg);
|
|
}
|
|
|
|
function forURL($hor){
|
|
return str_replace(array("á","é","í","ó","ö","ő","ú","ü","ű"," "),array("a","e","i","o","o","o","u","u","u",""),strtolower($hor));
|
|
}
|
|
function get_string_between($string, $start, $end){
|
|
$string = ' ' . $string;
|
|
$ini = strpos($string, $start);
|
|
if ($ini == 0) return '';
|
|
$ini += strlen($start);
|
|
$len = strpos($string, $end, $ini) - $ini;
|
|
return substr($string, $ini, $len);
|
|
}
|
|
function genpre(){
|
|
$pre = "";
|
|
$r = rand(0,2);
|
|
switch($r){
|
|
case 0:
|
|
$pre ="Az univerzum azt üzeni, hogy";
|
|
break;
|
|
case 1:
|
|
$pre ="Szétterítem a kártyáimat! Látom hogy";
|
|
break;
|
|
case 2:
|
|
$pre ="Kiterítem a kártyáimat! Látom hogy";
|
|
break;
|
|
}
|
|
return $pre;
|
|
}
|
|
|
|
include __DIR__.'/vendor/autoload.php';
|
|
use Discord\Discord;
|
|
use Discord\Parts\Part;
|
|
use Discord\Parts\User\Game;
|
|
$honap = array('','januar','februar','marcius','aprilis','majus','junius','julius','augusztus','szeptember','oktober','november','december');
|
|
$discord = new \Discord\Discord([
|
|
'token' => $token,
|
|
]);
|
|
|
|
$discord->on('ready', function ($discord) {
|
|
|
|
echo "Bot is ready.", PHP_EOL;
|
|
// Listen for events here
|
|
$game = $discord->factory(Game::class, [
|
|
'name' => 'Overwatch',
|
|
'url' => null,
|
|
'type' => 0
|
|
]);
|
|
|
|
$discord->updatePresence($game);
|
|
$discord->on('message', function ($message) {
|
|
echo "Recieved a message from {$message->author->username}: {$message->content}", PHP_EOL;
|
|
$honap = array('','januar','februar','marcius','aprilis','majus','junius','julius','augusztus','szeptember','oktober','november','december');
|
|
if(strstr($message->content, '!astro') || strstr($message->content, '!napi')){
|
|
$horoszkop= str_replace(array('!astro','!napi'),"",$message->content);
|
|
if($horoszkop == ""){
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$horoszkop = $json[$message->author->username];
|
|
}
|
|
$horoszkop = forURL($horoszkop);
|
|
if(isvalid($horoszkop) !== false){
|
|
$www = file_get_contents("https://www.astronet.hu/horoszkop/".forURL($horoszkop)."-napi-horoszkop/".date('Y')."-".$honap[date('n')]."-".date("d")."/");
|
|
echo "https://www.astronet.hu/horoszkop/".forURL($horoszkop)."-napi-horoszkop/".date('Y')."-".$honap[date('n')]."-".date("d")."/";
|
|
$parsed = get_string_between($www, '<div class="details-content">', '</div>');
|
|
$message->reply(genpre()." ".lcfirst($parsed));
|
|
$auth= $message->author->username;
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$json[$auth]=forURL($horoszkop);
|
|
file_put_contents("data.json",json_encode($json));
|
|
|
|
}else{
|
|
error($message);
|
|
}
|
|
}
|
|
if(strstr($message->content, '!heti')){
|
|
$horoszkop= str_replace('!heti',"",$message->content);
|
|
if($horoszkop == ""){
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$horoszkop = $json[$message->author->username];
|
|
}
|
|
$horoszkop = forURL($horoszkop);
|
|
if(isvalid($horoszkop) !== false){
|
|
$x = 7-date("N");
|
|
$n = date("N")-1;
|
|
$url = "https://www.astronet.hu/horoszkop/".forURL($horoszkop)."-heti-horoszkop/".date('Y',strtotime("-$n days"))."-".$honap[date('n',strtotime("-$n days"))]."-".date('d',strtotime("-$n days"))."-".date('Y',strtotime("+$x days"))."-".$honap[date('n',strtotime("+$x days"))]."-".date('d',strtotime("+$x days"))."/";
|
|
$www = file_get_contents($url);
|
|
echo $url;
|
|
$parsed = get_string_between($www, '<div class="details-content">', '</div>');
|
|
$message->reply(genpre()." ".lcfirst($parsed));
|
|
$auth= $message->author->username;
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$json[$auth]=forURL($horoszkop);
|
|
file_put_contents("data.json",json_encode($json));
|
|
}else{
|
|
error($message);
|
|
}
|
|
}
|
|
if(strstr($message->content, '!havi')){
|
|
$horoszkop= str_replace('!havi',"",$message->content);
|
|
if($horoszkop == ""){
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$horoszkop = $json[$message->author->username];
|
|
}
|
|
$horoszkop = forURL($horoszkop);
|
|
if(isvalid($horoszkop) !== false){
|
|
$url = "https://www.astronet.hu/horoszkop/".forURL($horoszkop)."-havi-horoszkop/".date('Y')."-".$honap[date('n')]."/";
|
|
$www = file_get_contents($url);
|
|
echo $url;
|
|
$parsed = get_string_between($www, '<div class="details-content">', '</div>');
|
|
$message->reply(genpre()." ".lcfirst($parsed));
|
|
$auth= $message->author->username;
|
|
$json = json_decode(file_get_contents("data.json"),true);
|
|
$json[$auth]=forURL($horoszkop);
|
|
file_put_contents("data.json",json_encode($json));
|
|
}else{
|
|
error($message);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$discord->run();
|