Project

General

Profile

[Script] Muting words

Added by Not Relevant 5 months ago

Instant-ignoring for single words instead of whole users.

Type /toggle_wordfilter to manage everything.

;; A simple word-based mute script for AdiIRC.
;; by @Cthulhux

dialog wordfilter {
  title "Word Filter" 
  size -1 -1 250 130
  option dbu

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

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

    ; disable the button:
    did -b wordfilter 3

    ; refresh the list:
    refresh_wordlist
  }
  elseif ($did == 4) {
    ; new entry
    var %newitem $input(Please enter the word you want to mute:,qef)
    var %currentnumber $ini($scriptdir\wordfilter.ini, lines, 0)

    ; we'll filter the first word. this is not a sentence filter... :-)
    writeini $scriptdir\wordfilter.ini lines $iif(%currentnumber,$calc(%currentnumber+1),1) $gettok(%newitem,1,32)

    ; refresh the list:
    refresh_wordlist
  }
}

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

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

    ; rebuild the hash table...
    hdel wordfilter *

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

      hadd wordfilter %value
    }
  }
}

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

alias toggle_wordfilter {
  /dialog -md wordfilter wordfilter
}

on ^*:TEXT:*:#:{
  ; do the actual work
  if ($check_input_text($1-)) {
    haltdef
  }
}

on *:load:{
  ; should be enough ... :-)
  hmake wordfilter 500
}

on *:unload:{
  hfree wordfilter
}