Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- send new releases from magneto to PtokaX
- -- by deseven, 2010-2011
- require "luasql.mysql"
- BotName = "Magneto"
- PtokaXCodepage = "cp1251"
- BaseLink = "http://magneto.somesite.com/topic.php?type=show&code="
- MysqlHost = "localhost"
- MysqlUser = "magneto"
- MysqlPass = "magnetopwd"
- MysqlDB = "magnetodb"
- IDFile = "/srv/ptokax/scripts/medianew.id"
- CheckMediaTimer = 600000
- function OnStartup()
- env = assert(luasql.mysql())
- -- setting timer
- MediaTimer = TmrMan.AddTimer(CheckMediaTimer,"CheckRel")
- -- reading file to get LastRelID after restart (or first start)
- local IDFileR = assert(io.open(IDFile,"r"))
- LastRelID = IDFileR:read("*line")
- IDFileR:close()
- CheckRel()
- end
- CheckRel = function()
- if LastRelID == nil then else
- local Query = "select convert(tbl_kat.NAZV using "..PtokaXCodepage..") as cat,convert(tbl_base.NAZV using "..PtokaXCodepage..") as name,tbl_base.CODE as id from tbl_base join tbl_kat on tbl_kat.CODE = tbl_base.KAT where tbl_base.CODE > "..LastRelID.." order by tbl_base.CODE asc"
- local con = assert(env:connect(MysqlDB,MysqlUser,MysqlPass,MysqlHost))
- local res = assert(con:execute(Query))
- if res == nil then
- Core.SendToOps("<"..BotName.."> medianew: mysql-ошибка при получении новых раздач")
- else
- local row = res:fetch({},"a")
- if row == nil then else
- Core.SendToAll("<"..BotName.."> Новое в Magneto:")
- while row do
- LastRelID = row.id
- Core.SendToAll("<"..BotName.."> "..row.cat..": "..row.name:gsub("|","|").." ( "..BaseLink..row.id.." )")
- row = res:fetch(row,"a")
- end
- end
- end
- res:close()
- con:close()
- end
- end
- function OnExit()
- -- writing LastRelID to file
- if LastRelID == nil then else
- local IDFileW = assert(io.open(IDFile,"w"))
- IDFileW:write(LastRelID)
- IDFileW:close()
- end
- env:close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement