-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (168 loc) · 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
require 'vendor/autoload.php';
use meysampg\intldate\IntlDateTrait;
class Cal
{
use IntlDateTrait;
private function getMonth($num)
{
switch ($num) {
case '1':
return 'Thoout';
break;
case '2':
return 'Paope';
break;
case '3':
return 'Hathor';
break;
case '4':
return 'Koiahk';
break;
case '5':
return 'Tobe';
break;
case '6':
return 'Meshir';
break;
case '7':
return 'Paremhotep';
break;
case '8':
return 'Parmoute';
break;
case '9':
return 'Pashons';
break;
case '10':
return 'Paone';
break;
case '11':
return 'Epep';
break;
case '12':
return 'Mesore';
break;
case '13':
return 'Nesi';
break;
default:
return 'error';
break;
}
}
public function getDate()
{
$rawdate = date('Y-m-d');
$date = explode('-', $rawdate);
$result = $this->fromGregorian([$date[0], $date[1], $date[2]])->toCoptic()->asDateTime();
$dateres = substr($result, 0, -10);
$datecomp = explode('/', $dateres);
$m = $this->getMonth($datecomp[1]);
$d = $datecomp[2];
$y = $datecomp[0];
return "$m $d, $y";
}
public function getCopticMonth()
{
$rawdate = date('Y-m-d');
$date = explode('-', $rawdate);
$result = $this->fromGregorian([$date[0], $date[1], $date[2]])->toCoptic()->asDateTime();
$dateres = substr($result, 0, -10);
$datecomp = explode('/', $dateres);
$m = $this->getMonth($datecomp[1]);
return "$m";
}
public function getCopticDay()
{
$rawdate = date('Y-m-d');
$date = explode('-', $rawdate);
$result = $this->fromGregorian([$date[0], $date[1], $date[2]])->toCoptic()->asDateTime();
$dateres = substr($result, 0, -10);
$datecomp = explode('/', $dateres);
$d = $datecomp[2]-1;
return "$d";
}
}
//$t = new Telegram('757146827:AAG2Q71HrkB9eG9c2-5V960bvJLAmN479g0');
$t = new Telegram('--------------------------add your bot token here--------------------------------');
$chat_id = $t->ChatID();
$result = $t->getData();
$text = $result['message']['text'];
$calendar = new Cal;
$content = array('chat_id' => $chat_id);
$year = date("Y");
$month = date("n");
$ex_month = date("F");
$day = date("j");
$ex_day = date("d");
$data = file_get_contents("year/" . $ex_month . "/saints.json");
$json = json_decode($data);
$n = $day - 1;
$i = 0;
$saint = '';
do {
if (
isset($json->days[$n]->celebrations[$i]) &&
$json->days[$n]->celebrations[$i] != ""
) {
$saint .= "- " . $json->days[$n]->celebrations[$i]->title . "\n";
$i++;
} else {
break;
}
} while (1);
function doAbout($ex_month,$day,$copticdate)
{
$data = file_get_contents("coptic_year/" . $ex_month . ".json");
$json = json_decode($data);
$n = $day ;
$i = 0;
$saint = '';
$saint .="Today is : ".$copticdate."\n\n";
do {
if (
isset($json->days[$n]->celebrations[$i]) &&
$json->days[$n]->celebrations[$i] != ""
) {
$saint .= "(".($i+1).") -" . $json->days[$n]->celebrations[$i]->title . "\n";
$i++;
} else {
break;
}
} while (1);
return ($saint);
}
if ($text) {
switch ($text) {
case '/start':
$content['text'] = "Welcome to CopticBot. You can use /date to get the Coptic date or /saint to get the saint of the day. ";
$t->sendMessage($content);
break;
case '/date':
$date = $calendar->getDate();
$content['text'] = "Today is $date";
$t->sendMessage($content);
break;
case '/saint':
$content['text'] = "$saint";
$t->sendMessage($content);
break;
case '/about':
$copticdate = $calendar->getDate();
$date = $calendar->getCopticMonth();
$day = $calendar->getCopticDay();
$content['text'] = doAbout($date,$day,$copticdate);
$t->sendMessage($content);
break;
case '/month':
$date = $calendar->getCopticMonth();
$content['text'] = "Current Coptic Month is $date";
$t->sendMessage($content);
break;
default:
$content['text'] = "Wrong command, type /date to know the coptic date";
$t->sendMessage($content);
break;
}
}