Epic 8ball

By Cados on Apr 20, 2010

This is yet another 8ball script, but this one is different. It is used by either messages or dialog. So you can control it either way.

on owner:TEXT:*:#:{
  if ($1 == !8ball) {
    if ($2 == cmds) { .notice $nick Current 8ball commands: !8ball add <response> !8ball}
      if ($2 == add) {
        if ($3 == $null) { .notice $nick Please specify a response to add. }
      else ( .write responses.txt $3- | .notice $nick Added  $+ $3- to 8ball response database. }
    }
    if ($2 == del) {
      if ($3 == $null) { .notice $nick Please specify a line number to delete. To view responses type !8ball list }
      else {
        set %line $3
        .notice $nick Deleted line: %line $+ : $read(responses.txt,%line)
        .write -d responses.txt %line
        unset %line
      }
    }
    if ($2 == list) {
      set %y 1
      set %x 1
      while ($read(responses.txt,%x)) {
        .notice $nick %y $+ ) $read(responses.txt,%x)
        inc %y
        inc %x
      }
    }
  }
}
on *:TEXT:!8ball*:#:{
  if ($2 == $null) { .notice $nick Please specify a question. }
  else { .msg $chan Question:  $+ $2- Response:  $+ $read(responses.txt) }
}
menu channel {
  8Ball:/8ball
}
alias 8ball {
  dialog -m 8ball 8ball
}
dialog 8ball {
  title "8Ball"
  size 220 75 250 175
  option dbu
  text "Responses:", 1, 5 5 40 10
  edit "", 2, 5 15 145 10
  button "Add", 3, 35 25 20 10, dis
  button "Del", 4, 65 25 20 10, dis
  button "Clear", 5, 95 25 20 10
  list 6, 5 35 145 140
  text "Bot owner:", 7, 175 15 55 10, nowrap
  edit "", 8, 175 25 50 10
  button "Set", 9, 175 35 20 10
  button "Unset", 10, 205 35 20 10
  button "Ok", 11, 165 155 35 10, ok
  button "Cancel", 12, 210 155 35 10, cancel
}
on 1:dialog:8ball:*:*:{
  if ($devent == sclick) {
    if ($did == 3) { 
      .write responses.txt $did(2)
      did -a 8ball 6 $did(2)
    }
    if ($did == 4) { 
      .write -ds $+ $did(2) responses.txt $did(2)
      did -d 8ball 6 $did(2)
    }
    if ($did == 5) { 
      .write -c responses.txt
      did -r 8ball 6
    }
    if ($did == 6) {
      did -r 8ball 2
      did -a 8ball 2 $did(6).seltext
      did -e 8ball 3,4
    }
    if ($did == 9) {
      guser owner $did(8)
      .write -c 8owner.txt $did(8)
    }
    if ($did == 10) {
      .write -c 8owner.txt
    }
  }
  if ($devent == edit) {
    did -e 8ball 3,4
  }
  if ($devent == init) {
    set %x 1
    while ($read(responses.txt,%x)) {
      did -a 8ball $read(responses.txt)
      inc %x
    }
    did -a 8ball 8 $read(8owner.txt)
  }
}

Comments

Sign in to comment.
sk68   -  Apr 22, 2010

now that I take a better look this could be combined into 1 event using $level

on *:TEXT:!8ball*:#:{ if ($level($nick) == Owner) { ... }
else { ... }
}
 Respond  
Cados   -  Apr 20, 2010

Fixed a few major bugs. Should work now for everyone.

 Respond  
WorldDMT   -  Apr 20, 2010

fast look only i'll comeback tomorow :p
the second event missed ":"

 Respond  
Cados   -  Apr 20, 2010

For adding, listing, and deleting questions. The actual 8ball is open to all users. :D

 Respond  
sk68   -  Apr 20, 2010

why is it restricted to only owners???

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.