This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

is not add and save the words/phrases in file badwords.txt

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
G
Gulio
Halfop
Posts: 74
Joined: Sun Nov 01, 2020 11:53 am

is not add and save the words/phrases in file badwords.txt

Post by Gulio »

I have 1 problem is not add and save word/phrase in file badwords.txt
can someone give 1 look to see what is wrong to be fixed if someone have time and desire to help thx

Code: Select all


setudef flag badword
set badwordfile "badwords.txt"

namespace eval bw {
	set file $::badwordfile
	set list {}

	# this procedure reloads the data from the file
	proc load_data {} {
		variable file
		variable data

		if {![file exists $file]} {
			set fp [open $file a]
			close $fp
		}
		set fp [open $file r]
		set lines [split [read $fp] "\n"]
		close $fp

		set data {}
		foreach line $lines {
			set line [string trim $line]
			if {$line eq {}} { continue }
			lappend data $line
		}
	}

	# this procedure writes back the data to the file
	proc save_data {} {
		variable file
		variable data

		if {![file exists $file]} {
			set fp [open $file a]
			close $fp
		}

		set fp [open $file w]
		set lines {}
		foreach line $data {
			set line [string trim $line]
			if {$line eq {}} { continue }
			lappend lines $line
		}

		set data $lines
		foreach line $data {
			puts $fp $line
		}
		close $fp
	}

	bind pub n|n .bw  bw::control
	bind msg n|n .badd bw::add_badword
	bind msg n|n .bdel bw::del_badword
	bind pubm - * bw::pubm:badword


	proc control {nick host handle chan args} {

		if { ![channel get $chan badword] && [string compare $args "on"] == 0 } {
			channel set $chan +badword
			putserv "NOTICE $nick :\002\0036BadWord\00318: \00347Is \0033ON \00347For \0034$chan\002"
		} elseif { [channel get $chan badword] && [string compare $args "off"] == 0 } {
			channel set $chan -badword
			putserv "NOTICE $nick :\002\0036badWord\00318: \00347Is \0034OFF \00347For \0033$chan\002"
		}
	}


	proc pubm:badword {nick uhost hand chan text} {

		global badwords variable data

		set ban_time 5
		bw::load_data

		if {[matchattr $hand "fo"]} { return 0 }

		if {[set chost [getchanhost $nick $chan]] ne ""} {
			switch -glob -- $chost {
				{*.irccloud.com} - {*.mibbit.com} - {*.kiwiirc.com} {
					set mask4x *![lindex [split $chost @] 0]@*
				}
				{default} {
					set mask4x [maskhost "$nick!$chost" 2]
				}

			}
		}

		if {[botisop $chan] && ![isbotnick $nick]} {
			foreach badword $badwords {
				if {[string match -nocase "*[lindex [split $badword ,] 1]*" $text]} {
					regsub -all -- {-} $text {} text
					regsub -all -- {[-\^~\|_\*]} $text {} text
					putquick "MODE $chan -v+b $nick $mask4x "
					#putquick "KICK $chan $nick :Dont Swearing!"
					after {[expr $ban_time*1000*60] [list putquick "MODE $chan -b $mask4x"]}

					break

				}
			}
		}

		return 0

	}


	proc add_badword {nick ushost handle text} {
		variable file
		variable data

		# load the data from the file
		bw::load_data

		set badword [lindex [split $text] 0]



		if {$badword eq {}} {
			putserv "Notice $nick :\002\0034Oops?!\002 \0036Use:  \002\0033.badd <word/phrase>\002"
			return 0
		} else {
			set badword {}

			putserv "privmsg $nick : NOW badword is: $badword"


			foreach line $data {

				if {![string match -nocase $line $badword]} {
					lappend badwords $line

					
				}
			}

			if {$badword ne {}} {
				putserv "Notice $nick :\002\0034Sorry\002 \0036This Mask \002\00310$text\002 \0036exist already in \002\0033BadWords File\002."
				return 0
			}

			# add the host to the data
			lappend data $badword


			# write back to the file
			bw::save_data


			putserv "NOTICE $nick :\002\0033DONE\002. \0034ADDED \0036The word/phrase \002\00310$text\002 \0036Successfully In \002\0033BadWords File\002"
			return 0
		}
	}

	proc del_badword {nick ushost handle text} {
		variable file
		variable data


		# load the data from the file
		bw::load_data

		set badword [lindex [split $text] 0]

		if {$badword eq {}} {
			putserv "NOTICE $nick :\002\0034Oops?!\002 \0036Use:  \002\0033.bdel <word/phrase>\002"
			return 0
		} else {
			set lines {}
			set badword {}
			foreach line $data {
				if {[string match -nocase $line $badword]} {
					lappend badwords $line
				} else {
					lappend lines $line
				}
			}

			if {$badword eq {}} {
				putserv "NOTICE $nick :\002\0034Sorry\002 \0036This word/phrase \002\00310$text\002 \0036does not exist in \002\0033BadWords File\002."
				return 0
			}

			set data $lines

			# write back to file
			bw::save_data

			putserv "NOTICE $nick :\002\0033DONE\002. \0034REMOVED \0036The word/phrase \002\00310$text\002 \0036Successfully from \002\0033BadWords File\002."
			return 0
		}
	}

	proc main {} {
		variable file
		variable data

		if {![file exists $file]} {
			close [open $file a]
		} elseif {![info exists data]} {
			bw::load_data
		}

		putlog " \002\0036Badword ChanneL\002 \0036- \002\0033Loaded\002 "
	}
}

bw::main

Post Reply