login and user system for a bot

By PuNkTuReD on Dec 31, 2008

ABOUT THIS SCRIPT
example: ~&@%+ ( q a o h v ) Owner Admin Op Helper Voice
It recognises a user by Nick and Address.
This bot has 7 levels of access and works best if it has owner level access to the channel.
Upon joining a channel a user has access on,
the bot will approve certain access to the bot and the channel.
Channel Owner = +qo
Channel Admin = +ao
Channel Op gets +ov
Channel Helper = +hv
Channel Voice = +v
( Bot Masters and regulars do not get any modes set on them when joining a channel )
If a user is logged in and
parts the channel the user has access on, changes nicks, or quits,
the bot will log them out automatically.

LEVELS OF ACCESS

  1. Bot Master [ Bot master is added by typing /botmaster nick password channel
    The nick is used as the username for login, The nick must be in the channel at the time, and they can only login when in that channel. ]
    The following user levels may only be added by Bot Masters:
  2. Channel Owner
  3. Channel Admin
  4. Channel Op
  5. Channel Helper
  6. Channel Voice
    The following user levels may only be added by Channels Owners:
  7. Channel Regular [ People who use the !request command ]
  8. Non Bot Users [ Public Users ]

COMMANDS [ Login commands may be used in channel or query, all other commands can only be accessed after login. ]
-Bot Master Commands
!adduser channel nick level username password
!deluser channel nick
-Channel Owner Commands
!request list/total
!request approve nick
-Channel Admin Commands
-Channel Op Commands
-Channel Helper Commands
-Channel Voice Commands
-Channel Regular Commands ( All other users with higher access can use these commands as well. )
!login username password channel
!logout channel
-Public User Commands
!request username password ( This requests "Channel Regular" access to the bot. )

ADDING TO THE SCRIPT
When adding to the script you can use
.msg %targ
so your commands can be used in channel or query

/*
Login and User System
By PuNkTuReD

ABOUT THIS SCRIPT
example: ~&@%+ ( q a o h v ) Owner Admin Op Helper Voice
It recognises a user by Nick and Address.
This bot has 7 levels of access and works best if it has owner level access to the channel.
Upon joining a channel a user has access on, 
the bot will approve certain access to the bot and the channel.
Channel Owner = +qo
Channel Admin = +ao
Channel Op gets +ov
Channel Helper = +hv
Channel Voice = +v 
( Bot Masters and regulars do not get any modes set on them when joining a channel )
If a user is logged in and 
parts the channel the user has access on, changes nicks, or quits, 
the bot will log them out automatically.

LEVELS OF ACCESS
1. Bot Master [ Bot master is added by typing /botmaster nick password channel
The nick is used as the username for login, The nick must be in the channel at the time, and they can only login when in that channel. ]
The following user levels may only be added by Bot Masters:
2. Channel Owner
The following user levels may only be added by Channel Owners:
3. Channel Admin
4. Channel Op
5. Channel Helper
6. Channel Voice
The following user levels may only be added by Channels Owners:
7. Channel Regular [ People who use the !request command ]
8. Non Bot Users [ Public Users ]

COMMANDS [ Login commands may be used in channel or query, all other commands can only be accessed after login. ]
-Bot Master Commands 
!adduser channel nick level username password
!deluser channel nick
-Channel Owner Commands
!request list/total
!request approve nick
-Channel Admin Commands
-Channel Op Commands
-Channel Helper Commands
-Channel Voice Commands
-Channel Regular Commands ( All other users with higher access can use these commands as well. )
!login username password channel
!logout channel
-Public User Commands
!request username password ( This requests "Channel Regular" access to the bot. )

ADDING TO THE SCRIPT
When adding to the script you can use 
.msg %targ 
so your commands can be used in channel or query 

*/
on *:join:#: {
  if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == owner) { 
    mode $chan +qo $nick $nick $nick 
  }
  if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == admin) { 
    mode $chan +ao $nick $nick $nick 
  }
  if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == op) { 
    mode $chan +ov $nick $nick 
  }
  if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == helper) { 
    mode $chan +hv $nick $nick 
  }
  if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == voice) { 
    mode $chan +v $nick 
  }
}
on *:part:#: {
  if ($read($+($chan,loggedin.txt), w, $nick $+ *) == $nick) { 
    write -ds $+ $nick loggedin.txt 
    .notice $nick $+(<,$nick,>) Logged out. 
  }
}
on 1:quit: {
  var %com = $comchan($nick,0)
  while (%com) {
    if ($read($+($chan(%com),loggedin.txt), w, $nick $+ *) == $nick) { 
      write -ds $+ $nick $+($chan(%com),loggedin.txt) 
      dec %com 
    } 
    else { 
      dec %com 
    } 
  }
}
on *:nick: {
  var %com = $comchan($nick,0)
  while (%com) {
    if ($read($+($chan(%com),loggedin.txt), w, $nick $+ *) == $nick) { 
      write -ds $+ $nick $+($chan(%com),loggedin.txt) 
      .notice $newnick $+(<,$nick,>) Logged out. 
      dec %com 
    }
    else { 
      dec %com 
    } 
  }
}
on *:text:*:*: {
  if ($target == $chan) { var %targ = $target }
  if ($target == $me) { var %targ = $nick } 
  ;
  ; Login Procedure
  if (!login == $strip($1)) {
    if ($address($nick,2) != $gettok($readini(login.ini,users,$nick),1,32)) { 
      .msg %targ $+(<,$nick,>) You do not have user access to this bot. You can request an account by typing !request username password 
      halt 
    }
    if ($address($nick,2) == $gettok($readini(users.ini,botmaster,$nick),2,32)) {  
      if (!$3) { 
        .msg %targ Incorrect login procedure: Please proceed by typing !login username password  
      }
      if ($3) { 
        if ($2 == $gettok($readini(login.ini,users,$nick),2,32)) {
          if ($3 == $gettok($readini(login.ini,users,$nick),3,32)) {
            if ($read(loggedin.txt, w, $nick $+ *) == $nick) { 
              .msg %targ $+(<,$nick,>) You are already Logged in. 
            }
            else { 
              .msg %targ $+(<,$nick,>) Logged in. 
              write loggedin.txt $nick 
            }
          }
          elseif ($3 != $gettok($readini(login.ini,users,$nick),3,32)) { 
            .msg %targ Your password did not match. 
          }
        }
        elseif ($2 != $gettok($readini(login.ini,users,$nick),2,32)) { 
          .msg %targ Your username did not match. 
        }
      }
    }
    else { 
      if (!$4) { 
        .msg %targ Incorrect login procedure: Please proceed by typing !login username password channel 
      }
      if ($4) { 
        if ($2 == $gettok($readini(login.ini,users,$nick),2,32)) {
          if ($3 == $gettok($readini(login.ini,users,$nick),3,32)) {
            if ($read(loggedin.txt, w, $nick $+ *) == $nick) { 
              .msg %targ $+(<,$nick,>) You are already Logged in. 
            }
            else {
              .msg %targ $+(<,$nick,>) Logged in. 
              write loggedin.txt $nick 
            }
          }
          elseif ($3 != $gettok($readini(login.ini,users,$nick),3,32)) { 
            .msg %targ Your password did not match. 
          }
        }
        elseif ($2 != $gettok($readini(login.ini,users,$nick),2,32)) { 
          .msg %targ Your username did not match.
        }
      }
    }
  }
  ;
  ; Logout Procedure
  if (!logout == $strip($1)) {
    if ($read(loggedin.txt, w, $nick $+ *) == $nick) { 
      if (!$2) {
        .msg %targ Please specify a channel to log out of. 
      }
      else { 
        write -ds $+ $nick $+($2,loggedin.txt) 
        .msg %targ $+(<,$nick,>) Logged out. 
      }
    }
    else { 
      .msg %targ You are either "not logged in" or did not specify a channel to log out of. 
    }
  }
  ;
  ; Request user access Procedure ( These users get recognised as Regular Users )
  if (!request == $strip($1)) { 
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Owner) {
      if (list == $strip($2)) { 
        if ($lines(requests.txt) == 0) { 
          .msg %targ There are no requests pending. 
        }
        else {
          var %rt = $lines(requests.txt)
          while (%rt) { 
            .msg %targ %rt $+ : $read(requests.txt, %rt)  
            dec %rt
          }
        }
      }
      if (total == $strip($2)) { 
        .msg %targ There are a total of $lines(requests.txt) requests. 
      }
      if (approve == $strip($2)) { 
        if ($lines(requests.txt) == 0) { 
          .msg %targ There are no requests pending. 
        }
        else { 
          writeini login.ini users $gettok($read(requests.txt,2,$3),1,32) $gettok($read(requests.txt,2,$3),2,32) $gettok($read(requests.txt,2,$3),3,32) $gettok($read(requests.txt,2,$3),4,32) 
          write -ds $+ $3 $+ * requests.txt
          if ($3 ison $chan) { 
            .notice $3 You now have "Channel Regular" level access to me, login by typing: !login $gettok($readini(login.ini,users,$nick),2,32) $gettok($readini(login.ini,users,$nick),3,32)
            .notice $nick Added $3 with "Channel Regular" level access.
          }
          else { 
            haltdef 
          }
        }
      }
    } 
    else { 
      if (!$3) { 
        .msg %targ Request Regular User Access: !request username password 
      }
      else { 
        write requests.txt $nick $address($nick,2) $2 $3 
        .msg %targ Your request has been sent. 
      }
    }
  } 
  ;
  ; Commands for logged in users
  if ($read(loggedin.txt, w, $nick $+ *) == $nick) {
    ;
    ; Bot Master Commands
    if ($address($nick,2) == $gettok($readini(users.ini,botmaster,$nick),2,32)) {
      if ($strip($1) == !adduser) {
        if (!$6) { 
          .msg %targ Incorrect Syntax. Please Type: !adduser #channel nick level username password 
          .msg %targ level can be any of the following: owner - admin - op - helper - voice 
        }
        else { 
          writeini users.ini $2 $3 $address($3,2) $4 
          writeini login.ini users $3 $5 $6 
          .notice $3 You now have $+(",$4,") level access to me, login by typing: !login $5 $6 
          .notice $nick Added $3 with $+(",$4,") level access. 
        }
      }
      if ($strip($1) == !deluser) {
        if (!$3) || (!$2) { 
          .msg %targ Incorrect Syntax. Please Type: !deluser #channel nick 
        }
        else { 
          remini users.ini $2 $3 
          remini login.ini users $3 
          .notice $nick $3 has been removed from my database. 
        }
      }
      ;
      ; Add Bot Master Commands Here

    }
    ;
    ; Channel Owner Commands
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Owner) {
      ;
      ; Add Channel Owner Commands Here

    }
    ;
    ; Channel Admin Commands
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Admin) {
      ;
      ; Add Channel Admin Commands Here

    }
    ;
    ; Channel Op Commands
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Op) {
      ;
      ; Add Channel Op Commands Here

    }
    ;
    ; Channel Helper Commands
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Helper) {
      ;
      ; Add Channel Helper Commands Here

    }
    ;
    ; Channel Voice Commands
    if ($address($nick,2) == $gettok($readini(users.ini,$chan,$nick),1,32)) && ($gettok($readini(users.ini,$chan,$nick),2,32) == Voice) {
      ;
      ; Add Channel Voice Commands Here

    }
    ;
    ; Add Regular User Commands Here ( All other users with higher access may use these commands too. )

  } 
  ;
  ; Add Other Public User Commands Here ( All other users with higher access may use these commands too. )

}
alias botmaster { 
  writeini users.ini botmaster $1 $1 $address($1,2) 
  writeini login.ini users $1 $address($1,2) $1 $2 
  .notice $1 Username: $1 Password: $2 
}

Comments

Sign in to comment.
paxiz   -  Jun 30, 2010

Im sorry to write again :) but now I have managed to become the botmaster :)

but the users I create is not able to login .. it says that the user is not a user on this bot. but if he likes, he can request by !request username password.. Then the request comes in my ini file. But if I create the user, he still cant login :(

squigradio  -  Nov 17, 2013

crap this is happening to me too

Sign in to comment

paxiz   -  Jun 30, 2010

I cant get the script to work :( when I type /botmaster nick password channel, it gives me an error, saying BOTMASTER Unknown command.. What to do ? is it something with the .ini file ?

 Respond  
PuNkTuReD   -  Apr 02, 2009

nope, is you have someone as Helper
and you want them to be Op
just set them as Op and itll over write their previous status

 Respond  
94killerz   -  Apr 02, 2009

No command to change level?

 Respond  
Aucun50   -  Jan 01, 2009

Thanks, update works good.

 Respond  
PuNkTuReD   -  Jan 01, 2009

cheers man
edited to include Aucun50's suggestion

if you dont include a username or password it will echo an error message
if you do include them it will notice the nick you spefified

squigradio  -  Nov 16, 2013

I'm horrendously bad at scripting. I was hoping to just copy/paste my standard "on 1:TEXT:" down in the "Add Channel Op Commands" section but ON is not being recognized as available. Can you give an example of what I would code in this section for if somebody types "!ban name reason" and I can hopefully model after that for future command additions?

Thanks!

Sign in to comment

Aucun50   -  Jan 01, 2009

When you type /owner Nick Username Password maybe it could msg back if it worked or if you type something wrong.

The script it's self works good, great job btw.

squigradio  -  Nov 16, 2013

I'm horrendously bad at scripting. I was hoping to just copy/paste my standard "on 1:TEXT:" down in the "Add Channel Op Commands" section but ON is not being recognized as available. Can you give an example of what I would code in this section for if somebody types "!ban name reason" and I can hopefully model after that for future command additions?

Thanks!

Sign in to comment

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.