# Entertainment, Kiss (ent_kiss.tcl)
# Modified by nukie (02 Dec 2001) - http://nukie.front.ru/
#
# Commands: 
# Pub: !kiss, !blow, !fuck, !date & !lick
# DCC: .kiss, .blow, .fuck, .date & .lick
#
# Each response string is in this format: <type char><message, with tags>
# type chars:
#  a  : action (/me)
#  m  : msg (normal chat)
#   NOTE: there cannot be a type char `%'!
# tags:
#  %N : random nick on the channel
#  %L : lowercase random nick on the channel
#  %U : uppercase random nick on the channel
#  %n : nick of caller
#  %l : lowercase nick of caller
#  %u : uppercase nick of caller
#  %r : target, lowercase
#  %t : target
#  %T : target, uppercase

# Set logo
set entkisslg "\[4x]:"

# Set trigger
set KISSPRM "!"
# Set this to "1" if you like any of the scripts to be loaded and set it to "0" to unload.
set entkissloaded 1

set kiss_responses(kiss) {
  "meeww! no way! I'd kiss %N though! :)"
  "asteps over to %t and gives %t a big, passionate kiss! :)"
  "asteps over to %t and gives %t a hug and kiss :)"
  "mno %n, I'd rather kiss you :("
  "mhuh? cutie? come here %t :) <big IRC kiss here>"
  "mno %n, you're more kissable :)"
}

set kiss_responses(blow) {
  "acrawls on %r and *uNFs* him hard!!"
  "athinks %r is of the wrong sex..."
  "mhmm, %l, you really think I'm a whore don't you? :("
  "mhow rude %l! :("
  "mno problem, I'll give %t a good blow in a while, k?"
  "mhaha, no :D"
}

set kiss_responses(date) {
  "m%t: will you go out with me? pleeeeease??? :)"
  "mugh, you don't actually expect me to go out with %r, do you?"
  "m%t: what would you say if I asked you out?"
  "myeah, %r's a sweetie :)"
  "aasks %r out :)"
  "athinks %r will cheat on her :(("
}

set kiss_responses(lick) {
  "asssssssssslurrrrpppppppsssss %r!"
  "alicks %r real good :)"
  "mno, I don't think %r'd taste too great :(("
  "m%r you're so lickable :)"
}

######### Please do not edit anything below unless you know what you are doing ;) #########
# bindings

bind pub - ${KISSPRM}kiss pub_kiss
proc pub_kiss {nick host hand chan arg} {
  putlog "($nick!$host) !$hand! kiss $arg"
  set buf [parse_kiss $nick $chan $arg kiss]
  if { [string range $buf 0 1] == "^A" } {
    putserv "PRIVMSG $chan :ACTION [string range $buf 2 end]"
  }
  if { [string range $buf 0 1] != "^A" } {
    putserv "PRIVMSG $chan :$buf"
  }
}

bind pub - ${KISSPRM}blow pub_blow
bind pub - ${KISSPRM}fuck pub_blow
proc pub_blow {nick host hand chan arg} {
  putlog "($nick!$host) !$hand! blow $arg"
  set buf [parse_kiss $nick $chan $arg blow]
  if { [string range $buf 0 1] == "^A" } {
    putserv "PRIVMSG $chan :ACTION [string range $buf 2 end]"
  }
  if { [string range $buf 0 1] != "^A" } {
    putserv "PRIVMSG $chan :$buf"
  }
}

bind pub - ${KISSPRM}date pub_date
proc pub_date {nick host hand chan arg} {
  putlog "($nick!$host) !$hand! date $arg"
  set buf [parse_kiss $nick $chan $arg date]
  if { [string range $buf 0 1] == "^A" } {
    putserv "PRIVMSG $chan :ACTION [string range $buf 2 end]"
  }
  if { [string range $buf 0 1] != "^A" } {
    putserv "PRIVMSG $chan :$buf"
  }
}

bind pub - ${KISSPRM}lick pub_lick
proc pub_lick {nick host hand chan arg} {
  putlog "($nick!$host) !$hand! lick $arg"
  set buf [parse_kiss $nick $chan $arg lick]
  if { [string range $buf 0 1] == "^A" } {
    putserv "PRIVMSG $chan :ACTION [string range $buf 2 end]"
  }
  if { [string range $buf 0 1] != "^A" } {
    putserv "PRIVMSG $chan :$buf"
  }
}

# parse a string

proc parse_kiss {nick chan arg type} {
  global kiss_responses
  set counter 0
  set out_string ""
  set strindex [rand [llength $kiss_responses($type)]]
  while { $counter <= [string length $kiss_responses($type)] } {
    set buf [string index [lindex $kiss_responses($type) $strindex] $counter]
    set proc_flag 0
    # message types
    if { $counter == 0 && $proc_flag == 0 } {
      if { $buf == "a" } {
        set out_string "^A"
      }
      set proc_flag 1
      incr counter
    }
    if { $buf == "%" && $proc_flag == 0 } {
      set buf2 [string index [lindex $kiss_responses($type) $strindex] [expr $counter + 1]]
      if { $buf2 == "n" } {
        set out_string "$out_string$nick"
      }
      if { $buf2 == "l" } {
        set out_string "$out_string[string tolower $nick]"
      }
      if { $buf2 == "u" } {
        set out_string "$out_string[string toupper $nick]"
      }
      if { $buf2 == "N" } {
        set out_string "$out_string[lindex [chanlist $chan] [rand [llength [chanlist $chan]]]]"
      }
      if { $buf2 == "L" } {
        set out_string "$out_string[string tolower [lindex [chanlist $chan] [rand [llength [chanlist $chan]]]]]"
      }
      if { $buf2 == "U" } {
        set out_string "$out_string[string toupper [lindex [chanlist $chan] [rand [llength [chanlist $chan]]]]]"
      }
      if { $buf2 == "t" } {
        set out_string "$out_string$arg"
      }
      if { $buf2 == "T" } {
        set out_string "$out_string[string toupper $arg]"
      }
      if { $buf2 == "r" } {
        set out_string "$out_string[string tolower $arg]"
      }
      set proc_flag 1
      incr counter 2
    }
    # default is a normal character
    if { $proc_flag == 0 } {
      set out_string "$out_string$buf"
      incr counter
      set proc_flag 1
    }
  }
  return $out_string
}

# default theme is loaded, try to load up the selected one..
set loaded_theme "default"

if { [file exists "kiss-themes"] && [info vars "bnnick"] == "bnnick" } {
  global loaded_theme bnnick
  if { [info vars bnnick] != "bnnick" } {
    putlog " *** WARNING *** Cannot load/save Kiss themes because Eggdrop Extensions is not installed. It provides routines I need!"
    return
  }
  set loaded_theme default
  if { ![file exists "kiss-themes/$bnnick.theme.dat"] && [file exists "kiss-themes/default-theme.dat"] } {
    set thfd [open "kiss-themes/default-theme.dat" "RDONLY"]
    gets $thfd loaded_theme
    close $thfd
    if { [file exists "kiss-themes/$loaded_theme.thm"] } {
      source kiss-themes/$loaded_theme.thm
    }
  }
  if { [file exists "kiss-themes/$bnnick.theme.dat"] } {
    set thfd [open "kiss-themes/$bnnick.theme.dat" "RDONLY"]
    gets $thfd loaded_theme
    close $thfd
    if { [file exists "kiss-themes/$loaded_theme.thm"] } {
      source kiss-themes/$loaded_theme.thm
    }
  }
}

# now let masters change themes

bind dcc - kisstheme dcc_kisstheme
proc dcc_kisstheme {hand idx arg} {
  global loaded_theme bnnick kiss_responses
  if { $arg == "" } {
    putdcc $idx "\[4x]: current theme: $loaded_theme"
    putdcc $idx "\[4x]: usage: kisstheme \[new_theme\]"
    return
  }
  if { ![matchattr $hand m] } {
    putdcc $idx "\[4x]: access denied!"
    putlog "#$hand# failed KISSTHEME $arg (not a master)"
    return
  }
  if { ![file exists "kiss-themes/$arg.thm"] } {
    if { [matchattr $hand n] } {
      putdcc $idx "\[4x]: theme not found: $arg \[kiss-themes/$arg.thm\]"
    }
    if { ![matchattr $hand n] } {
      putdcc $idx "\[4x]: theme not found: $arg"
    }
    return
  }
  source kiss-themes/$arg.thm
  set loaded_theme $arg
  if { [info vars bnnick] == "bnnick" } {
    file delete "kiss-themes/$bnnick.theme.dat"
    set thfd [open "kiss-themes/$bnnick.theme.dat" "WRONLY CREAT"]
    puts $thfd $arg
    close $thfd
  }
  putdcc $idx "\[4x]: loaded theme: $arg"
  putlog "#$hand# KISSTHEME $arg"
}

# kiss help (in public/notice)
proc pub_kisshelp {nick uhost hand chan rest} {
	global KISSPRM botnick entkisslg
	puthelp "NOTICE $nick :${entkisslg} Entertainment, Kiss. Public Commands"
	puthelp "NOTICE $nick :${KISSPRM}kiss <nick>"
	puthelp "NOTICE $nick :${KISSPRM}blow <nick>"
	puthelp "NOTICE $nick :${KISSPRM}fuck <nick>"
	puthelp "NOTICE $nick :${KISSPRM}date <nick>"
	puthelp "NOTICE $nick :${KISSPRM}lick <nick>"
	puthelp "NOTICE $nick :${entkisslg} Other Commands:"
	puthelp "NOTICE $nick :${KISSPRM}kisshelp"
	putcmdlog "${entkisslg} <<$nick>> !$hand! Entertainment, Kiss. Public Commands Help." ; return 0
}
if {[info exist cmdmiscloaded]} {
	if {${cmdmiscloaded}} {
		bind pub - ${KISSPRM}kisshelp pub_kisshelp
	} else {
		unbind pub - ${KISSPRM}kisshelp pub_kisshelp
	}
              #putdcc "${entkisslg} Entertainment, Kiss. Loaded"
              putlog "${entkisslg} Entertainment, Kiss. Loaded"
}
