egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Check Online Status

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun Mar 26, 2006 5:21 pm    Post subject: Check Online Status Reply with quote

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
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Mon Mar 27, 2006 9:05 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message MSN Messenger
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Mon Mar 27, 2006 10:18 am    Post subject: Reply with quote

The easier one. Very Happy
Back to top
View user's profile Send private message
MMDollar
Voice


Joined: 04 Mar 2006
Posts: 8
Location: Bulgaria/Bourgas

PostPosted: Mon Mar 27, 2006 12:16 pm    Post subject: Reply with quote

I think this is what you need
Code:
## 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"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Mon Mar 27, 2006 2:41 pm    Post subject: Reply with quote

Shocked 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?
Back to top
View user's profile Send private message
MMDollar
Voice


Joined: 04 Mar 2006
Posts: 8
Location: Bulgaria/Bourgas

PostPosted: Mon Mar 27, 2006 2:45 pm    Post subject: Reply with quote

Sorry I don't know any other script
Back to top
View user's profile Send private message Send e-mail Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Mon Mar 27, 2006 3:05 pm    Post subject: Reply with quote

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

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:
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!"
 }
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Mar 27, 2006 3:25 pm    Post subject: Reply with quote

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'.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Mon Mar 27, 2006 3:31 pm    Post subject: Reply with quote

This is a quote of you Sir_Fz:
Quote:
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

Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Mar 27, 2006 7:59 pm    Post subject: Reply with quote

I was talking about [ison] tcl command and not server command.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Tue Mar 28, 2006 8:47 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Mar 28, 2006 12:38 pm    Post subject: Reply with quote

Glad you found what you wanted Smile

PS: [ison] Tcl command does not exist Razz
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Tue Mar 28, 2006 2:06 pm    Post subject: Reply with quote

But whats worng with this script now?
Code:
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}."
Back to top
View user's profile Send private message
tessa1
Halfop


Joined: 18 Apr 2005
Posts: 49
Location: Germany

PostPosted: Tue Mar 28, 2006 5:30 pm    Post subject: Reply with quote

Use this Smile

Code:

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
    }
  }
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Mar 28, 2006 7:31 pm    Post subject: Reply with quote

darton wrote:
But whats worng with this script now?
Code:
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:
Quote:
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:
proc isonline {nick uhost hand chan arg} {

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber