Simple Profiling Script

By LIQUID_NiTrO on Dec 22, 2004

This is a bulky but relatively simple script that uses hash tables to allow your users to register with you and then create a simple profile that includes their name, age, sex, and a place to put "personal information" or whatever you want to change that to. It has numerous things to insure that the data types for each field are correct (you can only enter numbers as your age, etc)
You will need to place this in its own script file if you already have an on Start or on Exit event.
Also includes the command /pinfo that will show you all of the specified nick's profile information, as well as their password and place it in a minimized @ window.
Note: When you want a space in the personal info field, use _'s. They will be evaluated into spaces later.
Commands: /ctcp YOURNICK register {password} registers account
/ctcp YOURNICK login {password} logs you in
!profile {set|nick} {name} [age] [sex] [info] sets your profile info or looks up profile info for another user.

on *:START: {
  hload Accounts Accounts.dat
  hload Info Info.dat
  hmake Logins 100
}
on *:EXIT: {
  hsave -o Accounts Accounts.dat
  hfree Accounts
  hsave -o Info Info.dat
  hfree Info
}
ctcp *:LOGIN: {
  if ( !$2 ) {
    ctcpreply $nick LOGIN Failed
    notice $nick Syntax: /ctcp $me LOGIN <password>
    halt
  }
  if ( $2 != $hget(Accounts,$nick) ) {
    ctcpreply $nick LOGIN Failed
    notice $nick You do not have an account, or you put an invalid password
    halt
  }
  hadd Logins $nick True
  ctcpreply $nick LOGIN Accepted
  notice $nick You are now logged in.
}
ctcp *:register: {
  if ( $hget(Accounts,$nick) != $null ) {
    notice $nick You are already registered!
    halt
  }
  if ( $hget(Accounts,Exists) == $null ) {
    hmake Accounts 50
    hmake Info 100
    hmake Logins 20
    hadd Accounts Exists True
    hadd Logins $nick True
  }
  if ( !$2 ) {
    notice $nick Syntax: REGISTER <password>
    halt
  }
  if ( $2 !isalnum ) {
    notice $nick Your password can only contain alphanumeric keys
    halt
  }
  hadd Accounts $nick $2
  msg $chan Account Created!
  notice $nick Your password is $2
}
on *:TEXT:!profile*:#happy: {
  if ( !$2 ) {
    msg $chan Syntax: !profile <set|nick> <name|nick> [age] [sex] [info]
    halt
  }
  if ( $2 == set ) {
    if ( $hget(Logins,$nick) != True ) {
      msg $chan You are not logged in!
      halt
    }
    if ( !$3 ) {
      msg $chan Syntax: !profile <set|nick> <name> [age] [sex] [info]
      halt
    }
    if ( $3 !isalpha ) {
      msg $chan Your name entry can contain only alphabetical keys!
      halt
    }
    if ( $4 !isnum ) {
      msg $chan Your age entry can contain only numeric keys!
      halt
    }
    if ( $5 != m ) && ( $5 != f ) {
      msg $chan Your sex entry must be either M or F!
      halt
    }
    if ( $7 != $null ) {
      msg $chan Your personal interests field cannot have spaces; use _'s instead
      halt
    }
    hadd Info $nick $+ _ $+ name $3
    hadd Info $nick $+ _ $+ age $4
    hadd Info $nick $+ _ $+ sex $upper($5)
    hadd Info $nick $+ _ $+ nfo $6
    msg $chan Successfully updated profile!
    halt
  }
  else {
    if ( !$hget(Info,$2 $+ _ $+ name) ) {
      msg $chan $2 is not registered or has not entered info for his/her profile!
      halt
    }
    msg $chan Info for $2 $+ : NAME= $+ $hget(Info,$2 $+ _ $+ name) AGE= $+ $hget(Info,$2 $+ _ $+ age) SEX= $+ $hget(Info,$2 $+ _ $+ sex) INFO: $replace($hget(Info,$2 $+ _ $+ nfo),$chr(95),$chr(32))
  }
}
alias pinfo {
  if ( !$1 ) {
    echo $colour(info) -a * SYNTAX: /info <nick>
    halt
  }
  if ( !$hget(Accounts,$1) ) {
    echo $colour(info) -a * $1 No Such Account
    halt
  }
  var %w = @Info: $+ $1
  window -nd %w
  aline %w $1 PASSWORD: $hget(Accounts,$1)
  aline %w $1 NAME: $hget(Info,$1 $+ _ $+ name)
  aline %w $1 AGE: $hget(Info,$1 $+ _ $+ age)
  aline %w $1 SEX: $hget(Info,$1 $+ _ $+ sex)
  aline %w -
  aline %w $1 Personal Info: $hget(Info,$1 $+ _ $+ nfo)
}

Comments

Sign in to comment.
RusselB   -  Mar 10, 2008

The ON START event is missing /hmake commands for the two tables that are called for in the /hload commands. From the help file [/quote]Note: /hload does not create the table, it must already have been created by /hmake.[quote]

 Respond  
bourneident   -  Feb 25, 2008

every time i restart my bot it says * /hload: no such table \'Accounts\' (line 2, profile.mrc) the file is there and the data still saved in it any suggestions

 Respond  
DarthReven   -  Dec 28, 2004

what Yonix was talking about was the /hfree command

 Respond  
LIQUID_NiTrO   -  Dec 28, 2004

And btw, there are actually 3 hash tables (Accounts, Info, and Logins) but there is no reason to have the Logins hash table save on exit; it would cause errors.

 Respond  
LIQUID_NiTrO   -  Dec 28, 2004

huh? I did remake them on start and save them on exit...what are you talking about darthreven. And yoinx, yeah, I\'ll remake it to have the register command in CTCP; wasn\'t thinking at the time. And I know I could do it with one hash table, I just get confused and it doesn\'t really slow anything down or anything having 2 so yeah...

 Respond  
DarthReven   -  Dec 26, 2004

technically when you exit all Hash tables that are running are deleted thats why you remake them on Start

 Respond  
Yoinx   -  Dec 26, 2004

lol, i didnt even notice that. You could use one with like $($+($nick,login)) $($+($nick,account)) etc. also, when using hash tables. on exit you always want to free them.

 Respond  
DarthReven   -  Dec 26, 2004

Good script but i don\'t think you need 2 hash tables considering that one hash table can carry a welth of information in a small space

 Respond  
Yoinx   -  Dec 26, 2004

You should have the register command in ctcp as well. instead of the channel, not someone will login to anything major.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.