Skip to content

Commit

Permalink
new tbot version
Browse files Browse the repository at this point in the history
  • Loading branch information
torhve committed Nov 1, 2012
1 parent 7dfdbba commit c64cff8
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions tbot.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,15 +64,30 @@ function string:split(sSeparator, nMax, bRegexp)
end end





function tbot_list(data, buffer, time, tags, displayed, highlight, prefix, message) function tbot_list(data, buffer, time, tags, displayed, highlight, prefix, message)
local patterns = w.config_string(tbot_config.hdtrue) -- Bot command list, return the hd and sd list
-- Prettier local function prettify_patterns(option)
patterns = patterns:split(',') local patterns = w.config_string(option)
table.sort(patterns, function (a, b) -- Prettier
return string.lower(a) < string.lower(b) patterns = patterns:split(',')
end) table.sort(patterns, function (a, b)
patterns = table.concat(patterns, ', ') return string.lower(a) < string.lower(b)
w.command(buffer, "HD: " .. patterns) end)
patterns = table.concat(patterns, ', ')
return patterns
end
w.command(buffer, "HD: " .. prettify_patterns(tbot_config.hdtrue))
w.command(buffer, "SD: " .. prettify_patterns(tbot_config.sdtrue))
return w.WEECHAT_RC_OK
end

function tbot_count(data, buffer, time, tags, displayed, highlight, prefix, message)
-- Bot command to count
local hdpatterns = w.config_string(tbot_config.hdtrue):split(',')
local sdpatterns = w.config_string(tbot_config.sdtrue):split(',')
w.command(buffer, "HD: count: " .. #hdpatterns)
w.command(buffer, "SD: count: " .. #sdpatterns)
return w.WEECHAT_RC_OK return w.WEECHAT_RC_OK
end end


Expand All @@ -85,7 +100,8 @@ function tbot_add(data, buffer, time, tags, displayed, highlight, prefix, messag
-- Save the new config option -- Save the new config option
w.config_option_set(tbot_config.hdtrue, str, 1) w.config_option_set(tbot_config.hdtrue, str, 1)
-- Display the new string -- Display the new string
return tbot_list(data, buffer, time, tags, displayed, highligh, prefix, message) w.command(buffer, "Added " .. new)
return w.WEECHAT_RC_OK
end end


function tbot_remove(data, buffer, time, tags, displayed, highlight, prefix, message) function tbot_remove(data, buffer, time, tags, displayed, highlight, prefix, message)
Expand Down Expand Up @@ -227,13 +243,14 @@ function tbot_init()
) )
tbot_config_init() tbot_config_init()
tbot_config_read() tbot_config_read()
local enabled = w.config_boolean(tbot_config.enable) local enabled = w.config_boolean(tbot_config.enable)
if enabled == 1 then if enabled == 1 then
-- Register bot commands -- Register bot commands
w.hook_print("", "", "@tbot list", 1, "tbot_list", "") w.hook_print("", "", "@tbot list", 1, "tbot_list", "")
w.hook_print("", "", "@tbot add", 1, "tbot_add", "") w.hook_print("", "", "@tbot add", 1, "tbot_add", "")
w.hook_print("", "", "@tbot remove", 2, "tbot_remove", "") w.hook_print("", "", "@tbot remove", 1, "tbot_remove", "")
end w.hook_print("", "", "@tbot count", 1, "tbot_count", "")
end
end end


-- Initialize the script -- Initialize the script
Expand Down

0 comments on commit c64cff8

Please sign in to comment.