Некоторые изменения, которые нужно внести здесь в этом скрипте Tl c - PullRequest
0 голосов
/ 05 марта 2020

Теперь скрипт работает отлично, но нужно изменить команды и удалить название канала, когда я добавляю IP в список файлов exce.txt, здесь кто-то может помочь, как изменить эту команду c, спасибо заранее

!exemp help change in !help
!exemp list change in !list
!exemp del 1 change in !del 75.34.37.12  75.34.37.* 75.34.*
!exemp add change in !add 75.34.37.12 75.34.37.*  75.34.*

и удалить канал имени, когда я добавляю Ip в список exce.txt, чтобы добавить только IP-адрес, и добавляется имя канала с Ip в файлеemp.txt

#Test 75.34.37.12 

заранее спасибо

proc check_ip {ip} {
   set file [open "exemp.txt" r]
   set fdata [split [read $file] \n]
   close $file
   foreach entry $fdata {
      if {[string match $entry $ip]} {
         return 1
      }
   }
   return 0
}

bind pub n|n !exemp  exemp:cmd

set exemp(file) "exemp.txt"

if {![file exists $exemp(file)]} {
   set file [open $exemp(file) w]
   close $file
}

proc exemp:cmd {nick host hand chan arg} {
   global exemp

   set arg0 [lindex [split $arg] 0]
   set arg1 [lindex [split $arg] 1]
if {$arg0 == ""} {
   putserv "NOTICE $nick :EXEMP Use: \002!exemp help\002 for more informations."
   return
}
switch $arg0 {
   add {
if {$arg1 == ""} {
   putserv "NOTICE $nick :EXEMP Use: \002!exemp help\002 for more informations."
   return
}
   set file [open $exemp(file) a]
   puts $file "$chan $arg1"
   close $file
   putserv "NOTICE $nick :EXEMP I added\002 $arg1 \002in my ExempList."
   }

   list {
   set file [open $exemp(file) "r"]
   set read [read -nonewline $file]
   close $file
   set data [split $read "\n"]
   set i 0
if {$data == ""} {
   putserv "NOTICE $nick :EXEMP There are\002 no IP \002added to ExempList."
   return
}
   putserv "NOTICE $nick :EXEMP The list of IP added in my ExempList."
foreach line $data {
   set read_chan [lindex [split $line] 0]
if {[string match -nocase $read_chan $chan]} {
   set i [expr $i +1]
   set read_blackchan [lindex [split $line] 1]
   putserv "NOTICE $nick :$i.) $read_blackchan"
         }
      }
   }


   del {
   array set exempdel [list]
if {![regexp {.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*?\((.*?)\)} $arg1]} {
   putserv "NOTICE $nick :EXEMP Use: \002!exemp help\002 for more informations."
   return
}


set file [open $exemp(file) "r"]
   set data [read -nonewline $file]
   close $file
   set lines [split $data "\n"]
   set counter -1
   set line_counter -1
   set current_place -1
foreach line $lines {
   set line_counter [expr $line_counter + 1]
   set read_chan [lindex [split $line] 0]
if {[string match -nocase $read_chan $chan]} {
   set counter [expr $counter + 1]
   set exempdel($counter) $line_counter
   }
}

foreach place [array names exempdel] {
   if {$place == [expr $arg1 - 1]} {
   set current_place $exempdel($place)
   }
}

if {$current_place == "-1"} {
   putserv "NOTICE $nick :EXEMP The entry number\002 $arg1 \002does not exist."   
   return   
}

   set delete [lreplace $lines $current_place $current_place]
   set files [open $exemp(file) "w"]
   puts $files [join $delete "\n"]
   close $files
   set file [open $exemp(file) "r"]
   set data [read -nonewline $file]
   close $file
if {$data == ""} {
   set files [open $exemp(file) "w"]
   close $files
}
   putserv "NOTICE $nick :EXEMP The entry number\002 $arg1 \002was removed from ExempList."

   }

   help {
   putserv "NOTICE $nick :EXEMP You can add IP using: \002!exemp add <IP>\002 "
   putserv "NOTICE $nick :EXEMP To see all the IP in ExempList use:\002 !exemp list\002"
   putserv "NOTICE $nick :EXEMP To delete a IP use:\002 !exemp del <number>\002 (from the ExempList)"
      }
   }
} 

Как сейчас работает


<BoB> !exemp add 75.34.37.12
TestBot EXEMP I added 75.34.37.12 in my ExempList.
<BoB> !exemp list
TestBot EXEMP The list of IP added in my ExempList.
TestBot 1.) 75.34.37.12
<BoB> !exemp del 1
TestBot EXEMP The entry number 1 was removed from ExempList.
<BoB> !exemp list
TestBot EXEMP There are no  IP added to ExempList.
<BoB> !exemp del 75.34.37.12
 TestBot EXEMP Use: !exemp help for more informations.
 <BoB> !exemp help
 TestBot EXEMP You can add IP using: !exemp add <IP>
 TestBot EXEMP To see all the IP in ExempList use: !exemp list
 TestBot- EXEMP To delete a IP use: !exemp del <number> (from the ExempList}

...