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.

Data Output

Help for those learning Tcl or writing their own scripts.
Post Reply
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Data Output

Post by COBRa »

Hi guys just scripted a small proc to display bots and owners from a database it outputs like this atm

Code: Select all

[9:48am] <~TurQ> !owners
[9:48am] <+ClonE> [OWNERS] *** owns *******
[9:48am] <+ClonE> [OWNERS] *** owns ****
[9:48am] <+ClonE> [OWNERS] *** owns ****
[9:48am] <+ClonE> [OWNERS] **** owns ****
[9:48am] <+ClonE> [OWNERS] *** owns ***
if possible i would to output it like this

Code: Select all

[OWNERS] owner1 owns bot1, bot2, bot3 
[OWNERS] owner2 owns bot1, bot2


so it would be one owner per line instead of multiple lines
here is my proc so far

Code: Select all

###################################
## !owners      ###################
###################################

proc dupe:owners { nick uhost hand chan arg } {
	global mysql_ otable_ chan_ db_handle bopen bdiv bclose	

	   if {![mysqlsel $db_handle "SELECT `id` , `owner` , `botname` FROM `bots`"]} {putnow "PRIVMSG $chan_(addbot) :No results found\."; return 0}
       	    
           mysqlmap $db_handle {id owner botname} {
                
			putnow "PRIVMSG $chan :${bopen}\00303OWNERS\003${bclose} \00314$owner owns $botname\003"
    }        
  }
many thx in advance
Last edited by COBRa on Thu May 17, 2018 11:40 am, edited 1 time in total.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Sorry for the late answer. You can achieve this directly from the select with:

Code: Select all

SELECT owner, group_concat(botname) AS bots FROM bots GROUP BY owner
and the result is:

Code: Select all

owner / bots
alterego / PREvision,dapre
DarkSide / DarkSide
MaTr1X / MaTr1X
TurQ / AddFeeD,KaNE,PR3,|PR3|,TRiAD
Your code becomes:

Code: Select all

proc dupe:owners {nick uhost hand chan text} {
	global mysql_ otable_ chan_ db_handle bopen bdiv bclose   
	if {![mysqlsel $db_handle "SELECT owner, group_concat(botname) AS bots FROM bots GROUP BY owner"]} {
		putnow "PRIVMSG $chan_(addbot) :No results found\."
		return
	}
	mysqlmap $db_handle {owner bots} {
		putnow "PRIVMSG $chan :${bopen}\00303OWNERS\003${bclose} \00314$owner owns [join [split $bots ","] ", "]\003"
	}     
}
Once the game is over, the king and the pawn go back in the same box.
Post Reply