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.

[SOLVED] help with check for activity

Help for those learning Tcl or writing their own scripts.
Post Reply
a
asim
Voice
Posts: 3
Joined: Mon Sep 21, 2009 2:39 pm

[SOLVED] help with check for activity

Post by asim »

Ok, i have a script and I would like to modify it to check for activity in the channel before giving credit.

Here is the code:

Code: Select all

proc out_bonus { min hour day month year} {
	set sql [mysqlconnect -h HOST -u USERNAME -password PASSWD -db DBNAME ]

	foreach user [chanlist #TheStash] {
		if {$user != "velvet" && $user != "stash" && $user != "destiny"} {
			set clock [ clock format [clock seconds] -format {%b. %d, %Y %I:%M:%S %p}] 
			set query [ mysqlquery $sql "UPDATE users SET seedbonus = seedbonus + 0.6 WHERE username=\'$user\'"]
		}
	}
	set user [chanlist #thestash]
	set clock [ exec sh -c { date  +'%Y-%m-%d %R:%S'} ]
	set query [ mysqlquery $sql "INSERT DELAYED INTO sitelog \(added, txt\) VALUES\(\'$clock\', \'Added 0.6 Point to $user for irc\'\)" ]

	mysqlclose $sql
}

bind time - "?0 * * * *" out_bonus
Velvet, Stash, Destiny are the name of bots in the channel. I am just not sure the best way to check for activity before awarding the bonus points.

Thanks in advance for the help.
Last edited by asim on Tue Sep 22, 2009 1:52 pm, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

What exactly do you mean by activity? messages in the channel?
a
asim
Voice
Posts: 3
Joined: Mon Sep 21, 2009 2:39 pm

Post by asim »

correct any message or action in the channel. just some sign of interaction, although if it makes it easier to just do activity based on chat text that is fine.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Limited testing done, but seems OK

Code: Select all

# logs a timestamp for the last channel event in all the bots channels
# an event is normal channel chat, channel notice or onotice, channel action

# calling 'pActivityReturn #channelname' will return 0 (inactive) or 1 (active)
# according to the preconfigured time limit
# example
# if {[pActivityReturn #botchannel]} {
#     code here
# }

# set here a time limit in seconds
# if the last channel event occurred within this time limit, the channel is deemed active
set vActivityTime 3600

bind CTCP - ACTION pActivityCtcp
bind NOTC - * pActivityNotc
bind PUBM - * pActivityPubm

proc pActivityCtcp {nick uhost hand dest keyword text} {
    global vActivityCurrent
    set channel [string tolower $dest]
    set vActivityCurrent($channel) [unixtime]
    return 0
}

proc pActivityNotc {nick uhost hand text dest} {
    global vActivityCurrent
    if {[regexp -- {^#} [string trimleft $dest @]]} {
        set channel [string tolower [string trimleft $dest @]]
        set vActivityCurrent($channel) [unixtime]
    }
    return 0
}

proc pActivityPubm {nick uhost hand chan text} {
    global vActivityCurrent
    set channel [string tolower $chan]
    set vActivityCurrent($channel) [unixtime]
    return 0
}

proc pActivityReturn {chan} {
    global vActivityCurrent vActivityTime
    set channel [string tolower $chan]
    if {[info exists vActivityCurrent($channel)]} {
        set now [unixtime]
        set elapsed [expr {$now - $vActivityCurrent($channel)}]
        if {$elapsed <= $vActivityTime} {
            return 1
        }
    }
    return 0
}

# eof
I must have had nothing to do
a
asim
Voice
Posts: 3
Joined: Mon Sep 21, 2009 2:39 pm

Post by asim »

Thanks, I am actually looking for activity by users, not the channel in general. but I should be able to adapt this.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

asim wrote:Thanks, I am actually looking for activity by users, not the channel in general. but I should be able to adapt this.
getchanidle <nickname> <channel>

Returns: number of minutes that person has been idle; 0 if the specified user isn't on the channel

Module: irc
Post Reply