Code: Select all
User1 http://user1url.com
User2 http://user2url.com
User3 http://user3url.com
User4 http://user4url.com
1. Add to the "database" && Update an existing User's URL
2. Delete Users from the "database" by just using their nick
3. List all the user's names in the channel
4. If I do !change user3 in my channel i want it to write user3's url to a var so i can input it into a mysql table
I have been trying to get this to work for days and days. here is my attempt feel free to modify it or w/e you need to do and if you have any advice or know of a better way to do this please tell me. Also I want to be able to do all of this from my channel.
Code: Select all
#mysql sever info
set host "HOST"
set user "username"
set passwd "passwd"
set db "Database"
#make sure you have the right package
package require mysqltcl
#set the database file
set streamers "scripts/stms.txt"
#bind your commands
bind pub - !addfeed add:feed
bind pub - !delfeed del:feed
bind pub - !feeds list:feed
bind pub - !feed feed:feed
if {![file exists $cmdsfile]} {
set fileid [open $cmdsfile w]
close $fileid
}
set feeds [list]
foreach donecmd [split [read [set fileid [open $streamers]]][close $fileid] \n][unset fileid] {
if {[string match -nocase "Stream name - *" $donecmd]} {
lappend feeds [lindex [split $donecmd] 3]
}
}
proc add:feed {nick uhost hand chan text} {
global streamers
if {$chan == "#sops"} {
set fs [open $streamers a]
set name [lindex $text 0]
set url [join [lrange [split $text] 1 end]]
puts $fs "Stream name: $name Stream URL: $url"
close $fs
}
}
proc del:feed {nick uhost hand chan text} {
global streamers
if {$chan == "#sops"} {
set fs [open $streamers "r"]
set data [read -nonewline $fs]
close $fs
set lines [split $data "\n"]
set name [lindex $text 0]
set match "Stream name - $name"
while {[set i [lsearch -glob $lines $match]]>-0} {
set lines [lreplace $lines $i $i]
set fs [open $streamers a]
puts $fs [join $lines "\n"]
close $fs
}
}
}
proc list:feed {nick uhost hand chan text} {
global allcommands
if {$chan == "#sops"} {
if {[llength $feeds]} {
puthelp "privmsg $chan :Available Streamers: [join $feeds {, }]"
} {
puthelp "privmsg $chan :No Available Streamers"
}
}
}
proc feed:feed { nick uhost chan handle arg } {
global host user passwd db
if {$chan == "#sops"} {
if {isop $nick $chan} {
set stream [lindex $text 0]
set feed [list]
foreach donecmd [split [read [set fileid [open $streamers]]][close $fileid] \n][unset fileid] {
if {[string match -nocase "$stream Stream URL - *" $donecmd]} {
lappend feed [lindex [split $donecmd] 3]
}
}
set con [::mysql::connect -host $host -user $user -password $passwd]
::mysql::use $con $db
::mysql::exec $con "UPDATE `streameronline` SET `StreamerUSC` = 'http://ustream.tv/e06,Q7h6Mbuey8aOxTltiQUyBKjIDFx4.usc'"
puthelp "privmsg #sops :Update successfull"
putlog "Update successfull"
::mysql::close $con
}
}
}
putlog "Script loaded: Stream Switcher"