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.

MySQL Profile Script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Okey, snippet,
I can make this (I think this will be better than teasers), but this still will be nick based right?
I mean, profile in the db: 'tomekk', now when some user with nick 'tomekk' joins the channel bot prints snippet for it, right? ($nick == $profile_name)

Anyway, I will add an option for enable or disable this 'thing', this on-join 'thing'
Last edited by tomekk on Sun Aug 30, 2009 5:45 am, edited 1 time in total.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

first file, interview-addon-0.1.tcl

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

# config header and procs moved to mysql-profile-0.*.tcl

################################ 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 ;)
second file, mysql-profile-0.1.tcl

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 +profile
# and later .save

# variables and procedures:
# with profile_ prefix are from mysql-profile script
# with int_ prefix are from interviewer-addon

# on-join 'snippet' profile information proc (based only on nick!, if $nick == $profile_name then show short msg)
# 0 - disabled, 1 - enabled
set profile_on_join 1

# bind for view procedure
# after this command bot will show the user profile
set profile_view_command "!view"

# bot for list procedure
# after this command bot will show the list of profile names
set profile_list_command "!list"

# bind for delete procedure
# after this command bot will delete the profile (only for o|o)
# user can delete his profile by typing !remove (only when key will be correct)
set profile_drop_command "!delete"

# bind for help procedure
# after this command bot will show the available commands
set profile_help_command "!help"

# 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"

# mysql user
set profile_mysql_user "db_user"

# mysql pass
set profile_mysql_pass "db_pass"

# mysql host
set profile_mysql_host "localhost"

# mysql database
set profile_mysql_dbase "profiles"

# mysql table
set profile_mysql_table "users"

# interviewer-addon script path
set interviewer_addon_path "scripts/interviewer-addon-0.1.tcl"

# regexp for !setup, !update, !remove, !flush commands (default, only small and BIG letters are allowed)
# in this script (mysql-profile-0.*.tcl), all profiles names are in 'lower case', but we have to allow big chars because someone can write !setup MyNiCk or something, otherwise script will make 'mynick' ;)
set int_bind_regexp {^[a-zA-Z]+$}

# all these five lists must have the same number of elements
# headers for !view
set profile_view_headers {
	"&n location:"
	"&n age:"
	"&n gender:"
	"&n description:"
	"&n kinks:"
	"&n limits:"
	"&n position:"
	"&n orientation:"
	"&n web URL:"
}

# questions lists, one by one
set int_questions_list {
	"your location ;>"
	"your age ;>"
	"your gender ;>"
	"your description ;>"
	"your kinks ;>"
	"your limits ;>"
	"your position ;>"
	"your orientation ;>"
	"your web URL ;>"
}

# uniq key of each question
# some short uniq word, without spaces will be better
set int_questions_key {
	"p_location"
	"p_age"
	"p_gender"
	"p_description"
	"p_kinks"
	"p_limits"
	"p_position"
	"p_orientation"
	"p_url"
}

# questions regexps, one by one
# if you don't know how to build regexp, use {.*}  and pray (.* any chars ;p)
set int_questions_regexp {
	{^.{1,64}$}
	{^[0-9]{1,2}$}
	{^(male|female)$}
	{^.{1,255}.{0,1}$}
	{^.{1,255}.{0,1}$}
	{^.{1,255}.{0,1}$}
	{^.{1,255}.{0,1}$}
	{^.{1,255}.{0,1}$}
	{^http:\/\/.{1,249}$}
}

# questions help messages, one by one
set int_question_help {
	"max 64 chars here, sorry"
	"only numbers are allowed (0-99)"
	"male or female"
	"max 256 chars here, sorry"
	"max 256 chars here, sorry"
	"max 256 chars here, sorry"
	"max 256 chars here, sorry"
	"max 256 chars here, sorry"
	"max 256 chars here and don't forget about 'http://' at the beginning"
}

# messages
set profile_help "available commands for every user: !setup, !update, !remove, !release, !view, !list"

set int_msg(int_start) "hey! Your profile has been created, get your key and type some info about yourself!"
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"

# 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 1

# 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 1

# 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"

################################################################################################################
bind pub -|- $profile_view_command profile_view_proc
bind pub -|- $profile_list_command profile_list_proc
bind pub -|- $profile_drop_command profile_drop_proc
bind pub -|- $profile_help_command profile_help_proc

if {$profile_on_join == 1} {
	bind join -|- "*" profile_do_on_join
}

package require mysqltcl

setudef flag profile

proc profile_mysql_query { result_mode mysql_query } {
	global profile_mysql_user profile_mysql_pass profile_mysql_host profile_mysql_dbase

	set mysql_result ""

	set mysql_handle [::mysql::connect -host $profile_mysql_host -user $profile_mysql_user -password $profile_mysql_pass]

	::mysql::use $mysql_handle $profile_mysql_dbase

	if {$result_mode == "quiet"} {
		::mysql::exec $mysql_handle $mysql_query
	} elseif {$result_mode == "verbose"} {
		set mysql_result [::mysql::sel $mysql_handle $mysql_query -flatlist]
	}

	::mysql::close $mysql_handle

	if {$result_mode == "verbose"} {
		return $mysql_result
	}
}

proc profile_check_if_profile_exists { profile_name } {
	global profile_mysql_table

	set profile_name [::mysql::escape $profile_name]

	set query_result [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table WHERE p_name='$profile_name'"]

	if {$query_result != ""} {
		return 1
	} {
		return 0
	}
}

proc profile_delete_proc { profile_name } {
	global profile_mysql_table

	set profile_name [::mysql::escape $profile_name]

	profile_mysql_query quiet "DELETE from $profile_mysql_table where p_name='$profile_name'"
}

proc profile_view_proc { nick uhost hand chan arg } {
	global profile_mysql_table profile_view_headers profile_view_command

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

	set profile_name [::mysql::escape [string tolower [lindex [split $arg] 0]]]

	if {$profile_name != ""} {
		if {[profile_check_if_profile_exists $profile_name]} {
			set query_result [profile_mysql_query verbose "SELECT p_location, p_age, p_gender, p_description, p_kinks, p_limits, p_position, p_orientation, p_url FROM $profile_mysql_table WHERE p_name='$profile_name'"]
			set header_idx 0

			foreach query_row $query_result { 
				set each_header [lindex $profile_view_headers $header_idx]

				regsub "&n" $each_header "$profile_name\'s" each_header

				if {$query_row != ""} {
					putnq "PRIVMSG $nick :$each_header $query_row"
				} {
					putnq "PRIVMSG $nick :$each_header N/A"
				}

				incr header_idx 1
			}
		} {
			putnq "PRIVMSG $nick :profile $profile_name doesn't exists"
		}
	} {
		putnq "PRIVMSG $nick :use: $profile_view_command <profile_name>"
	}
}

proc profile_list_proc { nick uhost hand chan arg } {
	global profile_mysql_table profile_list_command

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

	set list_number [lindex [split $arg] 0]

	if {$list_number != ""} {
		switch -- $list_number {
			"1" {
				set query_result_a [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table WHERE p_name REGEXP '^\[a-f\]' ORDER BY p_name"]
				set count_af [llength $query_result_a]
				set af_list [join $query_result_a ", "]

				if {$af_list != ""} {
					putnq "PRIVMSG $nick :list from A to F ($count_af): $af_list"
				} {
					putnq "PRIVMSG $nick :list is empty"
				}
			}

			"2" {
				set query_result_b [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table WHERE p_name REGEXP '^\[g-l\]' ORDER BY p_name"]
				set count_gl [llength $query_result_b]
				set gl_list [join $query_result_b ", "]

				if {$gl_list != ""} {
					putnq "PRIVMSG $nick :list from G to L ($count_gl): $gl_list"
				} {
					putnq "PRIVMSG $nick :list is empty"
				}
			}

			"3" {
				set query_result_c [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table WHERE p_name REGEXP '^\[m-r\]' ORDER BY p_name"]
				set count_mr [llength $query_result_c]
				set mr_list [join $query_result_c ", "]
				
				if {$mr_list != ""} {
					putnq "PRIVMSG $nick :list from M to R ($count_mr): $mr_list"
				} {
					putnq "PRIVMSG $nick :list is empty"
				}
			}

			"4" {
				set query_result_d [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table WHERE p_name REGEXP '^\[s-z\]' ORDER BY p_name"]
				set count_sz [llength $query_result_d]
                                set sz_list [join $query_result_d ", "]

				if {$sz_list != ""} {
					putnq "PRIVMSG $nick :list from S to Z ($count_sz): $sz_list"
				} {
					putnq "PRIVMSG $nick :list is empty"
				}
			}

			"showall" {
				set query_result_e [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table ORDER BY p_name"]
				set whole_list [join $query_result_e ", "]

				if {$whole_list != ""} {
					putnq "PRIVMSG $nick :whole list: $whole_list"
				} {
					putnq "PRIVMSG $nick :list is empty"
				}
			}

			"count" {
				set query_result_f [profile_mysql_query verbose "SELECT p_name FROM $profile_mysql_table"]
				set count_profiles [llength $query_result_f]

				putnq "PRIVMSG $nick :$count_profiles profile/s in the database"
			}
		}
	} {
		putnq "PRIVMSG $nick :use: $profile_list_command 1 (A->F) / $profile_list_command 2 (G->L) / $profile_list_command 3 (M->R) / $profile_list_command 4 (S-Z) / $profile_list_command showall / $profile_list_command count"
	}
}

proc profile_drop_proc { nick uhost hand chan arg } {
        global profile_mysql_table profile_drop_command

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

	if {[string trim $arg] != ""} {
		foreach profile_name [split $arg] {
			set profile_name [::mysql::escape [string tolower $profile_name]]
			if {$profile_name != ""} {
				if {[profile_check_if_profile_exists $profile_name]} {
					profile_delete_proc $profile_name
					putnq "PRIVMSG $nick :profile $profile_name has been deleted"
				} {
					putnq "PRIVMSG $nick :profile $profile_name doesn't exists"
				}
			}
		}
	} {
		putnq "PRIVMSG $nick :use: $profile_drop_command <profile_name> ... <profile_name>"
	}
}

proc profile_help_proc { nick uhost hand chan arg } {
	global profile_help

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

	putnq "PRIVMSG $nick :$profile_help"
}

proc int_check_if_profile_exists { nick uhost profile_name chan } {
	if {[profile_check_if_profile_exists $profile_name] == 1} {
		return 1
	} {
		return 0
	}
}

proc int_check_if_key_is_correct { nick uhost profile_name profile_key } {
	global profile_mysql_table

	set profile_name [::mysql::escape $profile_name]
        set profile_key [md5 $profile_key]

	set query_result [profile_mysql_query verbose "SELECT p_key FROM $profile_mysql_table WHERE p_name='$profile_name'"]

	if {[lindex $query_result 0] == $profile_key} {
		return 1
	} {
		return 0
	}
}

proc int_remove_profile_event { nick uhost profile_name action_time } {
	profile_delete_proc $profile_name
}

proc int_new_profile_event { nick uhost chan profile_name profile_key action_time} {
	global profile_mysql_table

	set nick [::mysql::escape $nick]
	set uhost [::mysql::escape $uhost]
	set profile_name [::mysql::escape $profile_name]
	set profile_key [md5 $profile_key]

	profile_mysql_query quiet "INSERT INTO $profile_mysql_table (p_name, p_key, p_nick, p_host, p_crt_date) VALUES('$profile_name', '$profile_key', '$nick', '$uhost', '$action_time')"

}

proc int_answer_event { nick uhost profile_name arg action_time question_key } {
	global profile_mysql_table

	set profile_name [::mysql::escape $profile_name]
	set arg [::mysql::escape $arg]
	set question_key [::mysql::escape $question_key]

	profile_mysql_query quiet "UPDATE $profile_mysql_table SET $question_key='$arg' WHERE p_name='$profile_name'"
}

proc int_update_event { nick uhost profile_name arg action_time question_key } {
	global profile_mysql_table

        set profile_name [::mysql::escape $profile_name]
	set arg [::mysql::escape $arg]
	set question_key [::mysql::escape $question_key]

	profile_mysql_query quiet "UPDATE $profile_mysql_table SET $question_key='$arg', p_lupd_date='$action_time' WHERE p_name='$profile_name'"
}

proc profile_do_on_join { nick uhost hand chan } {
	global profile_mysql_table profile_view_command botnick

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

	if {$botnick == $nick} {
		return
	}

	set profile_name [::mysql::escape $nick]

	if {[profile_check_if_profile_exists $profile_name]} {
		set query_result [profile_mysql_query verbose "SELECT p_age, p_location, p_gender FROM users WHERE p_name='$profile_name'"]
		
		set p_age [lindex $query_result 0]
		set p_location [lindex $query_result 1]
		set p_gender [lindex $query_result 2]

		putquick "PRIVMSG $chan :$profile_name has a profile. Age: $p_age\, Location: $p_location\, Gender: $p_gender\. To see $profile_name\'s full profile type $profile_view_command $profile_name"
	}
}

source $interviewer_addon_path
putlog "mysql-profile.tcl ver 0.1 by tomekk loaded"
database:
- database name, I made: profiles
- table with profiles, I made: users

Code: Select all

CREATE TABLE users (
	id INT(4) AUTO_INCREMENT, 
	p_name VARCHAR(32), 
	p_key VARCHAR(32),
	p_nick VARCHAR(32),
	p_host VARCHAR(128),
	p_crt_date VARCHAR(10),
	p_lupd_date VARCHAR(10),
	p_location VARCHAR(64),
	p_age VARCHAR(2),
	p_gender VARCHAR(6),
	p_description VARCHAR(256),
	p_kinks VARCHAR(256),
	p_limits VARCHAR(256),
	p_position VARCHAR(256),
	p_orientation VARCHAR(256),
	p_url VARCHAR(256),
	primary key(id)
);
some examples:
!list, !list count, !list showall
1:21:07 <botty> use: !list 1 (A->F) / !list 2 (G->L) / !list 3 (M->R) / !list 4 (S-Z) / !list showall / !list
count
11:21:39 <botty> 10 profile/s in the database
11:21:34 <botty> whole list: alpha, cyc, gamma, krystyna, narcyz, test, tomek, tomekk, xen, zenek
tomek joins the chan:
11:23:00 -!- tomek [tomekk@10.0.1.10] has joined #kupa
11:23:00 < botty> tomek has a profile. Age: 22, Location: somewhere in poland ;), Gender: male. To see tomek's
full profile type !view tomek
!view tomek
11:23:45 <botty> tomek's location: somewhere in poland ;)
11:23:45 <botty> tomek's age: 22
11:23:45 <botty> tomek's gender: male
11:23:45 <botty> tomek's description: here goes my desc, sd $% U$^&*U"4%^#!@Q$ T%@#%=0ty34\tyhyt[ ]]\ puts '
11:23:45 <botty> tomek's kinks: emany ;D [die] zonk [\\\] \\023432df ;0
11:23:46 <botty> tomek's limits: no
11:23:49 <botty> tomek's position: no
11:23:50 <botty> tomek's orientation: no
11:23:52 <botty> tomek's web URL: http://tomekk.org/
!setup myprofile
11:28:17 <botty> hey! Your profile has been created, get your key and type some info about yourself!
11:28:17 <botty> here is your key: 441e4f5873d85827610dd265153024df, save it, you will need it later for update
or delete your profile
11:28:17 <botty> your location ;>
11:28:24 <tomekk> Space
11:28:24 <botty> your age ;>
11:28:26 <tomekk> 69
11:28:26 <botty> your gender ;>
11:28:28 <tomekk> male
11:28:29 <botty> your description ;>
11:28:35 <tomekk> some desc
11:28:35 <botty> your kinks ;>
11:28:38 <tomekk> some kinks
11:28:39 <botty> your limits ;>
11:28:40 <tomekk> some limits
11:28:41 <botty> your position ;>
11:28:46 <tomekk> horizontal
11:28:46 <botty> your orientation ;>
11:28:55 <tomekk> hmm...
11:28:55 <botty> your web URL ;>
11:28:58 <tomekk> some
11:28:58 <botty> max 256 chars here and don't forget about 'http://' at the beginning
11:29:12 <tomekk> http://somewhere.blabla.com/
11:29:13 <botty> thanks for the answers, bye!
available commands for every user: !setup, !update, !remove, !release, !view, !list

available commands for o|o: !delete, !sessions, !flush

Just try all commands, read the comments in the config header.
It's very easy.

I made nick, uhost, creation_date, last_update fields in database,
I think those fields can be useful for your PHP page.

Ahh, dont forget about .chanset #channel_name +intadd +profile

try it, cheers
D
Daedalus
Voice
Posts: 24
Joined: Wed Jun 27, 2007 7:12 pm

Post by Daedalus »

Thank you very much! I'll give it a whirl now.

I would have answered this sooner but I'm a twit and didn't see there was a second page when I was refreshing. Doh!
User avatar
Domin
Halfop
Posts: 72
Joined: Sat Jun 10, 2006 9:10 am

Post by Domin »

Looks sweet, will the php part of it be pasted here to ?
Regards
Domin @ efnet
D
Daedalus
Voice
Posts: 24
Joined: Wed Jun 27, 2007 7:12 pm

Post by Daedalus »

When I've made the PHP to pull the data, I'll post it here if it's wanted. :)
D
Daedalus
Voice
Posts: 24
Joined: Wed Jun 27, 2007 7:12 pm

Post by Daedalus »

Hmmm... Ran into a little snag deploying this on one server which apparently has a pretty low sendq. Bot disconnects with excess flood. Just so anyone who comes along and has the same problem in the future knows why that happens...
D
Daedalus
Voice
Posts: 24
Joined: Wed Jun 27, 2007 7:12 pm

Post by Daedalus »

Daedalus wrote:Hmmm... Ran into a little snag deploying this on one server which apparently has a pretty low sendq. Bot disconnects with excess flood. Just so anyone who comes along and has the same problem in the future knows why that happens...
^^ Disregard the above. It turned out to be a rather simple error on my part when using a perl script to convert the flatfiles from the old profile script I was using into the new mysql database.

Incidentally, here's the php I'm using on my site to read from the DB. Note that this is only a first version, and so the code is a bit basic. It does work however.

Code: Select all

<?php

// Includes.

include 'pconfig.php';
include 'popendb.php';

// Static page formatting.

$PreString="<p>This lets you view profiles for the IRC channel <a href='irc://irc.sexnet.org/playthings4roughuse'>#playthings4roughuse</a>.</p>
<p>Please enter a nickname (and hit enter). If nothing appears, either this page is temporarily broken or the nickname doesn't have a profile!</p><form id='name'><input id='input' name='name' type='text' onkeypress='{if (event.keyCode==13)showProfile(input.value);}' />";
$FailString="<p>Either you didn't finish typing yet or that nick doesn't have a profile.</p>";

// If we have a profile to get, begin to get it.
if ($_GET['name'] !=null)
{

// Set the profile name and make it lowercase.

$profile = $_GET['name'];
$name = strtolower($profile);

// Actually get the data.

$locdata = mysql_query('SELECT `p_location` FROM `users` WHERE `p_nick`="' . $name . '"');
$agedata = mysql_query('SELECT `p_age` FROM `users` WHERE `p_nick`="' . $name . '"');
$genderdata = mysql_query('SELECT `p_gender` FROM `users` WHERE `p_nick`="' . $name . '"');
$descdata = mysql_query('SELECT `p_description` FROM `users` WHERE `p_nick`="' . $name . '"');
$kinkdata = mysql_query('SELECT `p_kinks` FROM `users` WHERE `p_nick`="' . $name . '"');
$limdata = mysql_query('SELECT `p_limits` FROM `users` WHERE `p_nick`="' . $name . '"');
$posdata = mysql_query('SELECT `p_position` FROM `users` WHERE `p_nick`="' . $name . '"');
$oriendata = mysql_query('SELECT `p_orientation` FROM `users` WHERE `p_nick`="' . $name . '"');
$webdata = mysql_query('SELECT `p_url` FROM `users` WHERE `p_nick`="' . $name . '"');

// Make it human-readable for output.

$location = mysql_fetch_row($locdata);
$age = mysql_fetch_row($agedata);
$gender = mysql_fetch_row($genderdata);
$description = mysql_fetch_row($descdata);
$kinks = mysql_fetch_row($kinkdata);
$limits = mysql_fetch_row($limdata);
$position = mysql_fetch_row($posdata);
$orientation = mysql_fetch_row($oriendata);
$web = mysql_fetch_row($webdata);

// Draw and display the page.

$DisplayString.="<table>";
$DisplayString.="<br /><h2>" . $name . " <br /><br />";
$DisplayString.="<tr><td><strong>Location:</strong> " . $location[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Gender:</strong> " . $gender[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Age:</strong> " . $age[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Description:</strong> " . $description[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Kinks:</strong> " . $kinks[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Limits:</strong> " . $limits[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Orientation:</strong> " . $orientation[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Position:</strong> " . $position[0] . "</td></tr>";
$DisplayString.="<tr><td><strong>Web Profile:</strong> <a href='" . $web[0] . "' target='_blank'>Here unless no entry.</a> Note that not everyone sets this, so mouseover before you click. :p</td></tr>";
$DisplayString.="</table>";
echo $PreString;
echo $DisplayString;
  }
else
  {
echo $PreString;
echo $PostString;
  }
?>
Further note that this example uses two includes - those are just to open the connection to the db. If anyone needs that code, I can supply it, but it's pretty basic stuff!

You couldn't possibly use this as-is, either - largely because it relies on some javascript I wrote. I'm not including that because it's not necessary to the example.

I plan on doing something particularly interesting with this soon. If it works, I'll be sure to give you plenty of credit for giving me a fantastic starting point, tomekk. :)

One thing I do plan on doing is rewriting the "key" section of this script ... I've gotten a little better with tcl now, and one problem I run into time and time again "in the field" using this is that people forget their keys. User-set password time!
Post Reply