raf
Active Member
How can i count messages sent on channels like help channel ? Does it require modifying core files or just LUA scripting ? Anyone got any ideas or thoughts - please post it here!
CREATE TABLE `channel_message` (
`channel_id` smallint(2) not null,
`count` int(11),
primary key (`channel_id`)
);
function getChannelMessageCount(Channel_id)
local count = db.storeQuery("SELECT `count` FROM `channel_message` WHERE `channel_id` = ".. Channel_id)
if count ~= false then
local value = result.getDataInt (count, "count")
result.free (count)
return value
end
return -1
end
function setChannelMessageCount(Channel_id, value)
if getChannelMessageCount(Channel_id) == -1 then
return db:query("INSERT INTO `channel_message` (`channel_id`,`count`) VALUES (".. Channel_id ..", ".. value .."); ")
else
return db:query("UPDATE `channel_message` SET `count` = " .. value .. " WHERE `channel_id` = ".. Channel_id .."; ")
end
end
local channel = 9 - this is the id of your channel
local count = getChannelMessageCount(channel)
if count == -1 then
count = 0
end
setChannelMessageCount(channel, count + 1)
That's really a good start for this feature! Thank you, will try to make it a little better soonYou can create a table in the database like this:
Code:CREATE TABLE `channel_message` ( `channel_id` smallint(2) not null, `count` int(11), primary key (`channel_id`) );
In global.lua adds this:
Code:function getChannelMessageCount(Channel_id) local count = db.storeQuery("SELECT `count` FROM `channel_message` WHERE `channel_id` = ".. Channel_id) if count ~= false then local value = result.getDataInt (count, "count") result.free (count) return value end return -1 end function setChannelMessageCount(Channel_id, value) if getChannelMessageCount(Channel_id) == -1 then return db:query("INSERT INTO `channel_message` (`channel_id`,`count`) VALUES (".. Channel_id ..", ".. value .."); ") else return db:query("UPDATE `channel_message` SET `count` = " .. value .. " WHERE `channel_id` = ".. Channel_id .."; ") end end
After the channel in your script before the return type you put this code:
Code:local channel = 9 - this is the id of your channel local count = getChannelMessageCount(channel) if count == -1 then count = 0 end setChannelMessageCount(channel, count + 1)
Have not tested, just I follow the logic.