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.

Add news as auto announce

Support & discussion of released scripts, and announcements of new releases.
Post Reply
C
CoCooner
Voice
Posts: 3
Joined: Mon Feb 09, 2009 1:24 pm

Add news as auto announce

Post by CoCooner »

hi there

first sry for my bad english

i've downloaded an installed the add news script from here
http://www.egghelp.org/cgi-bin/tcl_arch ... ad&id=1268

works great but is it possible to make this script announce every 30 minutes ?

maybe with a extra script ?
I've tried to contact the coder but unfortunately all his contact types are offline :(
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

After

Code: Select all

# ----------------------------------------------------------------------
# news
# !news
#   Querys the last 5 lines of news from the database or the news line 
#   number entered
# ----------------------------------------------------------------------
add this

Code: Select all

bind time - "30 * * * *" autonews
bind time - "00 * * * *" autonews
proc autonews {mins hours days months years} {
  global db_handle news_noflags

  foreach channel [channels] {

      if {![channel get $channel newsengine]} {
          return 0
      }

      set x 5
      while {$x > 0} {
          set y [expr $x - 1]
          set sql "SELECT * FROM news ORDER BY id desc limit $y,1"
          putloglev d * "NewsEngine: executing $sql"

          set result [mysqlquery $db_handle $sql]
    
          if {$x == 5} {
              puthelp "PRIVMSG $channel :NEWS:"
          }

          if {[set row [mysqlnext $result]] != ""} {
              set id [lindex $row 0]
              set news [lindex $row 3]
              set by [lindex $row 1]
              set when [clock format [lindex $row 5] -format "%d %b %Y %H:%M"]
              set chan [lindex $row 4]
              if {$chan != $channel} {
                  puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by on $chan: $news"
              } else {
                  puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by: $news"
              }
          } else {
              if {$x == 1} {
                  puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
              }
          }
          if {$x == 1} {
              puthelp "PRIVMSG $channel :End of news"
          }
          mysqlendquery $result
          set x [expr $x - 1]
      }
  }
}
I didnt test this.
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
C
CoCooner
Voice
Posts: 3
Joined: Mon Feb 09, 2009 1:24 pm

Post by CoCooner »

great work thx


now i have another problem ...if no news in the database the bot is posting

Couldn't find any news (try adding news first!)

is it possible if no news in the databse the bot is nothing to announce ?



and I find it just on that one! news now can not retrieve it

[19:43:10] Tcl error [mcpshandlepubOK]: invalid command name "news"
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

CoCooner wrote:great work thx


now i have another problem ...if no news in the database the bot is posting

Couldn't find any news (try adding news first!)

is it possible if no news in the databse the bot is nothing to announce ?
Im my code chnge

Code: Select all

puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
to

Code: Select all

return 0
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

      if {![channel get $channel newsengine]} {
          return 0
      }
if you wish to exit from a loop either use 'break' or 'continue' (self both are explanatory), not 'return'.

You should move the SQL query outside the while loop and change the 'limit' to suit your needs, meaning it's stupid to do 5 queries when you can do just one to fetch 5 results from the table and then have them parsed how you wish, something like:

Code: Select all

query
while (having results) {
parse them
}
free-up memory and close the mysql connection
Edit: In mysqlnews.sql I would change from "timestamp bigint(20)" to "timestamp int(10)" if the time is stored in this way.

Here is my (foolish) attempt on doing this:

Code: Select all

bind time - "30 * * * *" autonews
bind time - "00 * * * *" autonews

proc autonews {mins hours days months years} {
	global db_handle news_noflags
	
	set limit 5
	foreach channel [channels] {
		if {![channel get $channel newsengine]} {
			continue
		}
		set results [mysqlquery $db_handle "SELECT id, news, by, FROM_UNIXTIME(timestamp, "%d %b %Y %H:%M") AS when FROM news WHERE channel = $chan ORDER BY id DESC LIMIT $limit"]
		if {![moreresult $results]} {
			puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
		} else {
			puthelp "PRIVMSG $channel :NEWS:"
			while {[set row [mysqlfetch $results]] != ''} {
				set id [lindex $row 0]
				set news [lindex $row 1]
				set by [lindex $row 2]
				set when [lindex $row 3]
				puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by on $chan: $news"
			}
			puthelp "PRIVMSG $channel :End of news"
		}
		mysqlendquery $results
	}
	mysqlclose $db_handle
}
haven't tested it but theoretically should work. :D I'm not 100% sure about the 'FROM_UNIXTIME' thing. Anyway, I would appreciate some feedback on this.

user (a very resourceful fountain of information IMHO, too bad he's been idle lately, among others) once posted a decr proc you should use in your scripts:

Code: Select all

proc decr var {
   uplevel 1 [list incr $var -1]
}
Btw, ::mysql::map looks interesting. :)

Edit: Ahh, updated. Thanks username. :)
Last edited by caesar on Tue Oct 18, 2011 2:13 am, edited 2 times in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Change

Code: Select all

foreach chan [channels] {
to

Code: Select all

foreach channel [channels] {
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Post Reply