• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Counting msges on channels

raf

Active Member
Joined
Jan 10, 2011
Messages
261
Reaction score
38
Location
Warsaw, PL
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!
 
You 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.
 
Last edited:
You 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.
That's really a good start for this feature! Thank you, will try to make it a little better soon ;) And post results here.
 
Back
Top