1
wishcraft
Tweeting #IRC with #MIRC #XREST and #Twitterbomb using #JSON #API

First you have to add the alias to the remote side of mIRC scripts with the following function put into the remote part of the scripts with mIRC Scripts.

::JSON Alias for mIRC and Tweet Alias for Tweeting::
;;;Basic JSON PARSER for MIRC;;;
alias json {
  if (
$isid) {
    ;
name of the com interface declared so I don't have to type it over and over again :D
    var %c = jsonidentifier,%x = 2,%str,%p,%v

    ;if the interface hasnt been open and initialized, do it.
    if (!$com(%c)) {
      .comopen %c MSScriptControl.ScriptControl
      ;add two javascript functions for getting json from urls and files
      noop $com(%c,language,4,bstr,jscript) $com(%c,addcode,1,bstr,function httpjson(url) $({,0) y=new ActiveXObject("Microsoft.XMLHTTP");y.open("GET",encodeURI(url),false);y.send();return y.responseText; $(},0))
      noop $com(%c,addcode,1,bstr,function filejson (file) $({,0) x = new ActiveXObject("Scripting.FileSystemObject"); txt1 = x.OpenTextFile(file,1); txt2 = txt1.ReadAll(); txt1.Close(); return txt2; $(},0))
      ;add function to securely evaluate json
      noop $com(%c,addcode,1,bstr,function str2json (json) $({,0) return !(/[^,:{}[]0-9.-+Eaeflnr-u nrt]/.test(json.replace(/"(\.|[^"\])*"/g, ''))) && eval('
(' + json + ')'); $(},0))
      ;add a cache for urls
      noop $com(%c,addcode,1,bstr,urlcache = {})
    }
    if (!$timer(jsonclearcache)) { .timerjsonclearcache -o 0 300 jsonclearcache }

    ;get the list of parameters
    while (%x <= $0) {
      %p = $($+($,%x),2)
      if (%p == $null) { noop }
      elseif (%p isnum || $qt($noqt(%p)) == %p) { %str = $+(%str,[,%p,]) }
      else { %str = $+(%str,[",%p,"]) }
      inc %x
    }
    if ($prop == count) { %str = %str $+ .length }

    ;check to see if source is file
    if ($isfile($1)) {
      if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),filejson,$chr(40),$qt($replace($1,,\,;,u003b)),$chr(41),$chr(41),%str))) { return $com(%c).result }
    }
    ;check to see if source is url
    elseif (http://* iswm $1) {
      ;if url is in cache, used cached data
      if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,$replace($qt($1),;,u003b),],$chr(41),%str))) { return $com(%c).result }
      ;otherwise, get data
      elseif ($com(%c,executestatement,1,bstr,$+(urlcache[,$replace($qt($1),;,u003b),]) = $+(httpjson,$chr(40),$qt($1),$chr(41)))) {
        if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,$replace($qt($1),;,u003b),],$chr(41),%str))) { return $com(%c).result }
      }
    }
    ;get data from inputted json
    elseif ($com(%c,eval,1,bstr,$+(x=,$replace($1,;,u003b),;,x,%str,;))) { return $com(%c).result }
  }
}
alias jsonclearcache { if ($com(jsonidentifier)) { noop $com(jsonidentifier,executestatement,1,bstr,urlcache = {}) } }
;-------------------;


;;;Basic Tweet from MIRC;;;
;;;Syntax: $tweet(,)
;;;Requires $json
;;;Returns: array(    '
CODE'        =>         (integer)    )
;;;
;;;Error Codes:        CODE    =     300        (Message to short dropped and ignores,  < 10 characters)
;;;                CODE    =     200        (Message sucessfully tweeted)
;;;                CODE    =     100        (Message unsucessfully tweeted due to limits but stored for when channel goes quiet!)
alias tweet {

  ;Webmaster Username @ austnetsex.org
  var %website_username = cej

  ;MD5 to be secure, use hashcalc or open text
  var %website_password = cb8fg5432134432b726dace42cb1d37

  ;Url to REST API
  var %url = http://austnetsex.org/modules/xrest/tweet/?nick= $+ $1 $+ &message= $+ $2 $+ &username= $+ %website_username $+ &password= $+ %website_password

  return $json(%url) 
}


You then have to create the plugin for X-Rest 1.52 on XOOPS 2.5.x to talk to twitterbomb 1.27 classes systems.

This interacts when the alias function detects a rude comment tweets it via the X-REST 1.52 API Plugin, or schedules it be tweeted later if you have had the channel go quiet and you have met your hourly tweet limit through TwitterBomb 1.27 Class Structures with this X-REST 1.52 Plugin: This in this example is for the channel #php.

::X-Rest Plugin for Tweeting::

    
function tweet_xsd(){
        
$xsd = array();
        
$i=0;
        
$xsd['request'][$i++] = array("name" => "username""type" => "string");
        
$xsd['request'][$i++] = array("name" => "password""type" => "string");    
        
$xsd['request'][$i++] = array("name" => "nick""type" => "string");
        
$xsd['request'][$i++] = array("name" => "message""type" => "string");
                
        
$i=0;
        
$xsd['response'][$i++] = array("name" => "ERRNUM""type" => "integer");
        
$xsd['response'][$i++] = array("name" => "RESULT""type" => "string");
        
$xsd['response'][$i++] = array("name" => "CODE""type" => "string");
                
        return 
$xsd;
    }
    
    function 
tweet_wsdl(){
    
    }
    
    function 
tweet_wsdl_service(){
    
    }
    
    
    function 
tweet($username$password$nick$message)
    {    
        if (
strlen($message)<10||(!strpos($message'a')&&!strpos($message'e')&&!strpos($message'i')&&!strpos($message'o')&&!strpos($message'u'))) {
            return array(
'CODE' => 300);
        }

        global 
$xoopsModuleConfig$xoopsConfig;

        if (
$xoopsModuleConfig['site_user_auth']==1){
            if (
$ret check_for_lock(basename(__FILE__),$username,$password)) { return $ret; }
            if (!
checkright(basename(__FILE__),$username,$password)) {
                
mark_for_lock(basename(__FILE__),$username,$password);
                return array(
'ErrNum'=> 9"ErrDesc" => 'No Permission for plug-in');
            }
        }

        include(
$GLOBALS['xoops']->path('modules/twitterbomb/include/functions.php'));
        
xoops_load('cache');
        
set_time_limit(480);

        
$GLOBALS['myts'] = MyTextSanitizer::getInstance();

        
$module_handler xoops_gethandler('module');
        
$config_handler xoops_gethandler('config');
        
$GLOBALS['twitterbombModule'] = $module_handler->getByDirname('twitterbomb');
        
$GLOBALS['twitterbombModuleConfig'] = $config_handler->getConfigList($GLOBALS['twitterbombModule']->getVar('mid'));

        
$tweet '#'.str_replace(array('@''+''%'), ''$nick).' - '.twitterbomb_TweetString(htmlspecialchars_decode(urldecode($message)), $GLOBALS['twitterbombModuleConfig']['scheduler_aggregate'], $GLOBALS['twitterbombModuleConfig']['scheduler_wordlength']);
        
$log_handler=xoops_getmodulehandler('log''twitterbomb');
        
$scheduler_handler=xoops_getmodulehandler('scheduler''twitterbomb');
        
$oauth_handler=xoops_getmodulehandler('oauth''twitterbomb');
        
$urls_handler=xoops_getmodulehandler('urls''twitterbomb');
        
        
$oauth $oauth_handler->getRootOauth(true);

        
$ret XoopsCache::read('tweetbomb_scheduler_'.md5('2'.'2'));
        
        if (
$scheduler_handler->getCount(new Criteria('text'$tweet'LIKE'))==0) {
            
$schedule $scheduler_handler->create();
            
$schedule->setVar('cid''2');
            
$schedule->setVar('catid''2');
            
$schedule->setVar('mode''direct');
            
$schedule->setVar('pre''#sex');
            
$schedule->setVar('text'$tweet);
            
$schedule->setVar('uid'user_uid($username$password));
            
$schedule->setVar('when'time());
            
$schedule->setVar('tweeted'0);
            
$schedule $scheduler_handler->get($scheduler_handler->insert($scheduletrue));
            
$url $urls_handler->getUrl($schedule->getVar('cid'), $schedule->getVar('catid'));
            
$link XOOPS_URL.'/modules/twitterbomb/go.php?sid='.$schedule->getVar('sid').'&cid='.$schedule->getVar('cid').'&catid='.$schedule->getVar('catid').'&uri='.urlencodesprintf($urlurlencode(str_replace(array('#''@'), '',$tweet))));
            
$log $log_handler->create();
            
$log->setVar('provider''scheduler');
            
$log->setVar('cid'$schedule->getVar('cid'));
            
$log->setVar('catid'$schedule->getVar('catid'));
            
$log->setVar('sid'$schedule->getVar('sid'));
            
$log->setVar('url'$link);
            
$log->setVar('tweet'substr($tweet,0,139));
            
$log->setVar('tags'twitterbomb_ExtractTags($tweet));
            
$log $log_handler->get($lid $log_handler->insert($logtrue));
            
$link XOOPS_URL.'/modules/twitterbomb/go.php?sid='.$schedule->getVar('sid').'&cid='.$schedule->getVar('cid').'&lid='.$lid.'&catid='.$schedule->getVar('catid').'&uri='.urlencodesprintf($urlurlencode(str_replace(array('#''@'), '',$tweet))));
            
$link twitterbomb_shortenurl($link);
            
$log->setVar('url'$link);
            
$log $log_handler->get($lid $log_handler->insert($logtrue));
            if (
$id $oauth->sendTweet($schedule->getVar('pre').' '.$tweet$linktrue)) {
                
$schedule->setVar('tweeted'time());
                
$scheduler_handler->insert($scheduletrue);
                if (
$GLOBALS['twitterbombModuleConfig']['tags']) {
                    
$tag_handler xoops_getmodulehandler('tag''tag');
                    
$tag_handler->updateByItem(twitterbomb_ExtractTags($tweet), $lid$GLOBALS['twitterbombModule']->getVar("dirname"), $schedule->getVar('catid'));
                }
                
$log->setVar('id'$id);
                
$log->setVar('alias'$nick);
                
$log_handler->insert($logtrue);

                
$ret[]['title'] = $tweet;      
                
$ret[sizeof($ret)]['link'] = $link;
                
$ret[sizeof($ret)]['description'] = htmlspecialchars_decode($tweet);
                
$ret[sizeof($ret)]['lid'] = $lid;
                
$ret[sizeof($ret)]['sid'] = $schedule->getVar('sid');
                if (
count($ret)>$GLOBALS['twitterbombModuleConfig']['scheduler_items']) {
                    foreach(
$ret as $key => $value) {
                        if (
count($ret)>$GLOBALS['twitterbombModuleConfig']['scheduler_items'])
                            unset(
$ret[$key]);
                    }
                }
                
XoopsCache::write('tweetbomb_scheduler_'.md5('2'.'2'), $ret, ($GLOBALS['twitterbombModuleConfig']['interval_of_cron']+$GLOBALS['twitterbombModuleConfig']['scheduler_cache'])*100);
                
XoopsCache::read('tweetbomb_channel_last', array('last'=>time()), 60*70);
                return array(
'CODE' => 200);
            } else {
                
$schedule->setVar('tweeted'0);
                
$scheduler_handler->insert($scheduletrue);
                
XoopsCache::read('tweetbomb_channel_last', array('last'=>time()), 60*70);
                @
$log_handler->delete($logtrue);
                return array(
'CODE' => 100);
            }
            
        }
    } else {
        
XoopsCache::read('tweetbomb_channel_last', array('last'=>time()), 60*70);
        return array(
'CODE' => 100);
    }
    
?>


then you need to activate the scanning for it with the following code in remote of mirc as well

::channel scanning::
on 1:TEXT:*:#php:tweet($nick, $$1-)
*/
Resized Image
http://www.ohloh.net/accounts/226400

Follow, Like & Read:-

twitter.com/RegaltyFamily
github.com/Chronolabs-Cooperative
facebook.com/DrAntonyRoberts

Login

Who's Online

415 user(s) are online (348 user(s) are browsing Support Forums)


Members: 0


Guests: 415


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits