New implementation for /kys

Changed code to use the sender's username or name (if he/she has no username) and replace ##name## in kys.txt with that
This commit is contained in:
2018-04-02 18:03:40 +05:30
parent abb1e850c2
commit 2a9573a9e2
2 changed files with 19 additions and 12 deletions

View File

@@ -214,8 +214,15 @@ function kys() {
$kys = file('kys.txt');
$random_kys = $kys[rand(0,count($kys)-1)];
if (isset($decoded->{'message'}->{'reply_to_message'})) {
$reply_id = $decoded->{'message'}->{'reply_to_message'}->{'message_id'};
send_text($random_kys, $reply_id);
if (isset($decoded->{'message'}->{'reply_to_message'}->{'from'}->{'username'})){
$username = '@' . $decoded->{'message'}->{'reply_to_message'}->{'from'}->{'username'};
$random_kys = preg_replace('/##name##/g', $username, $random_kys);
}
else {
$first_name = $decoded->{'message'}->{'reply_to_message'}->{'from'}->{'first_name'};
$random_kys = preg_replace('/##name##/g', $first_name, $random_kys);
}
send_text($random_kys);
}
else {
send_text("Do you want to kill yourself?", true);