login and user system for a bot

Paste Your small code(s) here, ex. small aliases, identifiers

login and user system for a bot

Postby PuNkTuReD » Sun Jan 04, 2009 9:13 am

Login and User System
By PuNkTuReD

ABOUT THIS SCRIPT
this is made on anope style servers
example: ~&@%+ ( q a o h v ) Owner Admin Op Helper Voice
It recognises a user by Nick and Address.
This bot has 8 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 ( The nick is used as the username for login ( The nick must be in the channel at the time )))
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 ( All commands may be used in channel or query, all 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
!logout
-Public User Commands
!request username password ( This requests "Channel Regular" Access )

ADDING TO THE SCRIPT
When adding to the script you can use
.msg %targ
so your commands can be used in channel or query
Code: Select all
/*
Login and User System
By PuNkTuReD

ABOUT THIS SCRIPT
this is made on anope style servers
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

*/
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 $newnick $+(<,$nick,>) Logged out. }
}
on 1:quit: {
  var %com = $comchan(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(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($+($4,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 }
    else {
      if (!$2) || (!$3) || (!$4) { .msg %targ Incorrect login procedure: Please proceed by typing !login username password channel }
      if ($4) {
        if ($2 == $gettok($readini($+($4,login.ini),users,$nick),2,32)) {
          if ($3 == $gettok($readini($+($4,login.ini),users,$nick),3,32)) {
            if ($read($+($4,loggedin.txt), w, $nick $+ *) == $nick) { .msg %targ $+(<,$nick,>) You are already Logged in. }
            else { .msg %targ $+(<,$nick,>) Logged in. | write $+($4,loggedin.txt) $nick }
          }
          elseif ($3 != $gettok($readini($+($4,login.ini),users,$nick),3,32)) { .msg %targ Your password did not match. }
        }
        elseif ($2 != $gettok($readini($+($4,login.ini),users,$nick),2,32)) { .msg %targ Your username did not match. }
      }
    }
  }
  ;
  ; Logout Procedure
  if (!logout == $strip($1)) {
    if ($read($+($2,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($+($chan,users.ini),$chan,$nick),1,32)) && ($gettok($readini($+($chan,users.ini),$chan,$nick),2,32) == Owner) {
      if (list == $strip($2)) {
        if ($lines($+($chan,requests.txt)) == 0) { .msg %targ There are no requests pending. }
        else {
          var %rt = $lines($+($chan,requests.txt))
          while (%rt) { .msg %targ %rt $+ : $read($+($chan,requests.txt), %rt) | dec %rt }
        }
      }
      if (total == $strip($2)) { .msg %targ There are a total of $lines($+($chan,requests.txt)) requests. }
      if (approve == $strip($2)) {
        if ($lines($+($chan,requests.txt)) == 0) { .msg %targ There are no requests pending. }
        else {
          writeini $+($chan,login.ini) users $gettok($read($+($chan,requests.txt),2,$3),1,32) $gettok($read($+($chan,requests.txt),2,$3),2,32) $gettok($read($+($chan,requests.txt),2,$3),3,32) $gettok($read($+($chan,requests.txt),2,$3),4,32)
          write -ds $+ $3 $+ * $+($chan,requests.txt)
          if ($3 ison $chan) {
            .notice $3 You now have "Channel Regular" level access to me, login by typing: !login $gettok($readini($+($chan,login.ini),users,$nick),2,32) $gettok($readini($+($chan,login.ini),users,$nick),3,32)
            .notice $nick Added $3 with "Channel Regular" level access.
          }
          else { haltdef }
        }
      }
    }
    else {
      if (!$2) { .msg %targ Request Regular User Access: !request username password }
      else { write $+($chan,requests.txt) $nick $address($nick,2) $2 $3 | .msg %targ Your request has been sent. }
    }
  }
  ;
  ; Commands for logged in users
  if ($read($+($chan,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 (!$3) || (!$2) { .msg %targ Incorrect Syntax. Please Type: !adduser channel nick level username password | .msg %targ Where level may be: admin - op - helper - voice }
        else { writeini $+($chan,users.ini) $2 $3 $address($3,2) $4 | writeini $+($2,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 $+($chan,users.ini) $2 $3 | remini $+($2,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($+($chan,users.ini),$chan,$nick),1,32)) && ($gettok($readini($+($chan,users.ini),$chan,$nick),2,32) == Owner) {
      ;
      ; Add Channel Owner Commands Here


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


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


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


    }
    ;
    ; Channel Voice Commands
    if ($address($nick,2) == $gettok($readini($+($chan,users.ini),$chan,$nick),1,32)) && ($gettok($readini($+($chan,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 $+($3,users.ini) botmaster $1 $1 $address($1,2) | writeini $+($3,login.ini) users $1 $address($1,2) $1 $2 | .notice $1 Username: $1 Password: $2 }
Last edited by PuNkTuReD on Tue Jan 06, 2009 6:34 am, edited 3 times in total.
PuNkTuReD
 

Re: login and user system for a bot

Postby capurro » Sun Jan 04, 2009 9:21 am

thanx :twisted:
capurro
 

Re: login and user system for a bot

Postby Cristian » Sun Jan 04, 2009 2:08 pm

nice work, a start kit for scripters.
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar


Return to Mirc Scripting Snippets

Who is online

Users browsing this forum: No registered users and 0 guests

cron