currenttopic.tcl

currenttopic.tcl

This script shows info of the current topic of the channel if it is possible. Current DCC Commands: .ctopic/.currenttopic [channel]

Postat de Copyright Categorie Review user Vizualizari Data
btc Teemu Hjelt chanops Cod netestat 553 2023-12-25 00:20:26

# currenttopic.tcl v1.10 [4 December 1999] 
# Copyright © 1999 Teemu Hjelt <[email protected]>
#
# Latest version can be found from http://www.iki.fi/temex/tcls/
# 
# If you have any suggestions, questions or you want to report 
# bugs, please feel free to send me email to [email protected]
#
# This script shows info of the current  
# topic of the channel if it is possible.
#
# Current DCC Commands: 
#    .ctopic/.currenttopic [channel]
#
# Current MSG Commands: 
#    ctopic/currenttopic <channel>
#
# Current Channel Commands: 
#    ctopic/currenttopic [channel] 
#
# Tested on eggdrop1.4.0 with TCL 7.6
#
# Version history:
# v1.00 - The very first version!
# v1.01 - Fixed little bugs, renamed the procs and added msg commands. 
# v1.02 - Made the channel option an optional option in dcc commands.
# v1.03 - Fixed few bugs and made this script more compact.
# v1.04 - Added the amount of words to the info line and fixed little bugs.
# v1.10 - Now this script shows how long time ago the topic was changed.
#         Fixed a bug with topics that that contain chars like { } [ ] $ \ "
#         Also fixed lots of smaller bugs.

### Settings ###

## [0/1] Enable Channel Commands?
set ct_enablepublic 1

## [0/1] Enable MSG Commands?
set ct_enablemsg 1

## [0/1] Enable DCC Commands?
set ct_enabledcc 1

## What users can use the commands?
set ct_flag "f|f"

## What command prefix do you want to use for channel commands?
set ct_cmdpfix "!"

## [0/1] Enable this if you want to use [strftime] instead of [ctime [unixtime]] to show the time and date.
set ct_enablestrftime 0

## If you have enabled $ct_enablestrftime, then set this to the formatstring for strftime.
# Note: If you don't have a clue what this is, then leave it like it is.
set ct_formatstring "%c"

###### You don't need to edit below this ######

### Misc Things ###

set ct_ver "1.10"

### Bindings ###

bind topc - * topc:ct_change

## Channel Commands
if {$ct_enablepublic} {
	bind pub $ct_flag ${ct_cmdpfix}ctopic pub:ct_ctopic
	bind pub $ct_flag ${ct_cmdpfix}currenttopic pub:ct_ctopic
}

## MSG Commands
if {$ct_enablemsg} {
	bind msg $ct_flag ctopic msg:ct_ctopic
	bind msg $ct_flag currenttopic msg:ct_ctopic
}

## DCC Commands
if {$ct_enabledcc} {
	bind dcc $ct_flag ctopic dcc:ct_ctopic
	bind dcc $ct_flag currenttopic dcc:ct_ctopic
}

### Procs ###

proc topc:ct_change {nick uhost hand chan topic} {
global botnick ct_topic ct_topictime ct_topicinfo ct_enablestrftime ct_formatstring
	if {($nick != "*") && ($uhost != "*")} {
		set ct_topic([string tolower $chan]) $topic
		set ct_topictime([string tolower $chan]) [unixtime]
		if {$ct_enablestrftime} { 
			if {[catch {set time [strftime $ct_formatstring]} 0]} {
				set time [ctime [unixtime]]
			}
		} else {
			set time [ctime [unixtime]]
		}
		if {([string tolower $nick] != [string tolower $botnick]) && ($hand != "*")} {
			if {$topic == ""} {
				set ct_topicinfo([string tolower $chan]) "The topic was cleared by $nick ($uhost) !$hand! at $time"
			} else {
				set ct_topicinfo([string tolower $chan]) "The topic \"$topic\" ([string length $topic] chars/[llength [split $topic]] words) was set by $nick ($uhost) !$hand! at $time"
			}
		} else {
			if {$topic == ""} {
				set ct_topicinfo([string tolower $chan]) "The topic was cleared by $nick ($uhost) at $time"
			} else {
				set ct_topicinfo([string tolower $chan]) "The topic \"$topic\" ([string length $topic] chars/[llength [split $topic]] words) was set by $nick ($uhost) at $time"
			}
		}
	}
}

proc pub:ct_ctopic {nick uhost hand chan arg} {
global ct_topic ct_topictime ct_topicinfo
	if {[lindex [split $arg] 0] != ""} { 
		set c [lindex [split $arg] 0]
	} else {
		set c $chan 
	}
	if {![ct_botonchan $c]} {
		putserv "NOTICE $nick :I'm not on $c."
	} else {
		if {[info exist ct_topic([string tolower $c])] && [info exist ct_topictime([string tolower $c])] && [info exist ct_topicinfo([string tolower $c])] && ($ct_topic([string tolower $c]) == [topic $c])} {
			if {[string tolower $chan] == [string tolower $c]} {
				if {[catch {set duration [duration [expr [unixtime]-$ct_topictime([string tolower $c])]]} 0]} { set duration "[expr [unixtime]-$ct_topictime([string tolower $c])] seconds" }
				putserv "PRIVMSG $chan :$ct_topicinfo([string tolower $c]) ($duration ago)"
			} else {
				if {[catch {set duration [duration [expr [unixtime]-$ct_topictime([string tolower $c])]]} 0]} { set duration "[expr [unixtime]-$ct_topictime([string tolower $c])] seconds" }
				putserv "PRIVMSG $chan :$c: $ct_topicinfo([string tolower $c]) ($duration ago)" 
			}
		} else {
			if {[string tolower $chan] == [string tolower $c]} {
				putserv "PRIVMSG $chan :I don't know who set the current topic."
			} else {
				putserv "PRIVMSG $chan :I don't know who set the current topic for $c."
			}
		}
	}
return 1
}

proc msg:ct_ctopic {nick uhost hand arg} {
global ct_topic ct_topictime ct_topicinfo
set c [lindex [split $arg] 0]
	if {$c == ""} {
		putserv "NOTICE $nick :Usage: ctopic <channel>"
	} else {
		if {![ct_botonchan $c]} {
			putserv "NOTICE $nick :I'm not on $c."
		} else {
			if {[info exist ct_topic([string tolower $c])] && [info exist ct_topictime([string tolower $c])] && [info exist ct_topicinfo([string tolower $c])] && ($ct_topic([string tolower $c]) == [topic $c])} {
				if {[catch {set duration [duration [expr [unixtime]-$ct_topictime([string tolower $c])]]} 0]} { set duration "[expr [unixtime]-$ct_topictime([string tolower $c])] seconds" }
				putserv "NOTICE $nick :$c: $ct_topicinfo([string tolower $c]) ($duration ago)"
			} else {
				putserv "NOTICE $nick :I don't know who set the current topic for $c."
			}
		}
	}
return 1
}

proc dcc:ct_ctopic {hand idx arg} {
global ct_topic ct_topictime ct_topicinfo
	putcmdlog "#$hand# ctopic $arg"
	if {[lindex [split $arg] 0] != ""} { 
		set c [lindex [split $arg] 0]
	} else {
		set c [lindex [console $idx] 0] 
	}
	if {$c == ""} {
		putidx $idx "Usage: .ctopic <channel>"
	} else {
		if {![ct_botonchan $c]} {
			putidx $idx "I'm not on $c."
		} else {
			if {[info exist ct_topic([string tolower $c])] && [info exist ct_topictime([string tolower $c])] && [info exist ct_topicinfo([string tolower $c])] && ($ct_topic([string tolower $c]) == [topic $c])} {
				if {[catch {set duration [duration [expr [unixtime]-$ct_topictime([string tolower $c])]]} 0]} { set duration "[expr [unixtime]-$ct_topictime([string tolower $c])] seconds" }
				putidx $idx "$c: $ct_topicinfo([string tolower $c]) ($duration ago)"
			} else {
				putidx $idx "I don't know who set the current topic for $c."
			}
		}
	}
}

proc ct_botonchan {chan} {
global botnick numversion
	if {$numversion < 1032400} {
		if {[validchan $chan] && [onchan $botnick $chan]} {
			return 1
		} else {
			return 0
		}
	} else {
		if {[validchan $chan] && [botonchan $chan]} {
			return 1
		} else {
			return 0
		}
	}
}

### End ###

putlog "TCL loaded: currenttopic.tcl v$ct_ver by Sup <[email protected]>"