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.

interviewer-addon

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

interviewer-addon

Post by tomekk »

interviewer-addon

Simple and easy to configure interview-addon script.
Script can work like standalone script or it can be include in your own script (I think the second option is better/easier. Example below.)
Script supports multiuser mode. You can add new questions without rewriting the script.

full code:

Code: Select all

# Author: tomekk                                                                                    
# e-mail:  tomekk/@/oswiecim/./eu/./org                                                             
# home page: http://tomekk.oswiecim.eu.org/                                                         
#                                                                                                   
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

# if you want to use commands from this script on your chan, type in eggdrop console (via telnet or DCC chat)
# .chanset #channel_name +intadd
# and later .save

# <config>

# regexp for !setup, !update, !remove, !flush commands (default, only small and BIG letters are allowed)
set int_bind_regexp {^[a-zA-Z]+$}

# type of key generator 
# 0 - use /dev/urandom (good for unix systems)
# 1 - use some rand() (use it for windows systems, of course it will work under unix too)
set int_random_generator 0

# all these four lists must have the same number of elements
# questions lists, one by one
set int_questions_list {
	"what is your age?"
	"what is your sex?"
	"where are you from?"
	"what is your fav FPS game?"
	"what is your fav map?"
	"what is your fav game music track?"
}

# uniq key of each question
# some short uniq word, without spaces will be better
set int_questions_key {
	"age"
	"sex"
	"from"
	"fps"
	"map"
	"track"
}

# questions regexps, one by one
# if you don't know how to build regexp, use {.*}  and pray (.* any chars ;p)
set int_questions_regexp {
	{^[0-9]{1,2}$}
	{^(male|female|strogg|alien)$}
	{.*}
	{^(quake(1|2|3|4)|doom(1|2|3)|half life(1|2))$}
	{.*}
	{.*}
}

# questions help messages, one by one
set int_question_help {
	"only numbers are allowed (0 - 99)"
	"male, female, strogg or alien"
	""
	"quake1,2,3 or doom1,2,3 or half life1,2"
	""
	""
}

# which procedures bot should bind (default all)
# s - setup proc
# u - update proc
# d - remove proc
# r - release proc
# e - sessions proc
# f - flush proc
# p - private messages proc
# a - part proc
# i - sign proc
# l - split proc
# k - kick proc
# n - nick proc
set int_proc_bind "sudrefpailkn"

# autostart of 'questions', without any extra word
# 0 - disable, 1 - enable
set int_questions_auto_start 0

# bind for setup procedure
# after this command bot will try to make a new profile and start the interview
set int_bind(setup) "!setup"

# bind for update procedure
# after this command user will be able to update his profile information
set int_bind(updatee) "!update"

# bind for remove procedure
# after this command bot will try to remove profile
set int_bind(delete) "!remove"

# bind for release procedure
# after this command bot will try to destroy user's session (something like logout)
set int_bind(release) "!release"

# bind for sessions procedure
# after this command bot will print current sessions list (only for o|o)
set int_bind(sessions) "!sessions"

# bind for flush procedure
# after this command bot will try to destroy all sessions or just one given session (only for o|o)
set int_bind(flussh) "!flush"

# bind for questions start
# after this command bot will start the interview (priv command, after !setup)
# works only when $int_questions_auto_start is set to 0
# but, even if you set $int_questions_auto_start to 1, please leave here some word
set int_bind(questions_start) "start"

# messages
set int_msg(int_start) "hey! Your profile has been created, write: 'start' if you want to update your profile information now (6 extra questions)"
set int_msg(int_key) "here is your key: &k, save it, you will need it later for update or delete your profile"
set int_msg(int_end) "thanks for the answers, bye!"
set int_msg(update_start) "hi, if you want to update your profile you have to type your profile key now (paste it here and press enter)"
set int_msg(update_welcome) "hi, your key is OK, we can update your profile now; I will print the questions list for you, choose one and answer! (type number of question and press enter)"
set int_msg(update_question_list) "here are the questions(to stop the interview mode use !release on chan):"
set int_msg(update_question_number) "only numbers are allowed here (1 or more)"
set int_msg(update_question_number_range) "please choose number from 1 to 6"
set int_msg(update_wrong_key) "you typed wrong key, if you want to try again, please use !update <profile_name> again"
set int_msg(update_done) "information has been updated"
set int_msg(remove_start) "hi, if you want to remove this profile you have to type your profile key now (paste it here and press enter)"
set int_msg(remove_end) "profile has been successfully removed"
set int_msg(remove_wrong_key) "you typed wrong key, if you want to try again, please use !remove <profile_name> again"
set int_msg(just_one_command) "you can use just one command in the same time, !setup, !update or !remove; use !release if you want to use setup, update or remove command again"
set int_msg(profile_exists) "profile with that name already exists"
set int_msg(profile_not_exists) "profile with that name doesn't exists"
set int_msg(setup_already_in_use) "you can't use this command twice in the same time"
set int_msg(update_already_in_use) "you can't use this command twice in the same time"
set int_msg(remove_already_in_use) "you can't use this command twice in the same time"
set int_msg(setup_profile_name_already_in_use) "someone is already making setup with that name"
set int_msg(update_profile_name_already_in_use) "someone is already making update with that name"
set int_msg(remove_profile_name_already_in_use) "someone is already trying to remove profile with that name"
set int_msg(all_sessions_destroyed) "all sessions have been destroyed"
set int_msg(session_destroyed) "session has been destroyed"
set int_msg(session_n_exists) "session for this user doesn't exists"
set int_msg(sessions_list_empty) "sessions list is empty ;)"
set int_msg(release_empty) "your session doesn't exists"
set int_msg(release_done) "your session has been destroyed, you can use !setup, !update or !remove again"
set int_msg(setup_help) "use: !setup <profile_name>"
set int_msg(update_help) "use: !update <profile_name>"
set int_msg(remove_help) "use: !remove <profile_name>"
set int_msg(bind_help) "only small and BIG letters are allowed, sorry"
# </config>

# <procs> 

# procs from interviewer-addon to use in your script
# or if you want you can use this script, but i think,
# it will be easier to move these procs and the config section to other script and include the rest
# by using the 'source' command (use 'source' at the end of your script)

# this proc checks if profile exists or not
# proc should return 0 - if profile doesn't exists, 1 - when profile exists
# proc takes 4 arguments, nick/uhost/chan of user and profile name
# write here some sql query, check some file - whatever...
proc int_check_if_profile_exists { nick uhost profile_name chan } {
	putquick "PRIVMSG #debug :int_check_if_profile_exists{}: $nick $uhost $profile_name $chan r0"
	return 0
}

# this proc checks if key is correct or not
# proc should return 1 - if is correct, 0 - if is not
# proc takes 4 arguments, nick/uhost of user, profile name and profile key
# write here some sql query, check some file - whatever...
proc int_check_if_key_is_correct { nick uhost profile_name profile_key } {
	putquick "PRIVMSG #debug :int_check_if_key_is_correct{}: $nick $uhost $profile_name $profile_key r1"	
	return 1
}

# this proc is called when a profile needs to be removed
# proc takes 4 arguments, nick/uhost of user, profile name and action time
# write here some sql query, remove profile from some file - whatever
proc int_remove_profile_event { nick uhost profile_name action_time } {
	putquick "PRIVMSG #debug :int_remove_profile_event{}: $nick $uhost $profile_name $action_time"
}

# this proc is called when new profile is created
# proc takes 6 arguments, nick/uhost/chan of user, profile name, profile key and action time

# write this to sql, create profile in some file - whatever...
proc int_new_profile_event { nick uhost chan profile_name profile_key action_time} {
	putquick "PRIVMSG #debug :int_new_profile_event{}: $nick $uhost $chan $profile_name $profile_key $action_time"
}

# this proc is called after every answer (setup mode)
# proc takes 6 arguments, nick/uhost/profile name of user, answer, action time and question key
# write this to sql, some file - whatever...
proc int_answer_event { nick uhost profile_name arg action_time question_key } {
	putquick "PRIVMSG #debug :int_answer_event{}: $nick $uhost $profile_name $arg $action_time $question_key"
}

# this proc is called after every answer (update mode)
# proc takes 6 arguments, nick/uhost/profile name of user, answer, action time and question key
# write this to sql, some file - whatever...
proc int_update_event { nick uhost profile_name arg action_time question_key } {
	putquick "PRIVMSG #debug :int_update_event{}: $nick $uhost $profile_name $arg $action_time $question_key"
}

# </procs>

################################ high wizardry begins ######################################
############################################################################################
if {[string match "*s*" $int_proc_bind]} {
	bind pub -|- $int_bind(setup) int_proc_setup
}

if {[string match "*u*" $int_proc_bind]} {
	bind pub -|- $int_bind(updatee) int_proc_update
}

if {[string match "*d*" $int_proc_bind]} {
	bind pub -|- $int_bind(delete) int_proc_remove
}

if {[string match "*r*" $int_proc_bind]} {
	bind pub -|- $int_bind(release) int_proc_release
}

if {[string match "*e*" $int_proc_bind]} {
	bind pub o|o $int_bind(sessions) int_proc_sessions
}

if {[string match "*f*" $int_proc_bind]} {
	bind pub o|o $int_bind(flussh) int_proc_flush
}

if {[string match "*p*" $int_proc_bind]} {
	bind msgm -|- "*" int_proc_msgm
}

if {[string match "*a*" $int_proc_bind]} {
	bind part -|- "*" int_proc_part
}

if {[string match "*i*" $int_proc_bind]} {
	bind sign -|- "*" int_proc_sign
}

if {[string match "*l*" $int_proc_bind]} {
	bind splt -|- "*" int_proc_splt
}

if {[string match "*k*" $int_proc_bind]} {
	bind kick -|- "*" int_proc_kick
}

if {[string match "*n*" $int_proc_bind]} {
	bind nick -|- "*" int_proc_nick
}

setudef flag intadd

set int_global_nicks [list]
set int_global_uhosts [list]
set int_global_pnames [list]
set int_global_questions_idx [list]
set int_global_answers_mode [list]
set int_global_modes [list]
set int_global_update_mode [list]

proc putnq { data } {
	putdccraw 0 [string length "$data\n"] "$data\n"
}

proc int_check_global_n_u { nick uhost } {
	global int_global_nicks int_global_uhosts

	set new_n_u_state 0

	if {([lsearch $int_global_nicks $nick] > -1) && \
		([lsearch $int_global_uhosts $uhost] > -1)} {
				set new_n_u_state 1
	}

	return $new_n_u_state
}

proc int_check_global_pn { profile_name } {
	global int_global_pnames

	set new_pn_state 0

	if {[lsearch $int_global_pnames $profile_name] > -1} {
		set new_pn_state 1
	}

	return $new_pn_state
}

proc int_nick_to_profile { nick } {
	global int_global_nicks int_global_pnames

	set profile_name ""

	set nick_idx [lsearch $int_global_nicks $nick]

	set profile_name [lindex $int_global_pnames $nick_idx]

	return $profile_name
}

proc int_nick_to_idx { nick } {
	global int_global_nicks

	set nick_idx [lsearch $int_global_nicks $nick]

	return $nick_idx
}

proc int_nick_to_answer_mode { nick } {
	global int_global_answers_mode

	set nick_answer_mode ""

	set nick_global_idx [int_nick_to_idx $nick]

	set nick_answer_mode [lindex $int_global_answers_mode $nick_global_idx]

	return $nick_answer_mode
}

proc int_nick_to_update_mode { nick } {
	global int_global_update_mode

	set nick_update_mode ""

	set nick_global_idx [int_nick_to_idx $nick]

	set nick_update_mode [lindex $int_global_update_mode $nick_global_idx]

	return $nick_update_mode
}

proc int_nick_to_mode { nick } {
	global int_global_modes

	set nick_int_mode ""

	set nick_global_idx [int_nick_to_idx $nick]

	set nick_int_mode [lindex $int_global_modes $nick_global_idx]

	return $nick_int_mode
}

proc int_switch_answer_mode { nick } {
	global int_global_answers_mode

	set nick_global_idx [int_nick_to_idx $nick]

	set user_answer_mode [lindex $int_global_answers_mode $nick_global_idx]

	if {$user_answer_mode == 0} {
		set int_global_answers_mode [lreplace $int_global_answers_mode $nick_global_idx $nick_global_idx 1]
	} {
		set int_global_answers_mode [lreplace $int_global_answers_mode $nick_global_idx $nick_global_idx 0]
	}
}

proc int_switch_update_mode { nick } {
	global int_global_update_mode

	set nick_global_idx [int_nick_to_idx $nick]

	set user_update_mode [lindex $int_global_update_mode $nick_global_idx]

	if {$user_update_mode == 0} {
		set int_global_update_mode [lreplace $int_global_update_mode $nick_global_idx $nick_global_idx 1]
	} {
		set int_global_update_mode [lreplace $int_global_update_mode $nick_global_idx $nick_global_idx 0]
	}
}

proc int_incr_nick_idx { nick } {
	global int_global_questions_idx

	set nick_global_idx [int_nick_to_idx $nick]

	set nick_question_idx [expr [lindex $int_global_questions_idx $nick_global_idx] + 1]

	set int_global_questions_idx [lreplace $int_global_questions_idx $nick_global_idx $nick_global_idx $nick_question_idx]
}

proc int_set_nick_idx { nick new_idx } {
	global int_global_questions_idx

	set nick_global_idx [int_nick_to_idx $nick]

	set int_global_questions_idx [lreplace $int_global_questions_idx $nick_global_idx $nick_global_idx $new_idx]
}

proc int_nick_for_delete { nick } {
	global int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_global_modes int_global_update_mode

	set nick_global_idx [int_nick_to_idx $nick]

	set int_global_nicks [lreplace $int_global_nicks $nick_global_idx $nick_global_idx]
	set int_global_uhosts [lreplace $int_global_uhosts $nick_global_idx $nick_global_idx]
	set int_global_pnames [lreplace $int_global_pnames $nick_global_idx $nick_global_idx]
	set int_global_questions_idx [lreplace $int_global_questions_idx $nick_global_idx $nick_global_idx]
	set int_global_answers_mode [lreplace $int_global_answers_mode $nick_global_idx $nick_global_idx]
	set int_global_modes [lreplace $int_global_modes $nick_global_idx $nick_global_idx]
	set int_global_update_mode [lreplace $int_global_update_mode $nick_global_idx $nick_global_idx]
}

proc int_proc_setup { nick uhost hand chan arg } {
	global int_bind int_msg int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_global_modes int_global_update_mode int_bind_regexp int_questions_auto_start int_random_generator int_questions_list

	if {![channel get $chan intadd]} {
		return
	}

	set profile_name [lindex [split $arg] 0]

	if {$profile_name != ""} {
		if {![regexp $int_bind_regexp $profile_name]} {
			putnq "PRIVMSG $nick :$int_msg(bind_help)"
			return
		}

		if {[int_check_if_profile_exists $nick $uhost $profile_name $chan] == 0} {
			if {([int_nick_to_mode $nick] != "update") && ([int_nick_to_mode $nick] != "remove")} {
				if {[int_check_global_n_u $nick $uhost] == 0} {
					if {[int_check_global_pn $profile_name] == 0} {
						lappend int_global_nicks $nick
						lappend int_global_uhosts $uhost
						lappend int_global_pnames $profile_name
						lappend int_global_questions_idx 0
						lappend int_global_answers_mode 0
						lappend int_global_modes "setup"
						lappend int_global_update_mode 0

						if {$int_random_generator == 0} {
							set open_dev [open "/dev/urandom" r]
							set get_bytes [read $open_dev 16]   
							close $open_dev                     
						} {
							set some_numbers [expr floor(rand() * [clock seconds])]
							set some_string [lindex $int_questions_list [rand [llength $int_questions_list]]]
							set some_char [string index $some_string [expr [rand [string length $some_string]] - 1]]
							set get_bytes "$some_numbers $some_char"
						}

						set md5_key [md5 $get_bytes]
						set action_time [clock seconds]
						
						int_new_profile_event $nick $uhost $chan $profile_name $md5_key $action_time
	
						set key_msg $int_msg(int_key)
						regsub -all "&k" $key_msg $md5_key key_msg

						putnq "PRIVMSG $nick :$int_msg(int_start)"
						putnq "PRIVMSG $nick :$key_msg"

						if {$int_questions_auto_start == 1} {
							int_proc_msgm $nick $uhost $hand $int_bind(questions_start)
						}
					} {
						putnq "PRIVMSG $nick :$int_msg(setup_profile_name_already_in_use)"
					}
				} {
					putnq "PRIVMSG $nick :$int_msg(setup_already_in_use)"
				}
			} {
				putnq "PRIVMSG $nick :$int_msg(just_one_command)"
			}
		} {
			putnq "PRIVMSG $nick :$int_msg(profile_exists)"
		}
	} {
		putnq "PRIVMSG $nick :$int_msg(setup_help)"
	}
}

proc int_proc_update { nick uhost hand chan arg } {
	global int_msg int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_global_modes int_global_update_mode int_bind_regexp

	if {![channel get $chan intadd]} {
		return
	}

	set profile_name [lindex [split $arg] 0]

	if {$profile_name != ""} {
		if {![regexp $int_bind_regexp $profile_name]} {
			putnq "PRIVMSG $nick :$int_msg(bind_help)"
			return
		}

		if {[int_check_if_profile_exists $nick $uhost $profile_name $chan] == 1} {
			if {([int_nick_to_mode $nick] != "setup") && ([int_nick_to_mode $nick] != "remove")} {
				if {[int_check_global_n_u $nick $uhost] == 0} {
					if {[int_check_global_pn $profile_name] == 0} {
						lappend int_global_nicks $nick
						lappend int_global_uhosts $uhost
						lappend int_global_pnames $profile_name
						lappend int_global_questions_idx 0
						lappend int_global_answers_mode 0
						lappend int_global_modes "update"
						lappend int_global_update_mode 0

						putnq "PRIVMSG $nick :$int_msg(update_start)"
					} {
						putnq "PRIVMSG $nick :$int_msg(update_profile_name_already_in_use)"
					}
				} {
					putnq "PRIVMSG $nick :$int_msg(update_already_in_use)"
				}
			} {
				putnq "PRIVMSG $nick :$int_msg(just_one_command)"
			}
		} {
			putnq "PRIVMSG $nick :$int_msg(profile_not_exists)"
		}
	} {
		putnq "PRIVMSG $nick :$int_msg(update_help)"
	}
}

proc int_proc_remove { nick uhost hand chan arg } {
	global int_msg int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_global_modes int_global_update_mode int_bind_regexp

	if {![channel get $chan intadd]} {
		return
	}

	set profile_name [lindex [split $arg] 0]

	if {$profile_name != ""} {
		if {![regexp $int_bind_regexp $profile_name]} {
			putnq "PRIVMSG $nick :$int_msg(bind_help)"
			return
		}

		if {[int_check_if_profile_exists $nick $uhost $profile_name $chan] == 1} {
			if {([int_nick_to_mode $nick] != "setup") && ([int_nick_to_mode $nick] != "update")} {
				if {[int_check_global_n_u $nick $uhost] == 0} {
					if {[int_check_global_pn $profile_name] == 0} {
						lappend int_global_nicks $nick
						lappend int_global_uhosts $uhost
						lappend int_global_pnames $profile_name
						lappend int_global_questions_idx 0
						lappend int_global_answers_mode 0
						lappend int_global_modes "remove"
						lappend int_global_update_mode 0

						putnq "PRIVMSG $nick :$int_msg(remove_start)"
					} {
						putnq "PRIVMSG $nick :$int_msg(remove_profile_name_already_in_use)"
					}
				} {
					putnq "PRIVMSG $nick :$int_msg(remove_already_in_use)"
				}
			} {
				putnq "PRIVMSG $nick :$int_msg(just_one_command)"
			}
		} {
			putnq "PRIVMSG $nick :$int_msg(profile_not_exists)"
		}
	} {
		putnq "PRIVMSG $nick :$int_msg(remove_help)"
	}
}

proc int_proc_release { nick uhost hand chan arg } {
	global int_global_nicks int_msg

	if {![channel get $chan intadd]} {
		return
	}

	if {[lsearch $int_global_nicks $nick] > -1} {
		int_nick_for_delete $nick
		putnq "PRIVMSG $nick :$int_msg(release_done)"
	} {
		putnq "PRIVMSG $nick :$int_msg(release_empty)"
	}
}

proc int_proc_msgm { nick uhost hand arg } {
	global int_bind int_msg int_questions_list int_global_questions_idx int_questions_key int_questions_regexp int_question_help

	set arg [string trim $arg]

	if {[int_check_global_n_u $nick $uhost] == 1} {
		set profile_name [int_nick_to_profile $nick]
		set nick_global_idx [int_nick_to_idx $nick]
		set nick_answer_mode [int_nick_to_answer_mode $nick]
		set nick_update_mode [int_nick_to_update_mode $nick]
		set questions_counter [expr [llength $int_questions_list] - 1]
		set action_time [clock seconds]
		set nick_question_idx [lindex $int_global_questions_idx $nick_global_idx]
		set nick_int_mode [int_nick_to_mode $nick]

		if {$nick_int_mode == "setup"} {
			if {$nick_answer_mode == 0} {
				if {$int_bind(questions_start) == $arg} {
					putnq "PRIVMSG $nick :[lindex $int_questions_list $nick_question_idx]"
					int_switch_answer_mode $nick
				}
			} {
				if {[lindex $int_global_questions_idx $nick_global_idx] < $questions_counter} {
					if {[regexp [lindex $int_questions_regexp $nick_question_idx] $arg]} {
						int_incr_nick_idx $nick

						int_answer_event $nick $uhost $profile_name $arg $action_time [lindex $int_questions_key $nick_question_idx]
						putnq "PRIVMSG $nick :[lindex $int_questions_list [expr $nick_question_idx + 1]]"
					} {
						putnq "PRIVMSG $nick :[lindex $int_question_help $nick_question_idx]"
					}
				} {
					if {[regexp [lindex $int_questions_regexp $nick_question_idx] $arg]} {
						int_answer_event $nick $uhost $profile_name $arg $action_time [lindex $int_questions_key $nick_question_idx]
						int_nick_for_delete $nick
						putnq "PRIVMSG $nick :$int_msg(int_end)"
					} {
						putnq "PRIVMSG $nick :[lindex $int_question_help $nick_question_idx]"
					}
				}
			}
		} elseif {$nick_int_mode == "update"} {
			set question_list [list]

			set question_idx 1
			foreach question $int_questions_list {
				if {$question != ""} {
					lappend question_list "$question_idx\) $question"
					incr question_idx 1
				}
			}

			set question_list [join $question_list ", "]

			if {$nick_answer_mode == 0} {
				if {[int_check_if_key_is_correct $nick $uhost $profile_name $arg] == 1} {
					putnq "PRIVMSG $nick :$int_msg(update_welcome)"
					putnq "PRIVMSG $nick :$int_msg(update_question_list) $question_list"
					int_switch_answer_mode $nick
				} {
					int_nick_for_delete $nick
					putnq "PRIVMSG $nick :$int_msg(update_wrong_key)"
				}
			} {
				if {$nick_update_mode == 0} {
					if {[regexp {^[0-9]+$} $arg]} {
						if {($arg > 0) && ($arg <= [expr $questions_counter + 1])} {
							putnq "PRIVMSG $nick :[lindex $int_questions_list [expr $arg - 1]]"
							int_switch_update_mode $nick
							int_set_nick_idx $nick [expr $arg - 1]
						} {
							putnq "PRIVMSG $nick :$int_msg(update_question_number_range)"
						}
					} {
						putnq "PRIVMSG $nick :$int_msg(update_question_number)"
					}
				} {
					if {[regexp [lindex $int_questions_regexp $nick_question_idx] $arg]} {
						int_update_event $nick $uhost $profile_name $arg $action_time [lindex $int_questions_key $nick_question_idx]
						putnq "PRIVMSG $nick :$int_msg(update_done)"
						putnq "PRIVMSG $nick :$int_msg(update_question_list) $question_list"
						int_switch_update_mode $nick
						int_set_nick_idx $nick 0
					} {
						putnq "PRIVMSG $nick :[lindex $int_question_help $nick_question_idx]"
					}
				}
			}
		} elseif {$nick_int_mode == "remove"} {
			if {[int_check_if_key_is_correct $nick $uhost $profile_name $arg] == 1} {
				int_nick_for_delete $nick
				int_remove_profile_event $nick $uhost $profile_name $action_time
				putnq "PRIVMSG $nick :$int_msg(remove_end)"
			} {
				int_nick_for_delete $nick
				putnq "PRIVMSG $nick :$int_msg(remove_wrong_key)"
			}
		}
	}
}

proc int_proc_sessions { nick uhost hand chan arg } {
	global int_msg int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_questions_key int_global_modes int_global_update_mode

	if {![channel get $chan intadd]} {
		return
	}

	set sess_len [llength $int_global_nicks]

	if {$sess_len > 0} {
		putnq "PRIVMSG $nick :nick   |   uhost   |   profile   |   qidx   |   qkey   |   amode   |   imode   |   umode"

		for {set i 0} {$i < $sess_len} {incr i 1} {
			putnq "PRIVMSG $nick :[lindex $int_global_nicks $i]   |   [lindex $int_global_uhosts $i]   |   [lindex $int_global_pnames $i]   |   [lindex $int_global_questions_idx $i]   |   [lindex $int_questions_key [lindex $int_global_questions_idx $i]]   |   [lindex $int_global_answers_mode $i]   |   [lindex $int_global_modes $i]   |   [lindex $int_global_update_mode $i]"
		}
	} {
		putnq "PRIVMSG $nick :$int_msg(sessions_list_empty)"
	}
}

proc int_proc_flush { nick uhost hand chan arg } {
	global int_global_nicks int_msg int_bind_regexp int_global_nicks int_global_uhosts int_global_pnames int_global_questions_idx int_global_answers_mode int_global_modes int_global_update_mode

	if {![channel get $chan intadd]} {
		return
	}

	set nick_to_flush [lindex [split $arg] 0]

	if {$nick_to_flush != ""} {
		if {![regexp $int_bind_regexp $nick_to_flush]} {
			putnq "PRIVMSG $nick :$int_msg(bind_help)"
			return
		}

		if {[lsearch $int_global_nicks $nick_to_flush] > -1} {
			int_nick_for_delete $nick_to_flush
			putnq "PRIVMSG $nick :$int_msg(session_destroyed)"
		} {
			putnq "PRIVMSG $nick :$int_msg(session_n_exists)"
		}
	} {
		set int_global_nicks [list]
		set int_global_uhosts [list]
		set int_global_pnames [list]
		set int_global_questions_idx [list]
		set int_global_answers_mode [list]
		set int_global_modes [list]
		set int_global_update_mode [list]
		putnq "PRIVMSG $nick :$int_msg(all_sessions_destroyed)"
	}
}

proc int_proc_part { nick uhost hand chan msg } {
	global int_global_nicks 

	if {![channel get $chan intadd]} {
		return
	}

	if {[lsearch $int_global_nicks $nick] > -1} {
		int_nick_for_delete $nick
	}
}

proc int_proc_sign { nick uhost hand chan msg } {
	global int_global_nicks

	if {![channel get $chan intadd]} {
		return
	}

	if {[lsearch $int_global_nicks $nick] > -1} {
		int_nick_for_delete $nick
	}
}

proc int_proc_splt { nick uhost hand chan } {
	global int_global_nicks

	if {![channel get $chan intadd]} {
		return
	}

	if {[lsearch $int_global_nicks $nick] > -1} {
		int_nick_for_delete $nick
	}
}

proc int_proc_kick { nick uhost hand chan target rsn } {
	global int_global_nicks 

	if {![channel get $chan intadd]} {
		return
	}

	if {[lsearch $int_global_nicks $target] > -1} {
		int_nick_for_delete $target
	}
}

proc int_proc_nick { nick uhost hand chan newnick } {
	global int_global_nicks

	if {![channel get $chan intadd]} {
		return
        }

	set nick_global_idx [int_nick_to_idx $nick]
	if {$nick_global_idx > -1} {
		set int_global_nicks [lreplace $int_global_nicks $nick_global_idx $nick_global_idx $newnick]
	}
}

putlog "interviewer-addon.tcl ver 0.1 by tomekk loaded"
# end of magic ;)
Script is using pseudo-session system (couple lists in eggdrop memory not in the file!) based on user nick and ident@host.
Script is tracking user nick, channel part/sign/splt/kick. You can change your nick during setup/update/remove session, bot will automatically change this in the your session.
Bot will automatically remove your session from the sessions list, when you part, sign the channel or when you get splt, kick from it.

- It's impossible to use setup, update or remove command in the same time (I mean by the same user, you have to finish one and after you can use another)
- It's impossible to use setup, update or remove by two or more users with the same profile name (if user1 used '!setup myprofile', then other users can't use '!setup myprofile' because this is name is already in use)

Of course all command names, messages etc. are configurable in the config header of interview-addon script.
All command names which I'm using now are the default names.

Commands and other things have some comments in the script, should be no problem.
I think example of simple implementation will show you almost all.

--
Ok example, I wrote simple script to show how the interviewer-addon procedures are working. All the data from input goes to #debug chan.
(there should be mysql profile script based on interview-addon in few days)

Ah, one more thing. All proc names, global vars starts from int_ prefix.

First example, I assume that the profile name does not exist and we can make it (procedure returns 0)
chan:
19:46:47 <@tomekk> !setup sarge
later priv:
19:46:47 <botty> hey! Your profile has been created, write: 'start' if you want to update your profile information now (6 extra questions)
19:46:47 <botty> here is your key: 0fa06613ef5cda75f07db276b3207b7f, save it, you will need it later for update or delete your profile
19:47:07 <tomekk> something
19:47:13 <tomekk> start
19:47:13 <botty> what is your age?
19:47:17 <tomekk> abc
19:47:18 <botty> only numbers are allowed (0 - 99)
19:47:20 <tomekk> 66
19:47:21 <botty> what is your sex?
19:47:27 <tomekk> hmm
19:47:27 <botty> male, female, strogg or alien
19:47:30 <tomekk> strogg
19:47:30 <botty> where are you from?
19:47:46 <tomekk> space
19:47:47 <botty> what is your fav FPS game?
19:47:55 <tomekk> superfrog
19:47:55 <botty> quake1,2,3 or doom1,2,3 or half life1,2
19:47:58 <tomekk> quake2
19:47:58 <botty> what is your fav map?
19:48:07 <tomekk> The Edge - q2dm1
19:48:07 <botty> what is your fav game music track?
19:48:19 <tomekk> sonic mayhem - operation overload
19:48:19 <botty> thanks for the answers, bye!
actions on #debug during first example:
19:46:47 < botty> int_check_if_profile_exists{}: tomekk tomekk@oswiecim.eu.org sarge #kupa r0 <-- proc returned 0 then we know that the profile doesn't exist and we can make new
19:46:47 < botty> int_new_profile_event{}: tomekk tomekk@oswiecim.eu.org #kupa sarge 0fa06613ef5cda75f07db276b3207b7f 1250790292 <-- we are making new profile now (of course some proper code inside int_new_profile_event procedure will make new profile in some DB)
19:47:21 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge 66 1250790325 age <-- 1st answer
19:47:30 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge strogg 1250790335 sex <-- 2nd answer
19:47:47 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge space 1250790351 from <-- 3rd answer
19:47:58 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge quake2 1250790363 fps <-- 4th answer
19:48:07 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge The Edge - q2dm1 1250790372 map <-- 5th answer
19:48:19 < botty> int_answer_event{}: tomekk tomekk@oswiecim.eu.org sarge sonic mayhem - operation overload 1250790383 track <-- 6th answer
Second example, I assume that the profile name exist and we can't make it (procedure returns 1)
chan:
19:46:47 <@tomekk> !setup sarge
later priv:
19:59:53 <botty> profile with that name already exists
actions on #debug during second example:
19:59:54 < botty> int_check_if_profile_exists{}: tomekk tomekk@oswiecim.eu.org sarge #kupa r1 <-- proc returned 1 then we know that the profile exist and we can't make new
Third example, I assume that the profile name exist (procedure returns 1) and the key which I typed is correct (procedure returns 1)
chan:
20:04:25 <@tomekk> !update sarge
later priv:
20:04:25 <botty> hi, if you want to update your profile you have to type your profile key now (paste it here and
press enter)
20:06:15 <tomekk> mygeneratedkeygoeshere
20:06:16 <botty> hi, your key is OK, we can update your profile now; I will print the questions list for you,
choose one and answer! (type number of question and press enter)
20:06:16 <botty> here are the questions(to stop the interview mode use !release on chan): 1) what is your age?,
2) what is your sex?, 3) where are you from?, 4) what is your fav FPS game?, 5) what is your
fav map?, 6) what is your fav game music track?
20:06:38 <tomekk> qwe
20:06:38 <botty> only numbers are allowed here (1 or more)
20:06:49 <tomekk> 0
20:06:49 <botty> please choose number from 1 to 6
20:06:52 <tomekk> 7
20:06:53 <botty> please choose number from 1 to 6
20:06:58 <tomekk> 1
20:06:58 <botty> what is your age?
20:07:03 <tomekk> 69
20:07:03 <botty> information has been updated
20:07:03 <botty> here are the questions(to stop the interview mode use !release on chan): 1) what is your age?,
2) what is your sex?, 3) where are you from?, 4) what is your fav FPS game?, 5) what is your
fav map?, 6) what is your fav game music track?
20:07:12 <tomekk> 4
20:07:12 <botty> what is your fav FPS game?
20:07:21 <tomekk> worms
20:07:21 <botty> quake1,2,3 or doom1,2,3 or half life1,2
20:07:24 <tomekk> quake3
20:07:24 <botty> information has been updated
20:07:24 <botty> here are the questions(to stop the interview mode use !release on chan): 1) what is your age?,
2) what is your sex?, 3) where are you from?, 4) what is your fav FPS game?, 5) what is your
fav map?, 6) what is your fav game music track?
20:07:28 <tomekk> 5
20:07:28 <botty> what is your fav map?
20:07:37 <tomekk> The Longest Yard - q3dm17
20:07:37 <botty> information has been updated
20:07:37 <botty> here are the questions(to stop the interview mode use !release on chan): 1) what is your age?,
2) what is your sex?, 3) where are you from?, 4) what is your fav FPS game?, 5) what is your
fav map?, 6) what is your fav game music track?
actions on #debug during third example:
20:04:25 < botty> int_check_if_profile_exists{}: tomekk tomekk@oswiecim.eu.org sarge #kupa r0 <-- again, profile check
20:06:16 < botty> int_check_if_key_is_correct{}: tomekk tomekk@oswiecim.eu.org sarge mygeneratedkeygoeshere r1 <-- in this case, we need to check key for our profile, returns 1 then key is correct
20:07:03 < botty> int_update_event{}: tomekk tomekk@oswiecim.eu.org sarge 69 1250791508 age <-- 1st update answer
20:07:24 < botty> int_update_event{}: tomekk tomekk@oswiecim.eu.org sarge quake3 1250791529 fps <-- 2nd update answer
20:07:37 < botty> int_update_event{}: tomekk tomekk@oswiecim.eu.org sarge The Longest Yard - q3dm17 1250791542
map <-- 3rd update answer
and, for the end:
chan:
20:07:42 <@tomekk> !release
later priv:
20:07:42 <botty> your session has been destroyed, you can use !setup, !update or !remove again
Fourth example, I assume that the profile name exist (procedure returns 1) and the key which I typed is correct (procedure returns 1)
chan:
20:15:01 <@tomekk> !remove sarge
later priv:
20:15:01 <botty> hi, if you want to remove this profile you have to type your profile key now (paste it here and
press enter)
20:16:16 <tomekk> mykey
20:16:16 <botty> profile has been successfully removed
actions on #debug during fourth example:
20:15:01 < botty> int_check_if_profile_exists{}: tomekk tomekk@oswiecim.eu.org sarge #kupa r0 <-- again, profile check
20:16:16 < botty> int_check_if_key_is_correct{}: tomekk tomekk@oswiecim.eu.org sarge mykey r1 <-- again, key check
20:16:16 < botty> int_remove_profile_event{}: tomekk tomekk@oswiecim.eu.org sarge 1250792061 <-- if all were good, remove the profile
Fifth example:
chan:
20:18:58 <@tomekk> !sessions
later priv:
20:18:59 <botty> nick | uhost | profile | qidx | qkey | amode | imode | umode
20:18:59 <botty> tomekk | tomekk@oswiecim.eu.org | asd | 0 | age | 0 | remove | 0
20:19:03 <botty> someone | aaaa@some.host.com | myprofile | 2 | from | 1 | setup | 0
20:19:07 <botty> johndoe | blabla@some2.host2.com | sarge | 3 | fps | 1 | update | 1
It's just a tool for o|o ;)
Descriptions/options for flush and other things are in config header.

Here are the codes which I used for examples:
- interviewer-addon without config header and procs
- some other script with included interviewer-addon script and with config, procs from interviewer-addon script

I have problem with

Code: Select all

, maybe post is to long or something, lol[/b]
[b]if you want those codes, download it from here:[/b]
http://temp.tomekk.org/interviewer-addon-0.1.tcl.bz2
http://temp.tomekk.org/pro-ultra-profile-script.tcl.bz2
Post Reply