Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created November 4, 2009 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mheadd/226146 to your computer and use it in GitHub Desktop.
Save mheadd/226146 to your computer and use it in GitHub Desktop.
A class for creating IM/SMS/Twitter bots
<?php
/*
* Copyright 2009 Mark J. Headd
*
* This file is part of the PHP IM Bot Class
*
* PHP IM Bot Class is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP IM Bot Class is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For usage instructions and examples, go to http://www.voiceingov.org/blog/?p=860
*/
class imified {
// Private class members
private $userkey;
private $network;
private $user;
private $channel;
private $msg;
private $step;
private $values = Array();
/*
* Constructor method takes the $_POST array and
* populates the class properties
*
*/
public function __construct(Array $postValues) {
$this->userkey = $postValues['userkey'];
$this->network = $postValues['network'];
$this->msg = $postValues['msg'];
$this->step = (int) $postValues['step'];
foreach($postValues as $key => $value) {
if(preg_match("/^value/", $key)) {
array_push($this->values, $value);
}
}
}
// Returns the IMified user key
public function getUserkey() {
return $this->userkey;
}
// Returns the IM network the request came from (upper cased)
public function getNetwork() {
return strtoupper($this->network);
}
// Returns the actual screen name of the user calling the bot
public function getUser() {
return $this->user;
}
// Returns the Twitter method used to contact the bot (public/private)
public function getChannel() {
return $this->channel;
}
// Returns the message sent by the IM user with the last request
public function getMsg() {
return $this->msg;
}
// Returns the current step in the conversation with the user
public function getStep() {
return $this->step;
}
// Returns the entire values array, which holds all values submitted by user
public function getAllValues() {
return $this->values;
}
// Returns a specific value in the values array, specified by $key
public function getValue($key) {
return $this->values[$key];
}
// Returns the last value in the values array
public function getLastValue() {
return end($this->values);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment