mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2012
Posts: 2
C
c3j Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
C
Joined: Jan 2012
Posts: 2
I have constructed www.austnetsex.org for #sex on irc.austnet.org, I am using XOOPS 2.4.5 and have done the following for the channel operators bot so it can tweet the rude words.

I have written the following JSON Script for MiRC from importing it from an existing script on the web:

Php Code:

;;;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 \n\r\t]/.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(<nickname>,<message>)
;;;Requires $json
;;;Returns: array(	'CODE'		=>		 (integer)	)
;;;
;;;Error Codes:		CODE	=	 300		(Message to short dropped and ignores, <message> < 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) 
} 


This interacts when the bot 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:

Php Code:

<?php 

	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($schedule, true));
			$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='.urlencode( sprintf($url, urlencode(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($log, true));
			$link = XOOPS_URL.'/modules/twitterbomb/go.php?sid='.$schedule->getVar('sid').'&cid='.$schedule->getVar('cid').'&lid='.$lid.'&catid='.$schedule->getVar('catid').'&uri='.urlencode( sprintf($url, urlencode(str_replace(array('#', '@'), '',$tweet))));
			$link = twitterbomb_shortenurl($link);
			$log->setVar('url', $link);
			$log = $log_handler->get($lid = $log_handler->insert($log, true));
			if ($id = $oauth->sendTweet($schedule->getVar('pre').' '.$tweet, $link, true)) {
				$schedule->setVar('tweeted', time());
				$scheduler_handler->insert($schedule, true);
				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($log, true);

				$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($schedule, true);
				XoopsCache::read('tweetbomb_channel_last', array('last'=>time()), 60*70);
				@$log_handler->delete($log, true);
				return array('CODE' => 100);
			}
			
		}
	} else {
		XoopsCache::read('tweetbomb_channel_last', array('last'=>time()), 60*70);
		return array('CODE' => 100);
	}
	
?>



What I am wondering is how do I strap the tweet function to say tweet the channel #gaysex? or better still passing the tweet like so $tweet($channel, $nick, $message)...

don't worry about modifying the plugin, I just want to pass $channel which is what variable i don't know, I find the FAQ difficult to follow and i have never programmed MiRC, anyway I want to pass $channel as the `pre` in the database.

Joined: Jan 2012
Posts: 2
C
c3j Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
C
Joined: Jan 2012
Posts: 2
I am told the following alias will tweet everything like I am asking, is this so?

Php Code:
on 1:TEXT:*:*:tweet($channel, $nick, $$1-) 

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
mIRC syntax is not like PHP's, so you shouldn't put mIRC code inside of PHP syntax blocks on this forum. Of course, more importantly, the syntax you provided isn't valid mIRC syntax, and $channel doesn't exist.

You probably want /tweet # $nick $1-


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard