egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add news as auto announce

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
CoCooner
Voice


Joined: 09 Feb 2009
Posts: 3

PostPosted: Sat Oct 16, 2010 7:46 am    Post subject: Add news as auto announce Reply with quote

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_archive.tcl?mode=download&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 Sad
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sat Oct 16, 2010 11:17 am    Post subject: Reply with quote

After
Code:
# ----------------------------------------------------------------------
# news
# !news
#   Querys the last 5 lines of news from the database or the news line
#   number entered
# ----------------------------------------------------------------------

add this
Code:
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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CoCooner
Voice


Joined: 09 Feb 2009
Posts: 3

PostPosted: Sat Oct 16, 2010 12:09 pm    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sat Oct 16, 2010 1:56 pm    Post subject: Reply with quote

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:
puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
to
Code:
return 0

_________________
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sat Oct 16, 2010 4:19 pm    Post subject: Reply with quote

Code:

      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:

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:

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. Very Happy 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:

proc decr var {
   uplevel 1 [list incr $var -1]
}

Btw, ::mysql::map looks interesting. Smile

Edit: Ahh, updated. Thanks username. Smile
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Tue Oct 18, 2011 2:13 am; edited 2 times in total
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sun Oct 17, 2010 3:21 am    Post subject: Reply with quote

Change
Code:
foreach chan [channels] {
to
Code:
foreach channel [channels] {

_________________
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber