This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Check Online Status

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Check Online Status

Post by darton »

Hello!
I want my bot to check if a special nick e.g. Darton is online? If this nick is offline the bot should say "Darton is offline" and if the nick is online the bot should do nothing. It should react on the command "!ison". How is this possible?
Last edited by darton on Mon Mar 27, 2006 2:42 pm, edited 1 time in total.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

based on trigger or /watch? besides I am sure there is something around like that for either one.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

The easier one. :D
M
MMDollar
Voice
Posts: 8
Joined: Sat Mar 04, 2006 8:37 pm
Location: Bulgaria/Bourgas
Contact:

Post by MMDollar »

I think this is what you need

Code: Select all

## File, where the list of the !ison-ed users are stored.
set filename "nlist.users"

# Channel to whom the stuff goes.
set nchan "channel"

# File exits ? if no then created!
if {![file exists $filename]} {
    set fh [open $filename w]
    puts -nonewline $fh ""
    close $fh
}

## Don't change anything below, unless you know what you are doing!
# glob vars
set tell "notell"
set online ""

### raw 303 (ISON)
bind raw - 303 online:raw

### raw 325 (NS Id)
bind raw - 325 whois:idented

proc whois:idented {* 325 arg} {
global nchan
  putserv "PRIVMSG [lindex $arg 1] zabravil|si|da|vlezesh|v|kanal $nchan"
}

## ison is triggered
proc online:raw {* 303 arg} {
  global online nchan tell
  set nlist [getinfo]
  string tolower $nlist
  set arg [string trimleft [lrange $arg 1 end] ":"]
  set arg [charfilter $arg]
  if {$arg == ""} {
	set online1 $online
    if {$tell == "tell"} {
      puthelp "PRIVMSG $nchan :Noone's online."
      set tell "notell"
    }
	unset online
	set online [qonreport 1 $arg $online1]
	set quitted [qonreport 0 $online1 $online]
	set quitted [charfilter $quitted]
	set quitted [removespaces $quitted]
	if {$quitted == ""} {
	  return
	}
    putserv "PRIVMSG $nchan: $quitted offline."
    set online ""
  } else {
  	if {$tell == "tell"} {
	  set arg [removespaces $arg]
	  set onchan [onlineon $arg]
	  set tell "notell"
	  set online $arg
      puthelp "PRIVMSG $nchan :Online: $arg"
      puthelp "PRIVMSG $nchan :Online total [llength $arg] of [llength $nlist]."
      puthelp "PRIVMSG $nchan :On $nchan: [llength $onchan] of [llength $arg] online."
	  return
	}

	if {$online == ""} {
	  set arg [removespaces $arg]
	  set onchan [onlineon $arg]
      set online $arg
      puthelp "PRIVMSG $nchan :Online: $arg"
      puthelp "PRIVMSG $nchan :Online total [llength $arg] of [llength $nlist]."
      puthelp "PRIVMSG $nchan :On $nchan: [llength $onchan] of [llength $arg] online."
      return
	}

	set foo [qonreport 0 $arg $online]

	if {$foo != ""} {
	  set foo [charfilter $foo]
	  set foo [removespaces $foo]
	  set onchan [onlineon $arg]
      append online " $foo"
      puthelp "PRIVMSG $nchan :Online: $foo"
      puthelp "PRIVMSG $nchan :Online total [llength $arg] of [llength $nlist]."
      puthelp "PRIVMSG $nchan :On $nchan: [llength $onchan] of [llength $arg] online."
	}
	set online1 $online
	unset online
	set online [qonreport 1 $arg $online1]
	set quitted [qonreport 0 $online1 $online]
	set quitted [charfilter $quitted]
	set quitted [removespaces $quitted]
	if {$quitted == ""} {
	  return
	}
    putserv "PRIVMSG $nchan :$quitted offline."
  }
}

### !ison
bind pub n !ison ison:pub

proc ison:pub {nick host hand chan arg} {
  global nchan tell
  if {[string tolower $chan] != [string tolower $nchan]} {
	return
  }
  set tell "tell"
  set nlist "[getinfo]"
  putserv "ISON :$nlist"
}

### !addison <nickname(s)>
bind pub n !addison ison:addison

proc ison:addison {nick host hand chan arg} {
  global nchan
  if {[string tolower $chan] != [string tolower $nchan]} {
	return
  }
  if {[lindex $arg 0] == ""} {
	putserv "PRIVMSG $chan :$nick: Usage !addison <nickname(s)>"
	return
  }
  set nlist [getinfo]
  set dontsay [dupZZ $nlist $arg 0]
  if {$dontsay == ""} {
	set count [expr [llength $arg] + [llength $nlist]]
	set arg [charfilter $arg]
	set arg [removespaces $arg]
	putserv "PRIVMSG $chan :$nick: Done. Successfully added $arg. Total ($count)."
	writetof "$nlist $arg"
	set tell "tell"
    putserv "ISON :$nlist"
  } else {
	set dontsay [removespaces $dontsay]
	set dontsay [charfilter $dontsay]
	putserv "PRIVMSG $chan :There is a duplicate :$dontsay"
	set nlist [getinfo]
        set list ""
        foreach bla $arg {
        if {[lsearch $list $bla] == -1} {
          lappend list $bla
            }
        }
        set final [$nlist $list 1]
	if {$final != ""} {
	  set count [expr [llength $final] + [llength $nlist]]
	  set final [removespaces $final]
	  set final [charfilter $final]
	  putserv "PRIVMSG $chan :$nick: Done. Successfully added $final. Total ($count)."
	}
	writetof "$nlist $final"
    putserv "ISON :$nlist $final"
	set tell "tell"
  }
}

## !delison <nickname>
bind pub n !delison del_in_fd
proc del_in_fd {nick uhost hand chan arg} {
  global nchan
  if {[string tolower $chan] != [string tolower $nchan]} {
	return
  }
  if {[llength $arg] != 1} {
    puthelp "NOTICE $nick :Usage: !delison <nickname|phone number>"
    return 0
  }
  set nicknames [getinfo]
  
  set who [lindex $arg 0]
  set who [charfilter $who]
  
  if {[lsearch -exact $nicknames [lindex $arg 0]] == -1} {
	puthelp "NOTICE $nick :Nickname $who not found in the database!"
	return 0
  }
  regsub -all "\\\m$who\\\M" $nicknames "" nicknames
  regsub -all {\s+} $nicknames { } nicknames
  writetof $nicknames
  puthelp "NOTICE $nick :Nickname $who erased from the database!"
}

## !list [nickname]
bind pub n !list list_out_of_fd
proc list_out_of_fd {nick uhost hand chan arg} {
  global nchan
  if {[string tolower $chan] != [string tolower $nchan]} {
	return
  }
  if {[llength $arg] == 0} {
	set nicknames [getinfo]
	set nicknames [charfilter $nicknames]
	set nicknames [removespaces $nicknames]
	if {$nicknames == ""} {
	  puthelp "NOTICE $nick :No one is added in the database!"
	} else {
	  puthelp "NOTICE $nick :Added in the database: $nicknames"
	}
  } elseif {[llength $arg] == 1} {
	set nicknames [getinfo]
	set nicknames [string tolower $nicknames]
	if {[lsearch -exact $nicknames [lindex $arg 0]] == -1} {
	  puthelp "NOTICE $nick :[charfilter [lindex $arg 0]] not found in the database!"
	} else {
	  puthelp "NOTICE $nick :[charfilter [lindex $arg 0]] is in the database!"
	}
  } else {
	puthelp "NOTICE $nick :Usage: !list \[nickname\]"
  }
}

## The proc
proc notify {} {
  set nlist [getinfo]
  putserv "ISON :$nlist"
  if {![string match *notify* [utimers]]} { utimer 30 notify }
}

proc charfilter {x {y ""} } {
  for {set i 0} {$i < [string length $x]} {incr i} {
    switch -- [string index $x $i] {
      "\"" {append y "\\\""}
      "\\" {append y "\\\\"}
      "\[" {append y "\\\["}
      "\]" {append y "\\\]"}
      "\}" {append y "\\\}"}
      "\{" {append y "\\\{"}
      default {append y [string index $x $i]}
    }
  }
  return $y
}

proc getinfo {} {
  global filename
  set file [open $filename r]
  set nlist ""
  while {![eof $file]} {
	set chast [gets $file]
    if {$chast != ""} {
	  append nlist $chast
	}
  }
  close $file
  return $nlist
}

proc removespaces {arg} {
  regsub {^\s+} $arg "" arg
  return $arg
}

proc onlineon {arg} {
  global nchan
  set onchan ""
  foreach tempchar $arg {
    if {![onchan $tempchar $nchan]} {
      putserv "WHOIS $tempchar"
    } else {
      append onchan " $tempchar"
    }
  }
  return $onchan
}

proc qonreport {how arg online} {
  set aq 0
  set foo ""
  foreach el $arg {
    foreach el1 $online {
	  if {$el == $el1} {
	    set aq 1
	  }
    }
    if {$aq == $how} {
	  append foo " $el"
	}
    set aq 0
  }
  return $foo
}

proc writetof {what} {
  global filename
  set fh [open $filename w]
  puts $fh $what
  close $fh
}

proc dupZZ {where what how} {
  set dontsay ""
  foreach el1 $what {
	if {[lsearch -exact $where $el1] != -1} {
	  if {$how == 0} {
  		append dontsay " $el1"
	  }
    } else {
	  if {$how == 1} {
		append dontsay " $el1"
	  }
	}
  }
  return $dontsay
}

if {![string match *notify* [utimers]]} { utimer 30 notify }

putlog "Modificiran ot MMDollar"
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

:shock: I thought this script only has to be 5 lines long. And I think it isn't necessary to save everything in textfiles. Isn't there a easier way?
M
MMDollar
Voice
Posts: 8
Joined: Sat Mar 04, 2006 8:37 pm
Location: Bulgaria/Bourgas
Contact:

Post by MMDollar »

Sorry I don't know any other script
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

onchan <nickname> [channel]
Returns: 1 if someone by that nickname is on the specified channel (or
any channel if none is specified); 0 otherwise
Module: irc
This command should be right. But I don't know really how to use it. Can anybody help me?
This thing doesn't work.

Code: Select all

set check_nick "Darton"

bind pub - !ison isonline
proc isonline {chan nick} {
global check_nick
  if {[onchan $check_nick $chan] == 0} {     
   putquick "privmsg $chan :Darton is offline!"
 }
} 
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

The [onchan] command checks if <nick> is inside <chan> where the bot is inside <chan> as well. What you need is to send ison requests to check if someone is online, try searching the forum for 'ison'.
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

This is a quote of you Sir_Fz:
ison
well thats not a valid command

instead:

from TCL-commands.doc
Quote:
onchan <nickname> [channel]
Returns: 1 if someone by that nickname is on the specified channel (or
any channel if none is specified); 0 otherwise
Module: irc
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I was talking about [ison] tcl command and not server command.
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

Sir_Fz wrote:The [onchan] command checks if <nick> is inside <chan> where the bot is inside <chan> as well.
This is exactly what I want to have.
Sir_Fz wrote:I was talking about [ison] tcl command and not server command.
I am talking about the tcl-command, too.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Glad you found what you wanted :)

PS: [ison] Tcl command does not exist :P
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

But whats worng with this script now?

Code: Select all

set check_nick "Darton"

bind pub - !ison isonline
proc isonline {chan nick} {
global check_nick
  if {[onchan $check_nick $chan] == 0} {     
   putquick "privmsg $chan :Darton is offline!"
 }
}
The error is: "Wrong args, should be {isonline chan nick}."
t
tessa1
Halfop
Posts: 49
Joined: Mon Apr 18, 2005 12:51 pm
Location: Germany

Post by tessa1 »

Use this :)

Code: Select all

bind pub -|- !ison    ison:nick
proc ison:nick {nick host hand chan arg} {
  global ison botnick ison_infonick
  set ison(rchan) "$chan"
  set isoninfonick [lindex [split $arg] 0]
  if {$isoninfonick == ""} {
    putquick "NOTICE $nick :Syntax: !ison <Nick>"
    return 0
   }
   bind raw -|- 303 isonnick:isonline
   set ison_infonick "$isoninfonick"
   putquick "PRIVMSG $ison(rchan) :Please wait..."
   putquick "ISON $ison_infonick"
   return 0
  }

proc isonnick:isonline {from keyword arg} {
  global ison ison_infonick botnick
  if {([string match "*$ison_infonick*" $arg])} {
   putserv "PRIVMSG $ison(rchan) :$ison_infonick is online!"
   unbind raw -|- 303 isonnick:isonline
      return 0
    } else {
      putserv "PRIVMSG $ison(rchan) :$ison_infonick is offline!"
      unbind raw -|- 303 isonnick:isonline
      return 0
    }
  }
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

darton wrote:But whats worng with this script now?

Code: Select all

set check_nick "Darton"

bind pub - !ison isonline
proc isonline {chan nick} {
global check_nick
  if {[onchan $check_nick $chan] == 0} {     
   putquick "privmsg $chan :Darton is offline!"
 }
}
The error is: "Wrong args, should be {isonline chan nick}."
From Tcl-commands.doc:
PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>

Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
Module: irc
so you need

Code: Select all

proc isonline {nick uhost hand chan arg} {
Post Reply