Word-based Filter

Here is room for additional scripts for Gamers.IRC.

You are highly advised to read the How-To first!
User avatar
Tuxman
Administrator
Posts: 1873
Joined: 24.10.2003 00:13
Status: That guy
Contact:

Word-based Filter

Unread postby Tuxman » 26.05.2018 20:51

This script basically allows you to filter IRC chat lines if they contain certain words and phrases.

Code: Select all

; Copyright © 2008-2018 by Gamers.Interactive. All Rights Reserved.
; Contact via world wide web (http://gamersirc.net) or e-mail (contact1@gamersirc.net)
; Feel free to modify and distribute this code as long as it fits to the GNU General Public License (http://gnu.org/licenses/gpl.html)
; which is included within Gamers.IRC.

; Forum: http://forum.gamersirc.net/viewtopic.php?f=34&t=1574


dialog dlgWordfilter {
  title "Word-based Filter"
  size -1 -1 300 130
  option dbu

  text "Currently filtering:", 1, 10 5 250 10, nowrap
  list 2, 10 15 230 100, sort vsbar
  button "Delete", 3, 10 110 50 11, flat disable
  button "New Entry", 4, 63 110 50 11, flat
}

on *:dialog:dlgWordfilter:sclick:*:{
  var $scriptdir\wordfilter.ini $scriptdir\wordfilter.ini
  if ($did == 2) {
    ; enable or disable "Delete":
    did $iif($did(2).sel > 0, -e, -b) wordfilter 3
  }
  elseif ($did == 3) {
    ; remove the selected line:
    remini $scriptdir\wordfilter.ini lines $ini($scriptdir\wordfilter.ini,lines,$did(2).seltext)

    ; disable the button:
    did -b dlgWordfilter 3

    ; refresh the list:
    refresh_wordlist
  }
  elseif ($did == 4) {
    ; new entry
    var %newitem = $input(Gib den zu filternden Begriff ein:,qef)
    var %currentnumber = $ini($scriptdir\wordfilter.ini, lines, 0)

    ; Hint: Item counters are increased, even after the deletion.
    ; That should not matter.
    writeini $scriptdir\wordfilter.ini lines $iif(%currentnumber,$calc(%currentnumber+1),1) %newitem

    ; refresh the list:
    refresh_wordlist
  }
}

on *:dialog:dlgWordfilter:init:{
  refresh_wordlist
}

alias -l refresh_wordlist {
  ; read and process the INI:
  if ($dialog(dlgWordfilter)) {
    did -r dlgWordfilter 2
    var %items = $ini($scriptdir\wordfilter.ini,lines,0)
    var %counter = 1

    ; rebuild the hash table:
    hdel hWordfilter *

    while (%counter <= %items) {
      var %value = $readini($scriptdir\wordfilter.ini,lines,$ini($scriptdir\wordfilter.ini,lines,%counter))
      did -a dlgWordfilter 2 %value
      inc %counter

      hadd hWordfilter %value
    }
  }
}

alias -l check_input_text {
  ; loop alias
  if ($hfind(hWordfilter, $*, 0, n) > 0) {
    ; the word is already there
    return $true
  }
  return $false
}

alias wordfilter {
  dialog -md dlgWordfilter dlgWordfilter
}

on ^*:TEXT:*:#:{
  ; Does the text contain a filtered word?
  ; If so, don't show it!
  if ($check_input_text($1-)) {
    haltdef
  }
}

on *:load:{
  hmake hWordfilter 200
}

on *:unload:{
  hfree hWordfilter
}

menu channel,query {
  -
  Word-based Filter:wordfilter
}
^\__/
..O.o

This is Einkaufswagen. Copy Einkaufswagen into your signature to help him on his way to world domination.

Who is online

Users browsing this forum: No registered users and 1 guest