Advertisement
X-Anonymous-Y

nickserv_identify.tcl

Jan 21st, 2024 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 12.47 KB | None | 0 0
  1. namespace eval nickserv::identify {
  2.   variable ni;
  3.   # nickserv_identify.tcl --
  4.   #
  5.  
  6.   ### Version:
  7.   # 29.01.2024
  8.   #
  9.  
  10.   ### Copyright:
  11.   # CIRCLED C WITH OVERLAID BACKSLASH (c) 2023-2024 X-Anonymous-Y
  12.   #
  13.  
  14.   ### License:
  15.   # public domain (PD)
  16.   #
  17.  
  18.   ### Contact:
  19.   # irc.kn-v2.com #Eggdrop
  20.   #
  21.  
  22.   ### Help:
  23.   #
  24.  
  25.   ### Usage:
  26.   #
  27.  
  28.   ### ToDo:
  29.   #
  30.  
  31.   ### Changes:
  32.   # 29.01.2024 (Bug fix) Fixed some small bugs (X-Anonymous-Y)
  33.   # 28.01.2024 (Code cleaned) If clauses that are no longer needed have been deleted (X-Anonymous-Y)
  34.   # 27.01.2024 (New feature) Added regex to check set variables (X-Anonymous-Y)
  35.   # 25.01.2024 (Code changed) Added variable nsc [namespace current] and variable ni; for global usage. This makes the code a lot smaller and clearer (X-Anonymous-Y)
  36.   # 22.01.2024 (Code changed) Changed comments and variables (X-Anonymous-Y)
  37.   # 21.01.2024 (Code cleaned) Cleaned up comments and some code (X-Anonymous-Y)
  38.   # 20.01.2024 (New feature) User modes change to ni(user:mode) after identifying with NickServ (X-Anonymous-Y)
  39.   # 20.01.2024 (New feature) Added multiple send types /ID, /IDENTIFY, /NS, /NICKSERV (X-Anonymous-Y)
  40.   # 01.01.2024 (Code cleaned) The code has been cleaned according to all possible best practices (X-Anonymous-Y)
  41.   # ??.??.???? (Script created) Script functions considered and script created (Diamond85 - my old nick)
  42.   #
  43.  
  44.  
  45.   #
  46.   #
  47.   ### The configuration begins
  48.   #
  49.   #
  50.  
  51.  
  52.   ##
  53.   # Variable settings
  54.   ##
  55.   # Here you can specify the account that will be used for identification at NickServ.
  56.   # Format: "account"
  57.   # Examples: "The-Bot"
  58.   set ni(account) "The-Bot"
  59.  
  60.   # Here you can specify the account password that will be used for identification at NickServ.
  61.   # Format: "password"
  62.   # Examples: "TopSecretNickPassword!"
  63.   set ni(password) "TopSecretNickPassword!"
  64.  
  65.   # Set the nickname of NickServ here (correct capitalization). Incoming notices are checked for this.
  66.   # Format: "nickname"
  67.   # Examples: "NickServ" ...
  68.   set ni(nickname) "NickServ"
  69.  
  70.   # Set the user@host of NickServ (/whois NickServ) here, as above with correct capitalization. Also used for checking.
  71.   # Format: "ident@host"
  72.   # Examples: "NickServ@kn-v2/services/nickserv" ...
  73.   set ni(uhost) "NickServ@kn-v2/services/nickserv"
  74.  
  75.   # # These strings are set for the KN-V2-Network by default. Customize the notifications to which Nickserv sends! You will see it when you connect to the server.
  76.   # Separate strings with | eg. {This nickname is registered*|...}, * replaces everything.
  77.   # Format: "registered_string"
  78.   # Examples:
  79.   # Atheme-Services: This nickname is registered. Please choose a different nickname, or identify via /msg NickServ IDENTIFY Guest <password>
  80.   # Anope: This nickname is registered and protected. If it is your nick, type /msg NickServ IDENTIFY password. Otherwise, please choose a different nick.
  81.   # Anope2: This nickname is registered and protected.  If it is your
  82.   #         nick, type /msg NickServ IDENTIFY password.  Otherwise,
  83.   #         please choose a different nick.
  84.   set ni(registered:string) "This nickname is registered.*|This nickname is registered and protected.*"
  85.   # Format: "identified_strings"
  86.   # Examples:
  87.   # Atheme-Services: You are now identified for account_name.
  88.   # Anope: Password accepted - you are now recognized.
  89.   set ni(identified:string) "You are now identified for *.|Password accepted - you are now recognized."
  90.  
  91.   # Set here the user mods that should be set on the bot after identification.
  92.   # Format: "+/-user_mode"
  93.   # Examples: "+B", "+iB-w", "+i-B" ...
  94.   # Set it to "0" so that no user modes are changed.
  95.   #
  96.   # All possible user modes for InspIRCd can be found here: (https://docs.inspircd.org/3/user-modes/)
  97.   #
  98.   # If your bot is used on a different server, first check which user modes the server supports!
  99.   set ni(user:mode) "+iB-w"
  100.  
  101.   # Set the send type you want to use for identification here.
  102.   # Format: number
  103.   # Examples:
  104.   # 0 /MSG NickServ IDENTIFY <Account> <Password>
  105.   # 1 /NS IDENTIFY <Account> <Password>
  106.   # 2 /NICKSERV IDENTIFY <Account> <Password>
  107.   # 3 /ID <Account> <Password>
  108.   # 4 /IDENTIFY <Account> <Password>
  109.   set ni(send:type) 0
  110.  
  111.  
  112.   #
  113.   #
  114.   ### End of configuration
  115.   #
  116.   #
  117.  
  118.  
  119.   ###
  120.   ### DO NOT EDIT ANYTHING BELOW HERE! UNLESS YOU KNOW WHAT YOU'RE DOING!
  121.   ###
  122.  
  123.  
  124.   ##
  125.   # Various variables
  126.   ##
  127.   # [various:variables] :
  128.   variable nsc [namespace current]
  129.   set ni(logo:default) "\002\[Nickserv Identify\]\002"
  130.   set ni(logo:color) "\002\[Nickserv Identify\]\002"
  131.   set ni(logo:putlog) "\002*** \[Nickserv Identify\] ***\002"
  132.   set ni(title:default) "\002\[Nickserv Identify\]\002"
  133.   set ni(title:color) "\002\[Nickserv Identify\]\002"
  134.   set ni(title:putlog) "\002*** \[Nickserv Identify\] ***\002"
  135.  
  136.  
  137.   ##
  138.   # Un/Binds | Init
  139.   ##
  140.   # [bind:evnt] :
  141.   bind evnt - loaded ${nsc}::init
  142.   bind evnt - prerehash ${nsc}::unbind:bindings
  143.   bind evnt - prerestart ${nsc}::unbind:bindings
  144.   bind evnt - rehash ${nsc}::init
  145.  
  146.   # [init] :
  147.   proc init {args} {
  148.     variable nsc;
  149.     variable ni;
  150.     if {[info exists ${nsc}::ni(account)] && ([string trim $ni(account)] eq "")} {
  151.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(account) \"$ni(account)\"\002"
  152.       return
  153.     }
  154.     if {[info exists ${nsc}::ni(password)] && ([string trim $ni(password)] eq "")} {
  155.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(password) \"$ni(password)\"\002"
  156.       return
  157.     }
  158.     if {[info exists ${nsc}::ni(nickname)] && ([string trim $ni(nickname)] eq "")} {
  159.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(nickname) \"$ni(nickname)\"\002"
  160.       return
  161.     }
  162.     if {[info exists ${nsc}::ni(uhost)] && ([string trim $ni(uhost)] eq "") || ([${nsc}::check:regex uhost $ni(uhost)])} {
  163.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(uhost) \"$ni(uhost)\"\002"
  164.       return
  165.     }
  166.     if {[info exists ${nsc}::ni(registered:string)] && ([string trim $ni(registered:string)] eq "") || ([${nsc}::check:regex registered:string $ni(registered:string)])} {
  167.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(registered:string) \"$ni(registered:string)\"\002"
  168.       return
  169.     } else {
  170.       foreach auth_strings [split $ni(registered:string) |] {
  171.         bind notc -|- [string trim $auth_strings] ${nsc}::start:idenitfy
  172.       }
  173.     }
  174.     if {[info exists ${nsc}::ni(identified:string)] && ([string trim $ni(identified:string)] eq "") || ([${nsc}::check:regex identified:string $ni(identified:string)])} {
  175.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(identified:string) \"$ni(identified:string)\"\002"
  176.       return
  177.     } else {
  178.       foreach identified_strings [split $ni(identified:string) |] {
  179.         bind notc -|- [string trim $identified_strings] ${nsc}::user:mode
  180.       }
  181.     }
  182.     if {[info exists ${nsc}::ni(user:mode)] && ([string trim $ni(user:mode)] eq "") || ([${nsc}::check:regex user:mode $ni(user:mode)])} {
  183.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(user:mode) \"$ni(user:mode)\"\002"
  184.       return
  185.     }
  186.     if {[info exists ${nsc}::ni(send:type)] && ([string trim $ni(send:type)] eq "") || ([${nsc}::check:regex send:type ${ni(send:type)}])} {
  187.       putlog "$ni(title:putlog) \[Error\] Please check \002nickserv_identify.tcl\002 --> \002set ni(send:type) $ni(send:type)\002"
  188.       return
  189.     }
  190.     bind ctcp -|- VERSION ${nsc}::version:reply
  191.   }
  192.  
  193.   # [unbind:bindings] :
  194.   proc unbind:bindings {args} {
  195.     variable nsc;
  196.     variable ni;
  197.     foreach auth_strings [split $ni(registered:string) |] {
  198.       unbind notc -|- [string trim $auth_strings] ${nsc}::start:idenitfy
  199.     }
  200.     foreach identified_strings [split $ni(identified:string) |] {
  201.       unbind notc -|- [string trim $identified_strings] ${nsc}::user:mode
  202.     }
  203.     unbind ctcp -|- VERSION ${nsc}::version:reply
  204.   }
  205.  
  206.  
  207.   ##
  208.   # Script information
  209.   ##
  210.   # [script:variables] :
  211.   set ni(tcl:name) "nickserv_identify"
  212.   set ni(tcl:project:name) "nidentify"
  213.   set ni(tcl:author) "X-Anonymous-Y"
  214.   set ni(tcl:contact) "irc.kn-v2.com #Eggdrop"
  215.   set ni(tcl:copyright) "©"
  216.   set ni(tcl:year) "2023-2024"
  217.   set ni(tcl:version) "29.01.2024"
  218.   set ni(tcl:website) "https://pastebin.com/VSXhUBbJ"
  219.  
  220.  
  221.   ##
  222.   # Actions
  223.   ##
  224.   # [start:idenitfy] :
  225.   proc start:idenitfy {nick uhost hand text {dest ""}} {
  226.     variable nsc;
  227.     variable ni;
  228.     if {[string match "$ni(nickname)" $nick] && [string match "$ni(uhost)" $uhost]} {
  229.       ${nsc}::idenitfy $nick $uhost
  230.     } else {
  231.       putlog "$ni(title:putlog) \[Warning\] $nick ($uhost) tried to get account identify data. (With notice: \002$text\002)"
  232.       return
  233.     }
  234.   }
  235.  
  236.   # [idenitfy] :
  237.   proc idenitfy {nick uhost} {
  238.     variable nsc;
  239.     variable ni;
  240.     if {$ni(send:type) == 0} {
  241.       putquick "PRIVMSG $nick :IDENTIFY $ni(account) $ni(password)"
  242.       putlog "$ni(title:putlog) \[Info\] Identify on $nick ($uhost) via /MSG NickServ IDENTIFY \002$ni(account)\002 <Password>"
  243.       return
  244.     } elseif {$ni(send:type) == 1} {
  245.       putquick "NS :IDENTIFY $ni(account) $ni(password)"
  246.       putlog "$ni(title:putlog) \[Info\] Identify on $nick ($uhost) via /NS IDENTIFY \002$ni(account)\002 <Password>"
  247.       return
  248.     } elseif {$ni(send:type) == 2} {
  249.       putquick "NICKSERV :IDENTIFY $ni(account) $ni(password)"
  250.       putlog "$ni(title:putlog) \[Info\] Identify on $nick ($uhost) via /NICKSERV IDENTIFY \002$ni(account)\002 <Password>"
  251.       return
  252.     } elseif {$ni(send:type) == 3} {
  253.       putquick "ID $ni(account) $ni(password)"
  254.       putlog "$ni(title:putlog) \[Info\] Identify on $nick ($uhost) via /ID \002$ni(account)\002 <Password>"
  255.       return
  256.     } elseif {$ni(send:type) == 4} {
  257.       putquick "IDENTIFY $ni(account) $ni(password)"
  258.       putlog "$ni(title:putlog) \[Info\] Identify on $nick ($uhost) via /IDENTIFY \002$ni(account)\002 <Password>"
  259.       return
  260.     }
  261.   }
  262.  
  263.   # [user:mode] :
  264.   proc user:mode {nick uhost hand text {dest ""}} {
  265.     variable nsc;
  266.     variable ni;
  267.     if {[string match "$ni(nickname)" $nick] && [string match "$ni(uhost)" $uhost]} {
  268.       putlog "$ni(title:putlog) \[Info\] Password accepted."
  269.       if {([string trim $ni(user:mode)] == 0)} {
  270.         return
  271.       } else {
  272.         global botnick
  273.         putquick "MODE $botnick $ni(user:mode)"
  274.         putlog "$ni(title:putlog) \[Info\] User modes changed to \002$ni(user:mode)\002"
  275.         return
  276.       }
  277.     } else {
  278.       putlog "$ni(title:putlog) \[Warning\] $nick ($uhost) tried to get account identify data. (With notice: \002$text\002)"
  279.       return
  280.     }
  281.   }
  282.  
  283.   # [check:regex] : type arg
  284.   proc check:regex {type arg} {
  285.     if {($type eq "uhost")} {
  286.       if {[regexp -- {^.*[@].*$} ${arg}]} {
  287.         return 0
  288.       } else {
  289.         return 1
  290.       }
  291.     } elseif {($type eq "registered:string")} {
  292.       if {[regexp -- {^(This.*nickname.*is.*registered.*)$} ${arg}]} {
  293.         return 0
  294.       } else {
  295.         return 1
  296.       }
  297.     } elseif {($type eq "identified:string")} {
  298.       if {[regexp -- {^(You.are.now.identified.*|Password.accepted.*)$} ${arg}]} {
  299.         return 0
  300.       } else {
  301.         return 1
  302.       }
  303.     } elseif {($type eq "user:mode")} {
  304.       if {[regexp -- {^[+-][ioswBcdDgGHhIkLNORrSTWxz]*(?:([+-][ioswBcdDgGHhIkLNORrSTWxz]*))*$} ${arg}]} {
  305.         return 0
  306.       } else {
  307.         return 1
  308.       }
  309.     } elseif {($type eq "send:type")} {
  310.       if {[regexp -- {^[0-4]$} $arg]} {
  311.         return 0
  312.       } else {
  313.         return 1
  314.       }
  315.     }
  316.   }
  317.  
  318.  
  319.   ##
  320.   # CTCP
  321.   ##
  322.   # [version:reply] :
  323.   proc version:reply {nick uhost hand dest key arg} {
  324.     variable ni;
  325.     puthelp "NOTICE $nick :VERSION $ni(title:default) Name: \002$ni(tcl:name)\002 \| Projectname: \002$ni(tcl:project:name)\002 \| Version: \002$ni(tcl:version)\002 \| \002$ni(tcl:copyright)\002 \002$ni(tcl:year)\002 by \002$ni(tcl:author)\002 \| Contact: \002$ni(tcl:contact)\002 \| Website: \037\002$ni(tcl:website)\002\037"
  326.     #putlog "$ni(title:putlog) \[Info\] CTCP version from $nick ($uhost)"
  327.     return
  328.   }
  329. }
  330.  
  331. putlog "$nickserv::identify::ni(title:putlog) Name: \002$nickserv::identify::ni(tcl:name)\002 \| Projectname: \002$nickserv::identify::ni(tcl:project:name)\002 \| Version: \002$nickserv::identify::ni(tcl:version)\002 \| \002Loaded\002."
  332.  
Tags: TCL eggdrop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement