Advertisement
Guest User

Untitled

a guest
Dec 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LOL Code 37.15 KB | None | 0 0
  1. ###############################################################################
  2. ## This FILE is part OF the Wolfpack module system
  3. ## Copyright (C) 1998-2003  Tothwolf <tothwolf@concentric.net>
  4. ## AND is distributed according to the GNU general public license.
  5. ## For full details, read the top OF wolfpack.tcl or the FILE called
  6. ## COPYING that was distributed WITH this code.
  7. ##
  8. ## $Id: pubcmds.tcl,v 1.14 2003/02/12 21:27:17 tothwolf Exp $
  9. ##
  10.  
  11. # name: pubcmds
  12. # version: 1.6.0.0
  13. # config: pubcmds.conf
  14. # description: Provides secure public user AND channel commands.
  15. # requires: authCheck commandChar putList putnot splitList findUser \
  16. #   getLastOn isNumber
  17.  
  18. namespace eval pubcmds {
  19.  
  20.   ##
  21.   ## Ops or voices a user: pub
  22.   ##
  23.   ## Args:    nick, user@host, handle, channel, arg
  24.   ## Returns: 1 if the user is auth'd
  25.   ##          0 otherwise
  26.   ##
  27.   proc pub:UP {nick uhost hand chan arg} {
  28.     if {[authCheck pub UP $nick $uhost $hand $chan]} then {
  29.       if {[botisop $chan]} then {
  30.         if {[matchattr $hand o|o $chan]} then {
  31.           if {![isop $nick $chan]} then {
  32.             pushmode $chan +o $nick
  33.             putnot $nick "You have been been op'd on $chan."
  34.           } else {
  35.             putnot $nick "You already have op on $chan."
  36.           }
  37.         } elseif {[matchattr $hand v|v $chan]} then {
  38.           if {![isvoice $nick $chan]} then {
  39.             pushmode $chan +v $nick
  40.             putnot $nick "You have been voiced on $chan."
  41.           } else {
  42.             putnot $nick "You already have voice on $chan."
  43.           }
  44.         }
  45.       } else {
  46.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  47.       }
  48.       return 1
  49.     }
  50.     return 0
  51.   }
  52.  
  53.   ##
  54.   ## Deops or devoices a user: pub
  55.   ##
  56.   ## Args:    nick, user@host, handle, channel, arg
  57.   ## Returns: 1 if the user is auth'd
  58.   ##          0 otherwise
  59.   ##
  60.   proc pub:down {nick uhost hand chan arg} {
  61.     if {[authCheck pub down $nick $uhost $hand $chan]} then {
  62.       if {[botisop $chan]} then {
  63.         if {[matchattr $hand o|o $chan]} then {
  64.           if {[isop $nick $chan]} then {
  65.             pushmode $chan -o $nick
  66.             putnot $nick "You have been deop'd on $chan."
  67.           } else {
  68.             putnot $nick "You do not have op on $chan."
  69.           }
  70.         } elseif {[matchattr $hand v|v $chan]} then {
  71.           if {[isvoice $nick $chan]} then {
  72.             pushmode $chan -v $nick
  73.             putnot $nick "You have been devoiced on $chan."
  74.           } else {
  75.             putnot $nick "You do not have voice on $chan."
  76.           }
  77.         }
  78.       } else {
  79.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  80.       }
  81.       return 1
  82.     }
  83.     return 0
  84.   }
  85.  
  86.   ##
  87.   ## Ops the given nick: pub
  88.   ##
  89.   ## Args:    nick, user@host, handle, channel, arg
  90.   ## Returns: 1 if the user is auth'd
  91.   ##          0 otherwise
  92.   ##
  93.   proc pub:op {nick uhost hand chan arg} {
  94.     if {[authCheck pub op $nick $uhost $hand $chan]} then {
  95.       set who [lindex [split [string trimright $arg]] 0]
  96.       if {![string compare "" $who]} then {
  97.         putnot $nick "Usage: [commandChar pub]op <nick>"
  98.       } elseif {[botisop $chan]} then {
  99.         if {![isbotnick $who]} then {
  100.           if {[onchan $who $chan]} then {
  101.             if {![isop $who $chan]} then {
  102.               pushmode $chan +o $who
  103.               putnot $nick "Gave op to $who on $chan."
  104.             } else {
  105.               putnot $nick "$who is already op'd on $chan."
  106.             }
  107.           } else {
  108.             putnot $nick "$who is not on $chan."
  109.           }
  110.         } else {
  111.           putnot $nick "I can't op myself!"
  112.         }
  113.       } else {
  114.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  115.       }
  116.       return 1
  117.     }
  118.     return 0
  119.   }
  120.  
  121.   ##
  122.   ## Deops the given nick: pub
  123.   ##
  124.   ## Args:    nick, user@host, handle, channel, arg
  125.   ## Returns: 1 if the user is auth'd
  126.   ##          0 otherwise
  127.   ##
  128.   proc pub:deop {nick uhost hand chan arg} {
  129.     if {[authCheck pub deop $nick $uhost $hand $chan]} then {
  130.       set who [lindex [split [string trimright $arg]] 0]
  131.       if {![string compare "" $who]} then {
  132.         putnot $nick "Usage: [commandChar pub]deop <nick>"
  133.       } elseif {[botisop $chan]} then {
  134.         if {![isbotnick $who]} then {
  135.           if {[onchan $who $chan]} then {
  136.             if {[isop $who $chan]} then {
  137.               if {(![matchattr [nick2hand $who $chan] m|m $chan]) || \
  138.                   (![string compare [string tolower $hand] \
  139.                      [string tolower [nick2hand $who $chan]]])} then {
  140.                 pushmode $chan -o $who
  141.                 putnot $nick "Took op from $who on $chan."
  142.               } else {
  143.                 putnot $nick "You can't deop a master."
  144.               }
  145.             } else {
  146.               putnot $nick "$who is not op'd on $chan."
  147.             }
  148.           } else {
  149.             putnot $nick "$who is not on $chan."
  150.           }
  151.         } else {
  152.           putnot $nick "I won't deop myself!"
  153.         }
  154.       } else {
  155.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  156.       }
  157.       return 1
  158.     }
  159.     return 0
  160.   }
  161.  
  162.   ##
  163.   ## Voices the given nick: pub
  164.   ##
  165.   ## Args:    nick, user@host, handle, channel, arg
  166.   ## Returns: 1 if the user is auth'd
  167.   ##          0 otherwise
  168.   ##
  169.   proc pub:voice {nick uhost hand chan arg} {
  170.     if {[authCheck pub voice $nick $uhost $hand $chan]} then {
  171.       set who [lindex [split [string trimright $arg]] 0]
  172.       if {![string compare "" $who]} then {
  173.         putnot $nick "Usage: [commandChar pub]voice <nick>"
  174.       } elseif {[botisop $chan]} then {
  175.         if {![isbotnick $who]} then {
  176.           if {[onchan $who $chan]} then {
  177.             if {![isvoice $who $chan]} then {
  178.               pushmode $chan +v $who
  179.               putnot $nick "Gave voice to $who on $chan."
  180.             } else {
  181.               putnot $nick "$who is already voiced on $chan."
  182.             }
  183.           } else {
  184.             putnot $nick "$who is not on $chan."
  185.           }
  186.         } else {
  187.           putnot $nick "I can't voice myself!"
  188.         }
  189.       } else {
  190.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  191.       }
  192.       return 1
  193.     }
  194.     return 0
  195.   }
  196.  
  197.   ##
  198.   ## Devoices the given nick: pub
  199.   ##
  200.   ## Args:    nick, user@host, handle, channel, arg
  201.   ## Returns: 1 if the user is auth'd
  202.   ##          0 otherwise
  203.   ##
  204.   proc pub:devoice {nick uhost hand chan arg} {
  205.     if {[authCheck pub devoice $nick $uhost $hand $chan]} then {
  206.       set who [lindex [split [string trimright $arg]] 0]
  207.       if {![string compare "" $who]} then {
  208.         putnot $nick "Usage: [commandChar pub]devoice <nick>"
  209.       } elseif {[botisop $chan]} then {
  210.         if {![isbotnick $who]} then {
  211.           if {[onchan $who $chan]} then {
  212.             if {[isvoice $who $chan]} then {
  213.               pushmode $chan -v $who
  214.               putnot $nick "Took voice from $who on $chan."
  215.             } else {
  216.               putnot $nick "$who is not voiced on $chan."
  217.             }
  218.           } else {
  219.             putnot $nick "$who is not on $chan."
  220.           }
  221.         } else {
  222.           putnot $nick "I won't devoice myself!"
  223.         }
  224.       } else {
  225.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  226.       }
  227.       return 1
  228.     }
  229.     return 0
  230.   }
  231.  
  232.   ##
  233.   ## Bans the given nick or mask: pub
  234.   ##
  235.   ## Args:    nick, user@host, handle, channel, arg
  236.   ## Returns: 1 if the user is auth'd
  237.   ##          0 otherwise
  238.   ##
  239.   proc pub:ban {nick uhost hand chan arg} {
  240.     if {[authCheck pub ban $nick $uhost $hand $chan]} then {
  241.       set arg [split [string trimright $arg]]
  242.       set who [lindex $arg 0]
  243.       set reason [join [lrange $arg 1 end]]
  244.       if {![string compare "" $reason]} then {
  245.         set reason requested
  246.       }
  247.       set parts [scan $who "%\[^!\]!%\[^@\]@%s" bannick banuser banhost]
  248.       if {($parts != 1) && ($parts != 3)} then {
  249.         putnot $nick "Usage: [commandChar pub]ban <nick|mask> \[reason\]"
  250.       } elseif {[botisop $chan]} then {
  251.         if {$parts == 1} then {
  252.           if {[onchan $who $chan]} then {
  253.             if {[isbotnick $who]} then {
  254.               putnot $nick "I won't ban myself!"
  255.               return 1
  256.             } elseif {[matchattr [nick2hand $who $chan] m|m $chan]} then {
  257.               putnot $nick "I won't ban a master."
  258.               return 1
  259.             } elseif {[matchattr [nick2hand $who $chan] o|o $chan]} then {
  260.               putnot $nick "I won't ban an op."
  261.               return 1
  262.             } elseif {[matchattr [nick2hand $who $chan] b]} then {
  263.               putnot $nick "I won't ban another bot."
  264.               return 1
  265.             } else {
  266.               set mask *!*[string trimleft [maskhost [getchanhost $who $chan]] *!]
  267.             }
  268.           } else {
  269.             putnot $nick "Unable to ban $who: invalid nick/banmask."
  270.             return 1
  271.           }
  272.         } elseif {$parts == 3} then {
  273.           foreach badmask "\\* \\*.?? \\*.\\*.?? \\*.??? \\*.\\*.???" {
  274.             if {[string match $badmask $banhost]} then {
  275.               putnot $nick "Unable to ban $who: invalid banmask."
  276.               return 1
  277.             }
  278.           }
  279.           foreach nickname [chanlist $chan] {
  280.             if {[string match $who $nick![getchanhost $nick $chan]]} then {
  281.               if {[isbotnick $nickname]} then {
  282.                 putnot $nick "I won't ban myself!"
  283.                 return 1
  284.               } elseif {[matchattr [set hand2 [nick2hand $nickname $chan]] m|m $chan]} then {
  285.                 putnot $nick "I won't ban a master."
  286.                 return 1
  287.               } elseif {[matchattr $hand2 o|o $chan]} then {
  288.                 putnot $nick "I won't ban an op."
  289.                 return 1
  290.               } elseif {[matchattr $hand2 b]} then {
  291.                 putnot $nick "I won't ban another bot."
  292.                 return 1
  293.               }
  294.             }
  295.           }
  296.           set mask $who
  297.         }
  298.         if {![isban $mask $chan]} then {
  299.           if {[onchan $who $chan]} then {
  300.             if {[isop $who $chan]} then {
  301.               newchanban $chan $mask $hand $reason 0
  302.               putquick "MODE $chan -o+b $who $mask"
  303.               putnot $nick "Added ban $mask on $chan."
  304.             } else {
  305.               newchanban $chan $mask $hand $reason 0
  306.               putquick "MODE $chan +b $mask"
  307.               putnot $nick "Added ban $mask on $chan."
  308.             }
  309.           } else {
  310.             newchanban $chan $mask $hand $reason 0
  311.             putquick "MODE $chan +b $mask"
  312.             putnot $nick "Added ban $mask on $chan."
  313.           }
  314.         } else {
  315.           resetbans $chan
  316.           putnot $nick "$mask is already banned on $chan."
  317.         }
  318.       } else {
  319.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  320.       }
  321.       return 1
  322.     }
  323.     return 0
  324.   }
  325.  
  326.   ##
  327.   ## Unbans the given nick or mask: pub
  328.   ##
  329.   ## Args:    nick, user@host, handle, channel, arg
  330.   ## Returns: 1 if the user is auth'd
  331.   ##          0 otherwise
  332.   ##
  333.   proc pub:unban {nick uhost hand chan arg} {
  334.     if {[authCheck pub unban $nick $uhost $hand $chan]} then {
  335.       set who [lindex [split [string trimright $arg]] 0]
  336.       if {![string compare "" $who]} then {
  337.         putnot $nick "Usage: [commandChar pub]unban <nick|mask>"
  338.       } elseif {[botisop $chan]} then {
  339.         if {[onchan $who $chan]} then {
  340.           set mask [maskhost [getchanhost $who $chan]]
  341.         } else {
  342.           set mask $who
  343.         }
  344.         if {[ischanban $mask $chan]} then {
  345.           killchanban $chan $mask
  346.           pushmode $chan -b $mask
  347.           putnot $nick "Removed ban $mask from $chan."
  348.         } else {
  349.           putnot $nick "$mask is not banned on $chan."
  350.         }
  351.       } else {
  352.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  353.       }
  354.       return 1
  355.     }
  356.     return 0
  357.   }
  358.  
  359.   ##
  360.   ## Kicks the given nick: pub
  361.   ##
  362.   ## Args:    nick, user@host, handle, channel, arg
  363.   ## Returns: 1 if the user is auth'd
  364.   ##          0 otherwise
  365.   ##
  366.   proc pub:kick {nick uhost hand chan arg} {
  367.     if {[authCheck pub kick $nick $uhost $hand $chan]} then {
  368.       set arg [split [string trimright $arg]]
  369.       set who [lindex $arg 0]
  370.       set reason [join [lrange $arg 1 end]]
  371.       set OK 0
  372.       if {![string compare "" $who]} then {
  373.         putnot $nick "Usage: [commandChar pub]kick <nick> \[reason\]"
  374.       } elseif {[botisop $chan]} then {
  375.         if {[onchan $who $chan]} then {
  376.           if {![isbotnick $who]} then {
  377.             if {[matchattr $hand m|m $chan]} then {
  378.               set OK 1
  379.             }
  380.             set khand [nick2hand $who $chan]
  381.             if {($ok) || (![matchattr $khand m|m $chan])} then {
  382.               if {($ok) || (![matchattr $khand o|o $chan])} then {
  383.                 if {($ok) || (![matchattr $khand b])} then {
  384.                   if {![string compare "" $reason]} then {
  385.                     set reason requested
  386.                   }
  387.                   if {[isop $who $chan]} then {
  388.                     putquick "MODE $chan -o $who"
  389.                     putkick $chan $who $reason
  390.                     putnot $nick "Kicked $who from $chan."
  391.                   } else {
  392.                     putkick $chan $who $reason
  393.                     putnot $nick "Kicked $who from $chan."
  394.                   }
  395.                 } else {
  396.                   putnot $nick "I won't kick another bot."
  397.                 }
  398.               } else {
  399.                 putnot $nick "I won't kick an op."
  400.               }
  401.             } else {
  402.               putnot $nick "I won't kick a master."
  403.             }
  404.           } else {
  405.             putnot $nick "I won't kick myself!"
  406.           }
  407.         } else {
  408.           putnot $nick "$who is not on $chan."
  409.         }
  410.       } else {
  411.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  412.       }
  413.       return 1
  414.     }
  415.     return 0
  416.   }
  417.  
  418.   ##
  419.   ## Kickbans the given nick: pub
  420.   ##
  421.   ## Args:    nick, user@host, handle, channel, arg
  422.   ## Returns: 1 if the user is auth'd
  423.   ##          0 otherwise
  424.   ##
  425.   proc pub:kickban {nick uhost hand chan arg} {
  426.     if {[authCheck pub kickban $nick $uhost $hand $chan]} then {
  427.       set arg [split [string trimright $arg]]
  428.       set who [lindex $arg 0]
  429.       set reason [join [lrange $arg 1 end]]
  430.       if {![string compare "" $who]} then {
  431.         putnot $nick "Usage: [commandChar pub]kickban <nick> \[reason\]"
  432.       } elseif {[botisop $chan]} then {
  433.         if {[onchan $who $chan]} then {
  434.           if {![isbotnick $who]} then {
  435.             if {![matchattr [nick2hand $who $chan] m|m $chan]} then {
  436.               if {![matchattr [nick2hand $who $chan] o|o $chan]} then {
  437.                 if {![matchattr [nick2hand $who $chan b]]} then {
  438.                   set mask [maskhost [getchanhost $who $chan]]
  439.                   if {![isban $mask $chan]} then {
  440.                     if {![string compare "" $reason]} then {
  441.                       set reason requested
  442.                     }
  443.                     if {[isop $who $chan]} then {
  444.                       newchanban $chan $mask $hand $reason 0
  445.                       putquick "MODE $chan -o+b $who $mask"
  446.                       putkick $chan $who $reason
  447.                     } else {
  448.                       newchanban $chan $mask $hand $reason 0
  449.                       putquick "MODE $chan +b $mask"
  450.                       putkick $chan $who $reason
  451.                     }
  452.                     putnot $nick "Added ban $mask and kicked $who from $chan."
  453.                   } else {
  454.                     resetbans $chan
  455.                     putnot $nick "$who is already banned on $chan."
  456.                   }
  457.                 } else {
  458.                   putnot $nick "I won't kickban another bot."
  459.                 }
  460.               } else {
  461.                 putnot $nick "I won't kickban an op."
  462.               }
  463.             } else {
  464.               putnot $nick "I won't kickban a master."
  465.             }
  466.           } else {
  467.             putnot $nick "I won't kickban myself!"
  468.           }
  469.         } else {
  470.           putnot $nick "$who is not on $chan."
  471.         }
  472.       } else {
  473.         putnot $nick "I can't help you right now since I'm not an op on $chan."
  474.       }
  475.       return 1
  476.     }
  477.     return 0
  478.   }
  479.  
  480.   ##
  481.   ## Changes a mode ON the channel: pub
  482.   ##
  483.   ## Args:    nick, user@host, handle, channel, arg
  484.   ## Returns: 1 if the user is auth'd
  485.   ##          0 otherwise
  486.   ##
  487.   proc pub:mode {nick uhost hand chan arg} {
  488.     global botnick
  489.  
  490.     if {[authCheck pub mode $nick $uhost $hand $chan]} then {
  491.       set arg [split [string trimright $arg]]
  492.       set mode [lindex $arg 0]
  493.       set what [join [lrange $arg 1 end]]
  494.       if {![string compare "" $mode]} then {
  495.         putnot $nick "Usage: [commandChar pub]mode <+-mode(s)> \[arguments\]"
  496.       } else {
  497.         if {![matchattr $hand m|m $chan]} then {
  498.           if {![regexp ".*o.*" $mode]} then {
  499.             if {![regexp ".*v.*" $mode]} then {
  500.               if {![regexp ".*b.*" $mode]} then {
  501.                 if {![string compare "" $what]} then {
  502.                   putquick "MODE $chan $mode"
  503.                   putnot $nick "Set mode $mode on $chan."
  504.                 } else {
  505.                   if {![regexp .*[string tolower $botnick].* [string tolower $what]]} then {
  506.                     putquick "MODE $chan $mode $what"
  507.                     putnot $nick "Set mode $mode $what on $chan."
  508.                   } else {
  509.                     putnot $nick "I won't do modes against myself!"
  510.                   }
  511.                 }
  512.               } else {
  513.                 set reason "Only masters can ban or unban users with this command."
  514.               }
  515.             } else {
  516.               set reason "Only masters can voice or devoice users with this command."
  517.             }
  518.           } else {
  519.             set reason "Only masters can op or deop users with this command."
  520.           }
  521.         } else {
  522.           if {![string compare "" $what]} then {
  523.             putquick "MODE $chan $mode"
  524.           } else {
  525.             putquick "MODE $chan $mode $what"
  526.           }
  527.         }
  528.       }
  529.       return 1
  530.     }
  531.     return 0
  532.   }
  533.  
  534.   ##
  535.   ## Displays/changes the topic ON the channel: pub
  536.   ##
  537.   ## Args:    nick, user@host, handle, channel, arg
  538.   ## Returns: 1 if the user is auth'd
  539.   ##          0 otherwise
  540.   ##
  541.   proc pub:topic {nick uhost hand chan arg} {
  542.     if {[authCheck pub topic $nick $uhost $hand $chan]} then {
  543.       set topic [string trimright $arg]
  544.       if {![string compare "" $topic]} then {
  545.         set oldtopic [topic $chan]
  546.         if {[string compare "" $oldtopic]} then {
  547.           putnot $nick "Topic for $chan: $oldtopic"
  548.         } else {
  549.           putnot $nick "No topic is set for $chan."
  550.         }
  551.       } elseif {![string compare none $topic]} then {
  552.         putserv "TOPIC $chan :"
  553.        putnot $nick "Cleared topic ON $chan."
  554.      } else {
  555.        putserv "TOPIC $chan :$topic"
  556.        putnot $nick "Changed topic ON $chan to: $topic"
  557.      }
  558.      return 1
  559.    }
  560.    return 0
  561.  }
  562.  
  563.  ##
  564.  ## Shows a user's flags: pub
  565.  ##
  566.  ## Args:    nick, user@host, handle, channel, arg
  567.  ## Returns: 1 if the user is auth'd
  568.  ##          0 otherwise
  569.  ##
  570.  proc pub:access {nick uhost hand chan arg} {
  571.    if {[authCheck pub access $nick $uhost $hand $chan]} then {
  572.      set arg [split [string trimright $arg]]
  573.      set who [lindex $arg 0]
  574.      set chan2 [lindex $arg 1]
  575.      if {[string compare "" $chan2]} then {
  576.        set chan $chan2
  577.      }
  578.      if {[validchan $chan]} then {
  579.        if {![string compare "" $who]} then {
  580.          set user $hand
  581.        } elseif {[matchattr $hand m|m $chan]} then {
  582.          set user [findUser $who $chan]
  583.        } else {
  584.          putnot $nick "Only a master CAN specify another user."
  585.          return 1
  586.        }
  587.        if {[validuser $user]} then {
  588.          scan [chattr $user $chan] "%\[^|\]|%s" gflags cflags
  589.          if {![string compare "-" $gflags]} then {
  590.            set gflags none
  591.          }
  592.          if {![string compare "-" $cflags]} then {
  593.            set cflags none
  594.          }
  595.          putnot $nick "Global flags for $user: $gflags"
  596.          putnot $nick "Channel flags for $user ON $chan: $cflags"
  597.        } else {
  598.          putnot $nick "I don't know who $who is."
  599.        }
  600.      } else {
  601.        putnot $nick "$chan is NOT a valid channel."
  602.      }
  603.      return 1
  604.    }
  605.    return 0
  606.  }
  607.  
  608.  ##
  609.  ## Makes the bot cycle the channel: pub
  610.  ##
  611.  ## Args:    nick, user@host, handle, channel, arg
  612.  ## Returns: 1 if the user is auth'd
  613.  ##          0 otherwise
  614.  ##
  615.  proc pub:cycle {nick uhost hand chan arg} {
  616.    if {[authCheck pub cycle $nick $uhost $hand $chan]} then {
  617.      putquick "PART $chan"
  618.      putquick "JOIN $chan"
  619.      putnot $nick "Finished cycling $chan."
  620.      return 1
  621.    }
  622.    return 0
  623.  }
  624.  
  625.  ##
  626.  ## Adds a new user to the userfile: pub
  627.  ##
  628.  ## Args:    nick, user@host, handle, channel, arg
  629.  ## Returns: 1 if the user is auth'd
  630.  ##          0 otherwise
  631.  ##
  632.  proc pub:adduser {nick uhost hand chan arg} {
  633.    variable configData
  634.  
  635.    if {[authCheck pub adduser $nick $uhost $hand $chan]} then {
  636.      set arg [split [string trimright $arg]]
  637.      set who [lindex $arg 0]
  638.      set host [lindex $arg 1]
  639.      if {(![string compare "" $who]) || \
  640.          ((![onchan $who $chan]) && (![string compare "" $host]))} then {
  641.        putnot $nick "Usage: [commandChar pub]adduser <nick> \[host\] | <hand> <host>"
  642.      } elseif {[string length $who] <= $configData(handlen)} then {
  643.        if {![validuser $who]} then {
  644.          if {![string compare "" $host]} then {
  645.            if {[onchan $who $chan]} then {
  646.              set host [maskhost [getchanhost $who $chan]]
  647.              adduser $who $host
  648.              putnot $nick "Added user: $who WITH host: $host"
  649.            } else {
  650.              putnot $nick "$who is NOT ON $chan."
  651.            }
  652.          } else {
  653.            adduser $who $host
  654.            putnot $nick "Added user: $who WITH host: $host"
  655.          }
  656.        } else {
  657.          putnot $nick "I already know a $who."
  658.        }
  659.      } else {
  660.        putnot $nick "Handle must be no longer THAN $configData(handlen) characters."
  661.      }
  662.      return 1
  663.    }
  664.    return 0
  665.  }
  666.  
  667.  ##
  668.  ## Removes a user from the userfile: pub
  669.  ##
  670.  ## Args:    nick, user@host, handle, channel, arg
  671.  ## Returns: 1 if the user is auth'd
  672.  ##          0 otherwise
  673.  ##
  674.  proc pub:deluser {nick uhost hand chan arg} {
  675.    if {[authCheck pub deluser $nick $uhost $hand $chan]} then {
  676.      set who [lindex [split [string trimright $arg]] 0]
  677.      if {![string compare "" $who]} then {
  678.        putnot $nick "Usage: [commandChar pub]deluser <nick|hand>"
  679.      } else {
  680.        set user [findUser $who $chan]
  681.        if {[validuser $user]} then {
  682.          if {![matchattr $user m|m $chan]} then {
  683.            deluser $user
  684.            putnot $nick "Deleted user: $user"
  685.          } else {
  686.            putnot $nick "You CAN't delete a master."
  687.          }
  688.        } else {
  689.          putnot $nick "I don't know who $who is."
  690.        }
  691.      }
  692.      return 1
  693.    }
  694.    return 0
  695.  }
  696.  
  697.  ##
  698.  ## Adds a host for a user: pub
  699.  ##
  700.  ## Args:    nick, user@host, handle, channel, arg
  701.  ## Returns: 1 if the user is auth'd
  702.  ##          0 otherwise
  703.  ##
  704.  proc pub:addhost {nick uhost hand chan arg} {
  705.    if {[authCheck pub addhost $nick $uhost $hand $chan]} then {
  706.      set arg [split [string trimright $arg]]
  707.      set who [lindex $arg 0]
  708.      set host [lindex $arg 1]
  709.      if {(![string compare "" $who]) || (![string compare "" $host])} then {
  710.        putnot $nick "Usage: [commandChar pub]addhost <nick|hand> <hostmask>"
  711.      } else {
  712.        set user [findUser $who $chan]
  713.        if {[validuser $user]} then {
  714.          if {(![matchattr $user m|m $chan]) && \
  715.              ([string compare [string tolower $hand] [string tolower $user]])} then {
  716.            if {[lsearch -exact [string tolower [getuser $user HOSTS]] \
  717.                 [string tolower $host]] == -1} then {
  718.              setuser $user HOSTS $host
  719.              putnot $nick "Added $host to $user."
  720.            } else {
  721.              putnot $nick "$host is already a valid host for $user."
  722.            }
  723.          } else {
  724.            putnot $nick "You CAN't change hosts for masters."
  725.          }
  726.        } else {
  727.          putnot $nick "I don't know who $who is."
  728.        }
  729.      }
  730.      return 1
  731.    }
  732.    return 0
  733.  }
  734.  
  735.  ##
  736.  ## Removes a host for a user: pub
  737.  ##
  738.  ## Args:    nick, user@host, handle, channel, arg
  739.  ## Returns: 1 if the user is auth'd
  740.  ##          0 otherwise
  741.  ##
  742.  proc pub:delhost {nick uhost hand chan arg} {
  743.    if {[authCheck pub delhost $nick $uhost $hand $chan]} then {
  744.      set arg [split [string trimright $arg]]
  745.      set who [lindex $arg 0]
  746.      set host [lindex $arg 1]
  747.      if {(![string compare "" $who]) || (![string compare "" $host])} then {
  748.        putnot $nick "Usage: [commandChar pub]delhost <nick|hand> <hostmask>"
  749.      } else {
  750.        set user [findUser $who $chan]
  751.        if {[validuser $user]} then {
  752.          if {(![matchattr $user m|m $chan]) && \
  753.              ([string compare [string tolower $hand] [string tolower $user]])} then {
  754.            if {[lsearch -exact [getuser $user HOSTS] $host] != -1} then {
  755.              delhost $user $host
  756.              putnot $nick "Removed $host from $user."
  757.            } else {
  758.              putnot $nick "$host is NOT a valid host for $user."
  759.            }
  760.          } else {
  761.            putnot $nick "You CAN't change hosts for masters."
  762.          }
  763.        } else {
  764.          putnot $nick "I don't know who $who is."
  765.        }
  766.      }
  767.      return 1
  768.    }
  769.    return 0
  770.  }
  771.  
  772.  ##
  773.  ## Shows a user's whois info: pub
  774.  ##
  775.  ## Args:    nick, user@host, handle, channel, arg
  776.  ## Returns: 1 if the user is auth'd
  777.  ##          0 otherwise
  778.  ##
  779.  # FIXME: handle long HANDLEN handles
  780.  proc pub:whois {nick uhost hand chan arg} {
  781.    global whois-fields
  782.  
  783.    if {[authCheck pub whois $nick $uhost $hand $chan]} then {
  784.      set who [lindex [split [string trimright $arg]] 0]
  785.      if {![string compare "" $who]} then {
  786.        putnot $nick "Usage: [commandChar pub]whois <nick|hand>"
  787.      } else {
  788.        set user [findUser $who $chan]
  789.        if {[validuser $user]} then {
  790.          if {[passwdok $user ""]} then {
  791.            set pass no
  792.          } else {
  793.            set pass yes
  794.          }
  795.          set notes [llength [listnotes $user -]]
  796.          set flags [chattr $user]
  797.          set lasttmp [getLastOn $user ""]
  798.          set lastwhere [lindex $lasttmp 1]
  799.          if {![string compare "" $lastwhere]} then {
  800.            set laston [lindex $lasttmp 0]
  801.          } else {
  802.            set laston "[lindex $lasttmp 0] ($lastwhere)"
  803.          }
  804.          foreach channel [channels] {
  805.            set chanflags [lindex [split [chattr $user $channel] |] 1]
  806.            set chanlaston [getLastOn $user $channel]
  807.            if {[string compare "-" $chanflags]} then {
  808.              set chanlist($channel) "$chanflags $chanlaston"
  809.            }
  810.          }
  811.          set hosts [getuser $user HOSTS]
  812.          regsub -all -- " " $hosts ", " hosts
  813.          set xtrafields [string tolower ${whois-fields}]
  814.          foreach field [lsort [getuser $user XTRA]] {
  815.            if {[lsearch -exact $xtrafields [string tolower [lindex $field 0]]] != -1} then {
  816.              lappend xtradata $field
  817.            }
  818.          }
  819.          if {![matchattr $user b]} then {
  820.            set info [getuser $user INFO]
  821.          } else {
  822.            set botflags [getuser $user BOTFL]
  823.            foreach {botaddress botport1 botport2} [getuser $user BOTADDR] {break}
  824.          }
  825.          putnot $nick "HANDLE    PASS NOTES FLAGS           LAST"
  826.          putnot $nick "[format "%-9s %-4s %5s %-15s %s" $user $pass $notes $flags $laston]"
  827.          foreach {name data} [array get chanlist] {
  828.            foreach {flags laston} $data {break}
  829.            putnot $nick "[format "  %-17s %-15s %s" $name $flags $laston]"
  830.          }
  831.          if {([info exists hosts]) && ([string compare "" $hosts])} then {
  832.            putList putnot $nick [splitList $hosts 35 , ", "] "  HOSTS: " "         "
  833.          }
  834.          if {[info exists xtradata]} then {
  835.            foreach field $xtradata {
  836.              putnot $nick "  [lindex $field 0]:  [lrange $field 1 end]"
  837.            }
  838.          }
  839.          if {([info exists info]) && ([string compare "" $info])} then {
  840.            putnot $nick "  INFO:  $info"
  841.          }
  842.          if {([info exists botflags]) && ([string compare "" $botflags])} then {
  843.            putnot $nick "  BOT FLAGS:  $botflags"
  844.          }
  845.          if {([info exists botaddress]) && \
  846.              (([string compare "" $botaddress]) && \
  847.               ([string compare "" $botport1]) && \
  848.               ([string compare "" $botport2]))} then {
  849.            putnot $nick "  ADDRESS: $botaddress"
  850.            putnot $nick "     telnet: $botport1, relay: $botport2"
  851.          }
  852.        } else {
  853.          putnot $nick "I don't know who $who is."
  854.        }
  855.      }
  856.      return 1
  857.    }
  858.    return 0
  859.  }
  860.  
  861.  ##
  862.  ## Adds +o or +oa for the given user: pub
  863.  ##
  864.  ## Args:    nick, user@host, handle, channel, arg
  865.  ## Returns: 1 if the user is auth'd
  866.  ##          0 otherwise
  867.  ##
  868.  proc pub:addop {nick uhost hand chan arg} {
  869.    variable configData
  870.  
  871.    if {[authCheck pub addop $nick $uhost $hand $chan]} then {
  872.      set arg [split [string trimright $arg]]
  873.      set who [lindex $arg 0]
  874.      set chan2 [lindex $arg 1]
  875.      if {![string compare "" $who]} then {
  876.        putnot $nick "Usage: [commandChar pub]addop <nick|hand> \[chan\]"
  877.      } else {
  878.        set user [findUser $who $chan]
  879.        if {[string compare "" $chan2]} then {
  880.          if {[validchan $chan2]} then {
  881.            set where $chan2
  882.          } else {
  883.            putnot $nick "Invalid channel: $chan2"
  884.            return 1
  885.          }
  886.        } else {
  887.          set where $chan
  888.        }
  889.        if {[validuser $user]} then {
  890.          if {![matchattr $user |o $where]} then {
  891.            if {$configData(autoop)} then {
  892.              chattr $user |+oa $where
  893.            } else {
  894.              chattr $user |+o $where
  895.            }
  896.            putnot $nick "Added op for $user."
  897.          } else {
  898.            putnot $nick "$user already had op ON $where."
  899.          }
  900.        } else {
  901.          putnot $nick "I don't know who $who is."
  902.        }
  903.      }
  904.      return 1
  905.    }
  906.    return 0
  907.  }
  908.  
  909.  ##
  910.  ## Removes +oa for the given user: pub
  911.  ##
  912.  ## Args:    nick, user@host, handle, channel, arg
  913.  ## Returns: 1 if the user is auth'd
  914.  ##          0 otherwise
  915.  ##
  916.  proc pub:delop {nick uhost hand chan arg} {
  917.    if {[authCheck pub delop $nick $uhost $hand $chan]} then {
  918.      set arg [split [string trimright $arg]]
  919.      set who [lindex $arg 0]
  920.      set chan2 [lindex $arg 1]
  921.      if {![string compare "" $who]} then {
  922.        putnot $nick "Usage: [commandChar pub]delop <nick|hand> \[chan\]"
  923.      } else {
  924.        set user [findUser $who $chan]
  925.        if {[string compare "" $chan2]} then {
  926.          if {[validchan $chan2]} then {
  927.            set where $chan2
  928.          } else {
  929.            putnot $nick "Invalid channel: $chan2"
  930.            return 1
  931.          }
  932.        } else {
  933.          set where $chan
  934.        }
  935.        if {[validuser $user]} then {
  936.          if {[matchattr $user |o $where]} then {
  937.            chattr $user |-oa $where
  938.            putnot $nick "Removed op from $user."
  939.          } else {
  940.            putnot $nick "$user didn't have op ON $where."
  941.          }
  942.        } else {
  943.          putnot $nick "I don't know who $who is."
  944.        }
  945.      }
  946.      return 1
  947.    }
  948.    return 0
  949.  }
  950.  
  951.  ##
  952.  ## Adds +v for the given user: pub
  953.  ##
  954.  ## Args:    nick, user@host, handle, channel, arg
  955.  ## Returns: 1 if the user is auth'd
  956.  ##          0 otherwise
  957.  ##
  958.  proc pub:addvoice {nick uhost hand chan arg} {
  959.    if {[authCheck pub addvoice $nick $uhost $hand $chan]} then {
  960.      set arg [split [string trimright $arg]]
  961.      set who [lindex $arg 0]
  962.      set chan2 [lindex $arg 1]
  963.      if {![string compare "" $who]} then {
  964.        putnot $nick "Usage: [commandChar pub]addvoice <nick|hand> \[chan\]"
  965.      } else {
  966.        set user [findUser $who $chan]
  967.        if {[string compare "" $chan2]} then {
  968.          if {[validchan $chan2]} then {
  969.            set where $chan2
  970.          } else {
  971.            putnot $nick "Invalid channel: $chan2"
  972.            return 1
  973.          }
  974.        } else {
  975.          set where $chan
  976.        }
  977.        if {[validuser $user]} then {
  978.          if {![matchattr $user |v $where]} then {
  979.            chattr $user |+v $where
  980.            putnot $nick "Added voice for $user."
  981.          } else {
  982.            putnot $nick "$user already had voice ON $where."
  983.          }
  984.        } else {
  985.          putnot $nick "I don't know who $who is."
  986.        }
  987.      }
  988.      return 1
  989.    }
  990.    return 0
  991.  }
  992.  
  993.  ##
  994.  ## Removes +v for the given user: pub
  995.  ##
  996.  ## Args:    nick, user@host, handle, channel, arg
  997.  ## Returns: 1 if the user is auth'd
  998.  ##          0 otherwise
  999.  proc pub:delvoice {nick uhost hand chan arg} {
  1000.    if {[authCheck pub delvoice $nick $uhost $hand $chan]} then {
  1001.      set arg [split [string trimright $arg]]
  1002.      set who [lindex $arg 0]
  1003.      set chan2 [lindex $arg 1]
  1004.      if {![string compare "" $who]} then {
  1005.        putnot $nick "Usage: [commandChar pub]delvoice <nick|hand> \[chan\]"
  1006.      } else {
  1007.        set user [findUser $who $chan]
  1008.        if {[string compare "" $chan2]} then {
  1009.          if {[validchan $chan2]} then {
  1010.            set where $chan2
  1011.          } else {
  1012.            putnot $nick "Invalid channel: $chan2"
  1013.            return 1
  1014.          }
  1015.        } else {
  1016.          set where $chan
  1017.        }
  1018.        if {[validuser $user]} then {
  1019.          if {[matchattr $user |v $where]} then {
  1020.            chattr $user |-v $where
  1021.            putnot $nick "Removed voice from $user."
  1022.          } else {
  1023.            putnot $nick "$user didn't have voice ON $where."
  1024.          }
  1025.        } else {
  1026.          putnot $nick "I don't know who $who is."
  1027.        }
  1028.      }
  1029.      return 1
  1030.    }
  1031.    return 0
  1032.  }
  1033.  
  1034.  # Configuration defaults, values and descriptions
  1035.  array set configDefaults {
  1036.    autoop {switch 0 {} {0/1} {add +a flag when adding the user as an op?}}
  1037.    handlen {handlen 9 {} handlen {max handle length}}
  1038.  }
  1039.  
  1040.  # Bind defaults
  1041.  array set bindDefaults {
  1042.    pub:up {{pub -|- up {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1043.    pub:down {{pub -|- down {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1044.    pub:op {{pub o|o op {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1045.    pub:deop {{pub o|o deop {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1046.    pub:voice {{pub o|o voice {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1047.    pub:devoice {{pub o|o devoice {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1048.    pub:ban {{pub o|o ban {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1049.    pub:unban {{pub o|o unban {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1050.    pub:kick {{pub o|o kick {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1051.    pub:kickban {{pub o|o kickban {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1052.    pub:mode {{pub o|o mode {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1053.    pub:topic {{pub o|o topic {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1054.    pub:access {{pub o|o access {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1055.    pub:cycle {{pub m|m cycle {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1056.    pub:adduser {{pub m|m adduser {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1057.    pub:deluser {{pub m|m deluser {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1058.    pub:addhost {{pub m|m addhost {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1059.    pub:delhost {{pub m|m delhost {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1060.    pub:whois {{pub m|m whois {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1061.    pub:addop {{pub m|m addop {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1062.    pub:delop {{pub m|m delop {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1063.    pub:addvoice {{pub m|m addvoice {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1064.    pub:delvoice {{pub m|m delvoice {cmdchr {cmdsub {{commandChar pub} ^}}} {}}}
  1065.  }
  1066.  
  1067.  # Help Data
  1068.  array set helpData {
  1069.    pub:up {{} {ops or voices the user using the command}}
  1070.    pub:down {{} {deops or devoices the user using the command}}
  1071.    pub:op {{<nick>} {ops the given nick}}
  1072.    pub:deop {{<nick>} {deops the given nick}}
  1073.    pub:voice {{<nick>} {voices the given nick}}
  1074.    pub:devoice {{<nick>} {devoice the given nick}}
  1075.    pub:ban {{<nick|mask> [reason]} {bans the given nick or mask from the channel with an optional reason}}
  1076.    pub:unban {{<nick|mask>} {unbans the given nick or mask from the channel}}
  1077.    pub:kick {{<nick> [reason]} {kicks the given nick from the channel the an optional reason}}
  1078.    pub:kickban {{<nick> [reason]} {kicks and bans the given nick from the channel with an optional reason}}
  1079.    pub:mode {{<+-mode(s)> [argument(s)]} {changes the mode on the channel}}
  1080.    pub:topic {{[topic]} {sets the topic on the channel to the topic given, or if none specified, will tell you the current topic}}
  1081.    pub:access {{[nick|hand] [chan]} {shows access flags for the given nick/hand on the given channel}}
  1082.    pub:cycle {{} {makes the bot cycle the channel}}
  1083.    pub:adduser {{<nick> [host] | <hand> <host>} {adds a user to the bot's userlist}}
  1084.    pub:deluser {{<nick|hand>} {removes a user from the bot's userlist}}
  1085.    pub:addhost {{<nick|hand> <host>} {adds a host for the given user}}
  1086.    pub:delhost {{<nick|hand> <host>} {removes a host for the given user}}
  1087.    pub:whois {{<nick|hand>} {shows information for the given user}}
  1088.    pub:addop {{<nick|hand>} {adds op access for the given user for the current channel}}
  1089.    pub:delop {{<nick|hand>} {removes op access for the given user for the current channel}}
  1090.    pub:addvoice {{<nick|hand>} {adds voice access for the given user for the current channel}}
  1091.    pub:delvoice {{<nick|hand>} {removes voice access for the given user for the current channel}}
  1092.  }
  1093.  
  1094. } ;# namespace pubcmds
  1095.  
  1096. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement