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.

Bit of logic help

Old posts that have not been replied to for several years.
Locked
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Bit of logic help

Post by Weirdo »

Hi all

having a bit of a problem getting my mind around a script i have been asked to do.

making a channel i run, chat only, and i want to make it fserve free.

So, using a time bind, that will run every 20 minutes. The script also needs some features. Using a Udef flag, and adding a +list-ban tag to each channel i want to be chat only. The way that i figure is, to do it like this, the bot will have to search for this flag in its channel file.

Question is, how do i do that? I know that once i have it, i can use a loop (foreach i think should do it) which will set off the trigger into the channel, and i think, that i can put a line of code to react to the notices that the bot will recieve, and looking for the various fserve lidentification flags that each script has at the beginning of each trigger, it will kickban when it finds one.

do i put the notice listening bit inside the loop or not? Can never seem to get my mind around logic :P

Any help you can provide would be muchly appreciated

Thanks

Weirdo
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Have you read doc/tcl-commands.doc?
Have you tried searching the forum?

The notc bind should be permanent. That way you don't have to care about lag/time limits, and besides, who would send your bot notices except from those fserves anyway?
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Yes i have read the TCL Commands, i tend to keep it open while i do these sorts of things.

After doing the experimentation with some bits of it last night, i found that the [channels] command gives me the list i want, in a [#channel1 #channel2] format, which should be easy enough to split.

Gave it a bit of though, and the way i figured it out logically last night was like this, roughly

* first loop - for each channel in [channels] run this command
>> check the channel modes for +list-ban
>>> if it has that mode, then run the in channel !list function, and find the little buggers
>>> if not, Ret0
** then, for each notice recieved in that channel run checks on it
>>> if its an fserve notice i recognise
>>>> goto next check
>>> if the person is voiced
>>>> goto next notice check
>>>> else ban the person
** end loop 2, go to next check
>> do the little logging thing
* end loop 1

What i am worried about is the running of 2 loops inside of each other, will the bot lag VERY badly, or will it still be able to function. Would like it to be as fast as possible, so this script takes at most, 15 seconds to run in its entirety, it might even be worth adding the ban to a big queue, and at the end of it all, banning who needs to be banned from the channel . Also doesnt help that i am reaaaaaly bad with the loop code, not sure how to get it to look at the channels variable, and split it, same problem with the notice bit.

i think this is the one i have to use...
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been used to extract the element, then calls the Tcl interpreter to execute body.
problem is, i have no idea really, what it is talking about :P
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

'channels' returns a list so you don't have to bother with splitting it.

Code: Select all

foreach chan [channels] {
  # the block of code contained in here will be executed for each channel in the channel list (or untill you 'break' out of the loop)
  # and each time $chan will be the name of the next channel
}
Weirdo wrote:** then, for each notice recieved in that channel run checks on it
This does not happen in the same piece of code (inside the foreach loop) replies to your !list query arrive later and should be catched by a notc bind that has its own proc doing the matching against known fserve replies.
Last edited by user on Fri Jul 04, 2003 5:36 am, edited 1 time in total.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

Weirdo wrote:[snip]
What i am worried about is the running of 2 loops inside of each other, will the bot lag VERY badly, or will it still be able to function.
[snip]
For each channel that is set +list-ban you do a !list once in a while. This is a small and fast loop.

You wait for the notices coming in and review them on content and ban where needed. This part is not within in a loop. It is on a first come, first review-ban basis.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Basicaly this will be a timer set to how many minutes you want (or something like this anyway) and he will do that !list thing on the channels that have the +list-ban; this is the main proc. Another proc should be one that will *catch* all the notices that he recives and filter them according to your rules and continue to do what you want with them.

Ps: Looping without returning/stoping/breaking makes it go insane :lol:
Once the game is over, the king and the pawn go back in the same box.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

probably 2 procedures then, one to send the signal, using one loop, which checks the channels, and puts out the !list now and again, which is on a time bind to run every, 20/30 mins or so

and then a notc bind to actually ban them

sounds good, sounds a lot simpler than my idea :)

thanks guys, ill post the code later when i written it :D
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Weirdo wrote:sounds good, sounds a lot simpler than my idea :)
Your idea wouldn't be possible using eggdrop/tcl because when a piece of tcl code is running everything else stops* untill the code is done.

That's why caesar warned about infinite loops I think... because if you create one, your eggdrop will disappear from irc and spend the rest of its life doing only that one tcl loop. However creating infinite loops using 'foreach' is impossible.

* Nothing happens simultaneously in eggdrop. Everything is just a big queue of events happening one at a time. (the bot itself is an endless loop (or at least it tries to be ;P))
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

(Bring on the multi CPU utiisation and supreme multitasking i say ;) )
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Let's add some pepper and some salt on this. The ingredients should be:
a) one proc that will do a !list for the channels that have +list-ban (a timer 20/30 minutes will do fine), using foreach will make it do the !list only on the channels that have the +list-ban.
b) one proc that will catch and filter the incoming notices (bind notc will do fine). Also, the ban *feature* can be included in this proc or can be moved in a separate proc that will handle only the bans.

Example for the first proc:

Code: Select all

foreach chan [channels] {
is {[channel get $chan list-ban] && [botonchan $chan]} {
putserv "PRIVMSG $chan :!list"
}
}
If you have any questions/sugestion do ask/tell. :)
Once the game is over, the king and the pawn go back in the same box.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

edit: Hint, dont test scripts in live channels, woooo that wasnt pretty :). They didnt like me for that one. Looks like the voice script wont be happening for my art distribution channel, looks like just my ban thingy addon for my !list ban script, for the chat only channel now. Well, could set up a spare channel with a !list trigger for testing, banning myself is fun :)

Well, the script works nicely, she performs additional checks, and only does it on channels. Just sorting out the notice binds now :)

Code: Select all

#This is the Proc to run the !list trigger every 20 or so minutes
proc time:list-voice {min hour day month year} {
	foreach list(chan) [channels] {
		if {[channel get $list(chan) list-voice] == 0} {return 0}
		putlog "list 1"
		if {[botonchan $list(chan)] && [botisop $list(chan)]} {
			putlog "list 2"
			putserv "Privmsg $list(chan) :!list" }
	}
}

#This proc voices people :)
proc notc:list-voice {nick uhost hand text {dest ""}} {
	global botnick; if {$dest == ""} {set dest $botnick}
	putlog "list 3"
#It asked me to put this in here for compatiability reasons :P
	if {[isvoice $nick] || [isop $nick] || [ishalfop $nick]} {return 0}
	putlog "list 4"
	putserv "mode $::chan +v $nick"
	putnotc $nick "You have an fserve, here is the prezzie :P"
	putlog "Voiced $nick in $::chan"
}
this is the script as it is. Running it in a diff channel, so i can test it, and make it do something nice for the leeching whores, like voice em, cant ban them with a stuffed up script :P

Only problem i have found, and i am majorly concerned with, is the Channel references. for voicing, and for checking , i need to know what channel its being checked in, and what channel it is checking. Problem is, i dont think this is channel specific. anyways of getting past this? Perhaps setting a variable in the foreach loop?
[00:20:05] <Natsuki-Chan> [00:20] Tcl error [notc:list-voice]: can't read "::chan": no such variable
And as i feared, it happened, script works, ish

Is there a pushmode that i can use, to queue up the voices, so as to prevent flooding the server?

This bit concerns how to remove the fserve "notice spam" from the logs
Looks like the log does store all fserve notices, not exacty a bad thing, but i would rather prevent it.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Slight Question, its to do with getting the channel. Re-written most of what i have done above, cause of the lack of a testing place, problem is, when it does place a ban, it makes it global. I cannot seem to get it to operate only on the channel where the fserve is, rather than every channel.

Code: Select all

#This proc voices people :) 
proc notc:list-ban {nick uhost hand text {dest ""}} { 
   global botnick; if {$dest == ""} {set dest $botnick} 
   putlog "list 3" 
#It asked me to put this in here for compatiability reasons :P 
#might be nice to make sure that bannee isnt an operator, and give them a polite notice instead
   newchanban $::chan $nick "Weirdo" "Fserve Ban" sticky
   putlog "list 4" 
   putnotc $nick "You have an fserve, here is the prezzie <insert meniacal laugh here" 
   putlog "Owned a silly little fserved operated by $nick in $::chan" 
} 
Now i know the $::chan variable doesnt exist, its just a space filler, as i have no idea where i can get this variable from, in the above looped procedure. It might be worth adding these channels to another list, where all the channels with +list-ban is enabled on, and then extracting these in the script above. Thats the only idea i can think of, problem is, being on a bind of notices, if i get too many, might just kill the bot :P

Can someone help me please?

Thanks

Weirdo
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Right before the foreach place something like: set chanlist "" and after or before the !list place this: lappend chanlist $chan then call the "chanlist" where you want.
Once the game is over, the king and the pawn go back in the same box.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

of course, lists, another something i must play with one day, thanks caesar :)

and it works, must remember that one :)
Locked