-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
111 lines (101 loc) · 3.5 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
error_reporting(E_ALL);
header('Content-Type: text/html; charset=UTF-8');
include("settings.php");
include("functions.php");
date_default_timezone_set(USER_TIMEZONE);
//RESET WAR
if ((isset($_GET["reset"]) && ($_GET["reset"] == 1))||(isset($_GET["new"]) && ($_GET["new"] == 1))){
unlink("names.json");
unlink("log.txt");
unlink("failed.txt");
array_map('unlink', glob("images/*"));
rmdir("images");
if ($_GET["reset"] == 1){
die("La batalla ha sido reiniciada, si quieres inicializarla haz clic <a href='index.php?new=1'>aquí</a>, si quieres empezarla haz clic <a href='index.php'>aquí</a>");
}
}
//GETTING NAMES
if (file_exists("names.json")){
$names = json_decode(file_get_contents("names.json"),true);
if (count($names)==1){
die("La batalla ha terminado, si quieres reiniciarla elimina el archivo names.json o haz clic <a href='index.php?reset=1'>aquí</a>");
}
}else{ //First execution
include("names.php");
if (isset($_GET["new"]) && ($_GET["new"] == 1)){
$image = getimage();
if ($image != ""){
$string = "Va a dar comienzo la batalla entre empresas de transporte o seguimiento de @MiTrackingBot.\n\nHay algunas sorpresas preparadas pero recordad que es un juego/parodia.\n\nLas compañías enfrentadas son:";
//SEND TO TWITTER
if ((API_KEY != "")&&(API_SECRET_KEY != "")){
sendTwitter($string,$image);
}
//SEND TO TELEGRAM
if ((TELEGRAM_TOKEN != "")&&(CHANNEL_ID != "")){
sendTelegram($string,$image);
}
}
die("La batalla ha sido inicializada, si quieres empezarla haz clic <a href='index.php'>aquí</a>");
}
}
//BATTLE
$killer = $names[mt_rand(0, count($names) - 1)];
$victim = $names[mt_rand(0, count($names) - 1)];
if ($killer == $victim){ //making sure no one kills itself
while($killer == $victim){
$victim = $names[mt_rand(0, count($names) - 1)];
}
}
$killer_key = array_search($killer,$names);
$victim_key = array_search($victim,$names);
$killer_twitter = $killer[key($killer)];
$victim_twitter = $victim[key($victim)];
file_put_contents("log.txt",date("Y-m-d H:i")." - ".count($names)." - ".key($killer)." - ".key($victim)."\n", FILE_APPEND);
//MESSAGE
if ($killer_twitter!=""){
$killer_twitter = " (@".$killer_twitter.")";
}
if ($victim_twitter!=""){
$victim_twitter = " (@".$victim_twitter.")";
}
$string = key($killer).$killer_twitter." ha eliminado a ".key($victim).$victim_twitter."\n\n";
//REMOVE FROM ARRAY
unset($names[$victim_key]);
//SAVE UPDATED JSON
savejson($names);
if (count($names)<2){
$string .= "Todos los enemigos han sido eliminados.\n".key($killer).$killer_twitter." es el ganador\n\n";
}else{
$string .= count($names)." compañías restantes.\n\n";
}
$string .= HASHTAG;
//SAVE IMAGE
$image = getimage();
$success = 0;
if ($image != ""){
//SEND TO TWITTER
if ((API_KEY != "")&&(API_SECRET_KEY != "")){
if (sendTwitter($string,$image)){
$success = 1;
}else{
$success = 0;
}
}
//SEND TO TELEGRAM
if ((TELEGRAM_TOKEN != "")&&(CHANNEL_ID != "")){
if (sendTelegram($string,$image)){
$success = 1;
}else{
$success = 0;
}
}
}
if ($image == "" || $success == 0){ //SOMETHING HAS FAILED
file_put_contents("failed.txt",date("Y-m-d H:i")." ".$string, FILE_APPEND);
//ADD AGAIN TO ARRAY
$names[] = array(key($victim) => $victim[key($victim)]);
//SAVE UPDATED JSON
savejson($names);
}
?>