• 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!

Talkaction bot

Mudrock

Member
Joined
Jan 25, 2017
Messages
102
Reaction score
19
Location
Minas Gerais - Brazil
Well, my idea is that the player uses a talkaction !bot <name> Send to a channel the information with the name of the player who used the talkaction and the name of the player reported!
If possible it would also be interesting to save the log to some folder on the server!

Thank you very much in advance.
Sorry for my bad english
 
Solution
2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
linux?
i made it for windows so idk the commands for linux
you could manually create the folder i guess though and just use this
Lua:
local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}

local function writeLog(filePath, text)
    local file = io.open(filePath, "a+")
    file:write(text .. "\n")
    file:close()
end

function onSay(player, words, param)
    if (param == "") then...
Well, my idea is that the player uses a talkaction !bot <name> Send to a channel the information with the name of the player who used the talkaction and the name of the player reported!
If possible it would also be interesting to save the log to some folder on the server!

Thank you very much in advance.
Sorry for my bad english
1.x, 0.4? Almost impossible to help without knowing it.
 
no other setup required, script automatically creates folder and report log files
usage: !report <playerName>
edit the channel id to whatever channel you want to send the message in
XML:
<talkaction words="!report" separator=" " script="report.lua"/>
Lua:
local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}

local folderExists = false

for file in io.popen('dir "data/" /b /ad'):lines() do
    if file:match("botReports") then
        folderExists = true
    end
end

if not folderExists then
    os.execute('mkdir "'.. folderPath ..'"')
end

local function writeLog(filePath, text)
    local file = io.open(filePath, "a+")
    file:write(text .. "\n")
    file:close()
end

function onSay(player, words, param)
    if (param == "") then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Param required.") and false
    end
    local target = Player(param)
    if not target then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Player is not online or you input an invalid player name.") and false
    end
    local exhausted = (exhausts[player:getId()] or 0) > os.mtime()
    if not exhausted then
        local reporter = player:getName()
        local reported = target:getName()
        local date = os.date()
        sendChannelMessage(channelId, TALKTYPE_CHANNEL_R1, ("%s reported %s at [%s]"):format(reporter, reported, date))
        writeLog(folderPath .. reporter .. ".log", ("[%s]: Reported player: %s."):format(date, reported))
        exhausts[player:getId()] = os.mtime() + exhaust
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Thank you for your report.") and false
    else
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot report this fast.") and false
    end
end
 
no other setup required, script automatically creates folder and report log files
usage: !report <playerName>
edit the channel id to whatever channel you want to send the message in
XML:
<talkaction words="!report" separator=" " script="report.lua"/>
Lua:
local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}

local folderExists = false

for file in io.popen('dir "data/" /b /ad'):lines() do
    if file:match("botReports") then
        folderExists = true
    end
end

if not folderExists then
    os.execute('mkdir "'.. folderPath ..'"')
end

local function writeLog(filePath, text)
    local file = io.open(filePath, "a+")
    file:write(text .. "\n")
    file:close()
end

function onSay(player, words, param)
    if (param == "") then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Param required.") and false
    end
    local target = Player(param)
    if not target then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Player is not online or you input an invalid player name.") and false
    end
    local exhausted = (exhausts[player:getId()] or 0) > os.mtime()
    if not exhausted then
        local reporter = player:getName()
        local reported = target:getName()
        local date = os.date()
        sendChannelMessage(channelId, TALKTYPE_CHANNEL_R1, ("%s reported %s at [%s]"):format(reporter, reported, date))
        writeLog(folderPath .. reporter .. ".log", ("[%s]: Reported player: %s."):format(date, reported))
        exhausts[player:getId()] = os.mtime() + exhaust
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Thank you for your report.") and false
    else
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot report this fast.") and false
    end
end

2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
 
2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /b: No such file or directory
2017-02-23 12:52:28 - dir: cannot access /ad: No such file or directory
linux?
i made it for windows so idk the commands for linux
you could manually create the folder i guess though and just use this
Lua:
local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}

local function writeLog(filePath, text)
    local file = io.open(filePath, "a+")
    file:write(text .. "\n")
    file:close()
end

function onSay(player, words, param)
    if (param == "") then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Param required.") and false
    end
    local target = Player(param)
    if not target then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Player is not online or you input an invalid player name.") and false
    end
    local exhausted = (exhausts[player:getId()] or 0) > os.mtime()
    if not exhausted then
        local reporter = player:getName()
        local reported = target:getName()
        local date = os.date()
        sendChannelMessage(channelId, TALKTYPE_CHANNEL_R1, ("%s reported %s at [%s]"):format(reporter, reported, date))
        writeLog(folderPath .. reporter .. ".log", ("[%s]: Reported player: %s."):format(date, reported))
        exhausts[player:getId()] = os.mtime() + exhaust
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Thank you for your report.") and false
    else
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot report this fast.") and false
    end
end
 
Solution
linux?
i made it for windows so idk the commands for linux
you could manually create the folder i guess though and just use this
Lua:
local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}

local function writeLog(filePath, text)
    local file = io.open(filePath, "a+")
    file:write(text .. "\n")
    file:close()
end

function onSay(player, words, param)
    if (param == "") then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Param required.") and false
    end
    local target = Player(param)
    if not target then
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Player is not online or you input an invalid player name.") and false
    end
    local exhausted = (exhausts[player:getId()] or 0) > os.mtime()
    if not exhausted then
        local reporter = player:getName()
        local reported = target:getName()
        local date = os.date()
        sendChannelMessage(channelId, TALKTYPE_CHANNEL_R1, ("%s reported %s at [%s]"):format(reporter, reported, date))
        writeLog(folderPath .. reporter .. ".log", ("[%s]: Reported player: %s."):format(date, reported))
        exhausts[player:getId()] = os.mtime() + exhaust
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "Thank you for your report.") and false
    else
        return player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot report this fast.") and false
    end
end

It worked perfectly, I just do not know if git will be able to find the reports folder to get me back on windows! But this I think I can correct!

I love you man <3

vkbbRMQ.png
 
Back
Top