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:
Ceda EI 2018-04-02 18:03:40 +05:30
parent abb1e850c2
commit 2a9573a9e2
2 changed files with 19 additions and 12 deletions

20
kys.txt
View File

@ -1,10 +1,10 @@
You should try tasting cyanide ##name## You should try tasting cyanide
Your enzymes are meant to digest rat poison! ##name## Your enzymes are meant to digest rat poison!
You should try sleeping forever ##name## You should try sleeping forever
Pick up a gun and shoot yourself ##name## Pick up a gun and shoot yourself
You could make a world record by jumping from a plane without parachute ##name## You could make a world record by jumping from a plane without parachute
Stop talking BS and jump in front of a running bullet train ##name## Stop talking BS and jump in front of a running bullet train
Try bathing with Hydrochloric Acid instead of water ##name## Try bathing with Hydrochloric Acid instead of water
Try this: if you hold your breath underwater for an hour, you can then hold it forever ##name## Try this: if you hold your breath underwater for an hour, you can then hold it forever
Go Green! Stop inhaling Oxygen. ##name## Go Green! Stop inhaling Oxygen.
God was searching for you. You should leave to meet him ##name## God was searching for you. You should leave to meet him

View File

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