09 Irc Idle Mod By Putyn

Started by Mindless, July 23, 2012, 10:41:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

putyn

#2
this for people who don't have mysqltcl installed on there server (what mindless posted)

if you have mysqltcl installed you can try this, note that the script will kick users that don't use there site username on irc , also youll still need to install the part from cleanup,index,user details etc 

Code (tcl) Select

package require mysqltcl

#set channel where script should work
set channel "#channel"
set site "site name"

#set the file where greet message is
#set gfile "greet.txt"

#settings for the database 
set db(user) "****"
set db(host) "****"
set db(pass) "****"
set db(name) "****"
#set db(socket) "/var/lib/mysql/mysql.sock"

#dont edit below if you don't know what your doing :)

#bind process
bind join - "$channel *" bind_join
bind part - "$channel *" bind_part
bind sign - "$channel *" bind_sign
bind nick - "$channel *" bind_nick

proc bind_join {nick host handle chan} {
user_check $nick ;
#hello $nick ;
irc_idle $nick "yes" "" ;
}
proc bind_part {nick host handle chan msg} {
irc_idle $nick "no" ""
}
proc bind_nick {nick host handle chan newnick} {
irc_idle $newnick "yes" $nick
user_check $newnick
}
proc bind_sign {nick host handle chan msg} {
irc_idle $nick "no" ""
}

proc irc_idle { user irc_idle old_user } {
global channel db
set db_hand [mysqlconnect -host $db(host) -user $db(user) -password $db(pass) -db $db(name)]

if { $old_user != "" } {
mysqlexec $db_hand "UPDATE users SET onirc = 'no' WHERE username = '$old_user'"
}
set sql "UPDATE users SET onirc = '$irc_idle' WHERE username = '$user'"
putloglev d * "ircstats: executing $sql"

set result [mysqlexec $db_hand $sql]

if {$result == 1 && $irc_idle == "yes"} {
putquick "notice $user : <+> Irc bonus enabled"

} elseif { $result == 1 && $irc_idle == "no" } {
putquick "PRIVMSG $channel : \0032<-> Irc bonus disabled for $user\003"
}
mysqlclose $db_hand
}
proc user_check { user } {
global db channel site

if { $user == "botName" } {
return 0
}
set db_hand [mysqlconnect -host $db(host) -user $db(user) -password $db(pass) -db $db(name)]

set id [mysqlsel $db_hand "SELECT id FROM users WHERE username = '$user'" -list]
if { $id > 0 } {
putserv "mode $channel +v $user"
} else {
putquick "PRIVMSG $user : This is only for $site members! Use your site username!"
putserv "kick $channel $user : Not a $site member ! Use your site username!"
}
mysqlclose $db_hand
}
proc hello { nick } {
global gfile channel

set h [open "$gfile" "r"]
set greet [read $h]

regsub -all "%nick" $greet "$nick" greet
regsub -all "%chan" $greet "$channel" greet

    foreach line [split $greet "|"] {
        putquick "NOTICE $nick : $line"
    }
}
putlog "putyn's idle,greet,usercheck scripts loaded!"

Mindless

#1
Irc idle mod by putyn
Can be used to award upload credit instead of seedbonus, comment queries accordingly on the cleanup code.

Add ircidle.tcl to your eggdrop.conf and rehash

Code (tcl) Select
package require http

#set channel where script should work
set conf(channel) "#09source"
set conf(chan) "#09source"
set conf(site) "09source"
set conf(key)  "changethistoarandomstringofletters"  # must match the string in irc_idle.php
set conf(site_url) "http://yourdomain/irc_idle.php"

#set the file where greet message is
set gfile "text/greet.txt"

#bind process
bind join - "#09source *" bind_join
bind part - "#09source *" bind_part
bind sign - "#09source *" bind_sign
bind nick - "#09source *" bind_nick

#bind join - "$channel *" bind_join
#bind part - "$channel *" bind_part
#bind sign - "$channel *" bind_sign
#bind nick - "$channel *" bind_nick

proc bind_join {nick host handle chan} {
  set check [user_check $nick]
if { $check == 1 } {
irc_idle $nick 1
#hello $nick
}
}
proc bind_part {nick host handle chan msg} {
irc_idle $nick 0
}
proc bind_nick {nick host handle chan newnick} {
  set check [user_check $nick]
if { $check == 1 } {
irc_idle $newnick 1
#hello $nick
}
}
proc bind_sign {nick host handle chan msg} {
irc_idle $nick 0
}

proc irc_idle { user irc_idle } {
global conf

  set  token [::http::geturl $conf(site_url)?key=$conf(key)&do=idle&username=$user&ircidle=$irc_idle]
set result [::http::data $token]

if { $result == 1 && $irc_idle == 1 } {
putquick "notice $user : <+> Irc bonus enabled"
} elseif { $result == 1 && $irc_idle == 0 } {
putquick "PRIVMSG $conf(chan) : \0032<*> Irc bonus disabled for $user\003"
} else {
putlog "There was an error while changing irc status($irc_idle) for user $user"
}
}
proc user_check { user } {
global db conf

  if { $user == "c00kie" } {
    return 0
  }
  set   token [::http::geturl $conf(site_url)?key=$conf(key)&do=check&username=$user]
set is_user [::http::data $token]

if { $is_user == 1 } {
putserv "mode $conf(chan) +v $user"
} else {
putquick "PRIVMSG $user : This is only for $conf(site) members! Use your site username!"
putserv "kick $conf(chan) $user : Not a $conf(site) member ! Use your site username!"
}
return $is_user
}
proc hello { nick } {
global gfile conf

set h [open "$gfile" "r"]
set greet [read $h]

regsub -all "%nick" $greet "$nick" greet
regsub -all "%chan" $greet "$conf(chan)" greet

    foreach line [split $greet "|"] {
        putquick "NOTICE $nick : $line"
    }
}
putlog "putyn's idle,greet,usercheck scripts loaded!"


Save and upload irc_idle.php to root :

irc_idle.php

Code (php) Select
<?php
//irc idle thingy using php
$key 'changethistoarandomstringofletters';
$vars = array('ircidle'=>'','username'=>'','key'=>'','do'=>'');
foreach(
$vars as $k=>$v)
$vars[$k] = isset($_GET[$k]) ? $_GET[$k] : '';
if(
$key !== $vars['key'] || empty($vars['username']))
die('hmm something looks odd');

require_once(
'include/bittorrent.php');
dbconn();

switch(
$vars['do']) {
case 'check':
$q mysql_query('SELECT id FROM users WHERE username = '.sqlesc($vars['username']));
print(mysql_num_rows($q));
break;
case 'idle':
mysql_query("UPDATE users SET onirc = ".sqlesc(!$vars['ircidle'] ? 'no':'yes')." where username = ".sqlesc($username));
print(mysql_affected_rows());
break;
default:
die('hmm something looks odd again');
}
die;
?>


SQL
Code (sql) Select
ALTER TABLE `users` ADD `onirc` enum('yes','no') NOT NULL default 'no';
ALTER TABLE users ADD `irctotal` bigint(20) unsigned NOT NULL default '0';



code for userdetails.php
where you want it to show add:
Code (php) Select
if  ($user['onirc'] == 'yes'){
    $ircbonus   = (!empty($user['irctotal'])?number_format($user["irctotal"] / $TBDEV['autoclean_interval'], 1):'0.0');
    $HTMLOUT .="<tr><td class='rowhead' valign='top' align='right'>Irc Bonus</td><td align='left'>{$ircbonus}</td></tr>";
    $irctotal = (!empty($user['irctotal'])?calctime($user['irctotal']):$user['username'].' has never been on IRC!');
    $HTMLOUT .="<tr><td class='rowhead' valign='top' align='right'>Irc Idle Time</td><td align='left'>{$irctotal}</td></tr>";
    }



code for cleanup.php
can add before the final closing }
Code (php) Select
//==Irc idle mod 
    $res = mysql_query("SELECT id FROM users WHERE onirc = 'yes'") or sqlerr(__FILE__, __LINE__);   
      if (mysql_num_rows($res) > 0)
      {
            while ($arr = mysql_fetch_assoc($res))
            {
           $users_buffer[] = '('.$arr['id'].',0.250,'.$TBDEV['autoclean_interval'].')'; // .250 karma
            //$users_buffer[] = '('.$arr['id'].',15728640,'.$TBDEV['autoclean_interval'].')'; // 15 mb                 
            }
            if (sizeof($users_buffer)>0){
            mysql_query("INSERT INTO users (id,seedbonus,irctotal) VALUES ".implode(', ',$users_buffer)." ON DUPLICATE key UPDATE seedbonus=seedbonus+values(seedbonus),irctotal=irctotal+values(irctotal)") or sqlerr(__FILE__,__LINE__);
           //mysql_query("INSERT INTO users (id,uploaded,irctotal) VALUES ".implode(', ',$users_buffer)." ON DUPLICATE key UPDATE uploaded=uploaded+values(uploaded),irctotal=irctotal+values(irctotal)") or sqlerr(__FILE__,__LINE__);
            $count = mysql_affected_rows();
            write_log("Cleanup ".$count/2 ." users idling on IRC");
            }
            unset ($users_buffer);
      }
   //== End



to show IRC Users Online,
in index,php, where you want it to show add:

Code (php) Select
//==09 IRC users on index
$activeircusers3 ="";
$file = "./cache/activeirc.txt";
$expire = 30; // 30 seconds
if (file_exists($file) && filemtime($file) > (time() - $expire)) {
$activeircusers3 = unserialize(file_get_contents($file));
} else {
$activeircusers1 = mysql_query("SELECT id, username, class, donor, title, warned, enabled".
              "FROM users WHERE onirc = 'yes' ".
              "ORDER BY username ASC") or sqlerr(__FILE__, __LINE__);
    while ($activeircusers2 = mysql_fetch_assoc($activeircusers1)) {
        $activeircusers3[] = $activeircusers2;
    }
    $OUTPUT = serialize($activeircusers3);
    $fp = fopen($file, "w");
    fputs($fp, $OUTPUT);
    fclose($fp);
} // end else
$activeircusers = "";
if (is_array($activeircusers3))
foreach ($activeircusers3 as $arr) {
    if ($activeircusers) $activeircusers .= ",\n";
    $activeircusers .= "<span style=\"white-space: nowrap;\">";
    $arr["username"] = "<font color='#" . get_user_class_color($arr['class']) . "'> " . htmlspecialchars($arr['username']) . "</font>";
    $donator = $arr["donor"] === "yes";
    $warned = $arr["warned"] === "yes";

    if ($CURUSER)
        $activeircusers .= "<a href='{$TBDEV['baseurl']}/userdetails.php?id={$arr["id"]}'><b>{$arr["username"]}</b></a>";
    else
        $activeircusers .= "<b>{$arr["username"]}</b>";
    if ($donator)
         $activeircusers .= "<img src='{$TBDEV['pic_base_url']}star.gif' alt='Donated' />";
    if ($warned)
        $activeircusers .= "<img src='{$TBDEV['pic_base_url']}warned.gif' alt='Warned' />";
    $activeircusers .= "</span>";
}

if (!$activeircusers)
    $activeircusers = "{$lang['index_noactive_irc']}";
   
    $HTMLOUT .= "<div style='text-align:left;width:80%;border:1px solid blue;padding:5px;'>
    <div style='background:lightgrey;height:25px;'><span style='font-weight:bold;font-size:12pt;'>{$lang['index_active_irc']}</span></div><br />";
     $HTMLOUT .="<table border='1' cellpadding='10' cellspacing='0' width='100%'>
      <tr class='table'>
      <td class='text'>{$activeircusers}</td>";
     $HTMLOUT .="</tr></table></div>";


lang_index.php
     
     
Code (php) Select
'index_active_irc' => "Active Irc users",
     'index_noactive_irc' => "Sorry - No users active in irc presently",


if you don't have this already you can add this function from laffin:
Code (php) Select
function calctime($val)
{
$days=intval($val / 86400);
$val-=$days*86400;
$hours=intval($val / 3600);
$val-=$hours*3600;
$mins=intval($val / 60);
$secs=$val-($mins*60);
return "&nbsp;$days days, $hours hrs, $mins minutes";
}