Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ranking command #8

Merged
merged 4 commits into from
Nov 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,58 @@
];
}

if(strpos(strtolower($messageText), 'ranking') !== false) { //get the ranking of an event

$event = str_replace('rankings', '', strtolower($messageText)); // remove rankings to only keep the event key
$event = str_replace('ranking', '', strtolower($messageText)); // remove ranking to only keep the event key
$event = str_replace(' ', '', $event); // remove spaces

$json_string = file_get_contents("https://www.thebluealliance.com/api/v2/event/{$event}?X-TBA-App-Id=frcbot:messengerchatbot:1");
$parsed_json = json_decode($json_string);

$evname = $parsed_json->{'name'};

$answer = "https://www.thebluealliance.com/event/{$event}#rankings";

if(strpos(strtolower($json_string), 'name') !== false) {
$response = array (
'recipient' =>
array (
'id' => $senderId,
),
'message' =>
array (
'attachment' =>
array (
'type' => 'template',
'payload' =>
array (
'template_type' => 'button',
'text' => "Click to see the rankings of {$evname} on TBA",
'buttons' =>
array (
0 =>
array (
'type' => 'web_url',
'url' => $answer,
'title' => "{$event} on TBA",
),
),
),
),
),
);
}else{
$answer = "Error: Invalid event key!";
$response = [
'recipient' => [ 'id' => $senderId ],
'message' => [ 'text' => $answer ]
];
}
}

// teams in events

//this check if the team exist and write an error if it does not exist
if (strpos(strtolower($isteamvalid), 'does not exist') !== false) {

Expand Down