This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to manipulate and tempstore Topicitems? add/remove/clear

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

How to manipulate and tempstore Topicitems? add/remove/clear

Post by Moneo »

Hi there,

im looking for a TCL Script with following possibilities:


!add <Realm> <Name>
!remove <Realm> <Name>
!cleartopic

basically you should be able to add teams for each realm and remove them when they went offline.


There should be a basic topic like: "Wednesday evening: [Alb: Mid: Hib:]" that you can get with the "!cleartopic" command.


If any user on the channel does "!add mid Team Dragon" it should change the topic like this: "Wednesday evening: [Alb: Mid: Team Dragon Hib:]"


remove would be the other way around "!remove mid Team Dragon would lead to: "Wednesday evening: [Alb: Mid: Hib:]"


same with the other realm mid/hib/alb



so the script has to store the realm and the teamnames in the topic, setting the colors right and be able to remove them when teams went offline.



can you help me? i could find anything like this in google or this archive :-(


cheers,

moneo
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Would be an extremely simple script to create if you read the documentation. For example:

Code: Select all

bind pub - !add addtopic
proc addtopic {nick uhost hand chan text} {
        set realm [lindex $text 0]
        set name [lindex $text 1]
        putserv "TOPIC $chan :\00310$realm\003 \00311$name\003"
}
Of course, you'd probably want to validate the $text input and limit who can actually use the command, and add your color codes.. As far as getting the day of week, check the tcl-commands.doc for strftime and so on..
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

thx for the quick answer, but I read the documentation :-(

setting the topic seems not really the problem, but setting it and then be able to remove it. (search the topic for the realm/group and then just cut out the one that should be removed !remove <realm> <grpname> ).



So if you have this topic for example:


"Wednesday evening: [Alb: Team A - MightyDucks - XYZClan Mid: Sunshine - Moonshine - NightOwls Hib: BigTrees - SmallBirds]"

and if you do "!remove mid Moonshine"

it should be like this afterwards

"Wednesday evening: [Alb: Team A - MightyDucks - XYZClan Mid: Sunshine - NightOwls Hib: BigTrees - SmallBirds]"


and if after this you do "!add hib TestM8s"

"Wednesday evening: [Alb: Team A - MightyDucks - XYZClan Mid: Sunshine - NightOwls Hib: BigTrees - SmallBirds - TestM8s]"






Thats the prob :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Ahh I didn't realize you were appending multiple pieces into the topic, I thought it was just 1 team with different colors for the realm and name. I don't understand what the alb/mid/hib means either. I think I can make a script like you're requesting, if I understood the request better. Send me a private msg with more details, and I'll put a script together for it.
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

just posted you an pm :-)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

All set:

http://members.dandy.net/~fbn/mmorpg.tcl.txt

I tested it quite a bit, it works as requested. If you want any additions or find bugs, let me know :)
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

Hiho rosc2112,



I must say im all excited about your help! :P


Just put the script in my eggdrop and it worked right away.

Did some excessive testing and I couldn´t find any bugs so far.

The lenght and parameter check are very nice and all the config variables in the beginning its real pro like. Not just a short spaghetti code thingy, you really but some effort into this and I really appreciate your work!


The only thing i changed was that i translated the bot output into german, that wasn´t to hard even for me. ;O


One thing i got asked about is if its possible to translate the weekday aswell?


Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag, Sonntag
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

You could set those days in a list and use the correct day using lindex from that list.

IE:

Code: Select all

# MMORPG Script for Moneo - Copyright C.Leonhardt Dec.2006 - rosc2112 at yahoo com
# http://members.dandy.net/~fbn/mmorpg.tcl.txt

# Purpose: Specialized script for Dark Age of Camelot MMORPG requested by Moneo
#          Adds/Removes Realms/Teams from channel topics.

# Use: !add <alb|mid|hib> <name>
#      !rem <alb|mid|hib> <name>
#      !clear (resets topic to empty stats)

# Note: I made a string map to replace spaces with underlines to simplify searching/removing teamnames, and also
#       to remove tcl-special chars ( [] {} \ " ) because they cause problems and I got tired of wrestling with it.

# When reporting bugs, PLEASE include the .set errorInfo debug info!
# Read: http://forum.egghelp.org/viewtopic.php?t=10215
#------------------------------------------------------------------------------------------------------------------
# Configs:

# Channels where we allow public use:
set mmorpgchans "#mychan #chan2 #etc"

# Color code for 'alb'
set albcolor "\00307"

# Color code for 'mid'
set midcolor "\00312"

# Color code for 'hib'
set hibcolor "\00309"

# Our week days
set days [list Montag Dienstag Mittwoch Donnerstag Freitag Samstag Sonntag]

# Max length for any single team-name (including spaces, spaces are converted to underlines in channel topics)
set maxteamlength 15

#- Script below -#-------------------------------------------------------------------------------------------------

bind pub - !add proc:addrpg
bind pub - !rem proc:remrpg
bind pub - !clear proc:resetrpg

proc proc:addrpg {nick uhost hand chan text} {
	# if command is run on non-mmorpgchan's, quietly ignore/return
	if {[lsearch -exact $::mmorpgchans $chan] == -1} {return}
	set text [string trim $text]
	set cmd [lindex $text 0]
	set teamname [lrange $text 1 end]
	set teamname [string map {" " _ \\ "" \[ "" \] "" \{ "" \} "" \" ""} $teamname]
	if {[string length [join $teamname]] > $::maxteamlength} {
		puthelp "PRIVMSG $chan :Team names must be $::maxteamlength chars or less in length!"
		return
	}
	if {(($cmd == "alb") || ($cmd == "mid") || ($cmd == "hib")) && ($teamname != "")} {
		# set the topic
		set chantopic [topic $chan]
		set alb [lindex [split $chantopic \003] 1];set alb [lrange $alb 1 end]
		set mid [lindex [split $chantopic \003] 3];set mid [lrange $mid 1 end]
		set hib [lrange [split $chantopic \003] 5 end];set hib [lrange [join $hib] 1 end-1]
		if {$cmd == "alb"} {set regsearch $alb} elseif {$cmd == "mid"} {set regsearch $mid} else {set regsearch $hib}
		if {[lsearch -exact [split [string tolower $regsearch]] [string tolower $teamname]] != -1} {
			puthelp "PRIVMSG $chan :That realm/teamname ($cmd/[join $teamname]) is already set in the topic."
			return
		}
		if {$cmd == "alb"} {lappend alb $teamname} elseif {$cmd == "mid"} {lappend mid $teamname} else {lappend hib $teamname}
		putserv "TOPIC $chan :[day] evening:  \[$::albcolor\Alb: [join $alb]\003 $::midcolor\Mid: [join $mid]\003 $::hibcolor\Hib: [join $hib]\003\]"
	} else {
		puthelp "PRIVMSG $chan :To add your realm/name, use: \002!add <alb OR mid OR hib> <team name>\002"
		return
	}
}

proc proc:remrpg {nick uhost hand chan text} {
	if {[lsearch -exact $::mmorpgchans $chan] == -1} {return}
	set text [string trim $text]
	set cmd [lindex $text 0]
	set teamname [lrange $text 1 end]
	set teamname [string map {" " _ \\ "" \[ "" \] "" \{ "" \} "" \" ""} $teamname]
	if {(($cmd == "alb") || ($cmd == "mid") || ($cmd == "hib")) && ($teamname != "")} {
		# set the topic
		set chantopic [topic $chan]
		set alb [lindex [split $chantopic \003] 1];set alb [lrange $alb 1 end]
		set mid [lindex [split $chantopic \003] 3];set mid [lrange $mid 1 end]
		set hib [lrange [split $chantopic \003] 5 end];set hib [lrange [join $hib] 1 end-1]
		if {$cmd == "alb"} {set regsearch $alb} elseif {$cmd == "mid"} {set regsearch $mid} else {set regsearch $hib}
		if {[set match [lsearch -exact [split [string tolower $regsearch]] [string tolower $teamname]]] == -1} {
			puthelp "PRIVMSG $chan :That realm/teamname ($cmd/[join $teamname]) could not be found in the topic."
			return
		}
		if {$cmd == "alb"} {set alb [lreplace $alb $match $match]} elseif {$cmd == "mid"} {set mid [lreplace $mid $match $match]} else {set hib [lreplace $hib $match $match]}
		putserv "TOPIC $chan :[day] evening:  \[$::albcolor\Alb: [join $alb]\003 $::midcolor\Mid: [join $mid]\003 $::hibcolor\Hib: [join $hib]\003\]"
	} else {
		puthelp "PRIVMSG $chan :To remove your realm/name, use: \002!rem <alb OR mid OR hib> <team name>\002"
		return
	}
}

proc proc:resetrpg {nick uhost hand chan text} {
	if {[lsearch -exact $::mmorpgchans $chan] == -1} {return}
	putserv "TOPIC $chan :[day] evening: \[$::albcolor\Alb:\003 $::midcolor\Mid:\003 $::hibcolor\Hib:\003\]"
}

# untested
proc day {} {
  global days

  if {![llength $days]} {
    return [clock format [clock seconds] -format %A]
  } else {
    return [lindex $days [expr [clock format [clock seconds] -format %u] - 1]]
  }
}
#antiwordwrap--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
putlog "MMORPG Topic script by Rosc loaded.."
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

The days were set by using strftime, I would've assumed your locale would have your native language, but if it's because your shell is english-language, I would simply make a string map to translate the day of week, something like:

Code: Select all

replace:

putserv "TOPIC $chan :[strftime %A] evening:  \[$::albcolor\Alb: [join $alb]\003 $::midcolor\Mid: [join $mid]\003 $::hibcolor\Hib: [join $hib]\003\]"

with:

set day [strftime %A]
set day [stringmap {Monday Montag Tuesday Dienstag Wednesday Mittwoch Thursday Donnerstag Friday Freitag Saturday Samstag Sunday Sonntag} $day]

putserv "TOPIC $chan :$day evening:  \[$::albcolor\Alb: [join $alb]\003 $::midcolor\Mid: [join $mid]\003 $::hibcolor\Hib: [join $hib]\003\]"
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

then stringmap thing didn´t work it crashed my eggy ;)

here the log from the crash

Code: Select all

[20:21] Tcl error in file 'nele.conf':
[20:21] invalid command name "stringmap"
    while executing
"stringmap {Monday Montag Tuesday Dienstag Wednesday Mittwoch Thursday Donnerstag Friday Freitag Saturday Samstag Sunday Sonntag} $day"
    invoked from within
"set day [stringmap {Monday Montag Tuesday Dienstag Wednesday Mittwoch Thursday Donnerstag Friday Freitag Saturday Samstag Sunday Sonntag} $day] "
    (file "scripts/mmorpg.tcl" line 35)
    invoked from within
"source scripts/mmorpg.tcl"
    (file "nele.conf" line 1352)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

My bad, it should have had a space in there, as [string map

Also, read here about how to set up scripts so they won't crash your bot on silly errors like that:
http://forum.egghelp.org/viewtopic.php?p=63899#63899
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

My modification should work fine without the need for a string map.
Unless you have actually tried it, don't give us errors.
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

Okay thanx M8, I tryed to find stringmap somewhere at the web and this forum, but I didn´t try string map :-)


I changed it and it worked right away, I wen´t with the string map because it was the easiest way for me, and because the script wont do anything else in the future then what it does now, so im not worried about the tweaking.



Im again very very happy for you two trying hard to help me and soo fast as well! /hug



Thanx again, now im totally satisfied!


PS: And I put in the script error snipped, its quite usefull, thanx for the hint!
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

Hi it´s me again with a follow up problem I just dicovered because of the uncommon use.



Its a problem with special characters in the german language -> " ö, ü, ä "

When you do: " !add alb töst " it will work fine and add töst to the topic, but " !rem alb töst "won´t work :-( the script won´t find this team.

I think there are some ways to solve it but since im not that good at tcl i can´t do it on my own.

One possibility is you could always convert the chars ö, ä, ü into oe, ae, ue what is possible in the german language.

The other way would be to check and integrate the special ö, ü, ä characters...

Or if all to difficult you just could disallow ö, ü, ä and print out another help text not to use this characters.



Could you find a solution für me? :-)
M
Moneo
Voice
Posts: 12
Joined: Tue Dec 05, 2006 7:22 pm

Post by Moneo »

Still working on it? :-)
Post Reply