--[[
DESCRIPTION
This is a demo config file to show, what you can do with lua.
Feature list:
XEP-0004 Forms parsing and filling
XEP-0030 Info/items discovery requests (mcabber already can do replies)
XEP-0047 In-Bound Byte Streams (sending, receiving, saving with specified name, rejecting)
XEP-0077 In-Band Registration (only registration, but with data forms too)
XEP-0146 Remote commands requests
Jobs (actions, fired when some event occurs, now in one file, updated on exit)
Room nicks completion
MPD status polling (can be turned off)
Beep on all messages, even on chatroom ones
Url saving to file (for urlview)
Transported buddies availability indication
Actions on multiple marked buddies
Fallback commands (localized also! :) )
Help for fallback commands (well, I know, that it can be done with mcabber's help system, but it requires access to system files...)
All features have native mcabber interface
REQUIREMENTS
liblua-loudmouth (lm.lua and loudmouth.so)
liblua-socket - mpd
NOTES
Ibb uses own iq handler. This is the laziest way to implement this.
BUILTINS
print (global) - prints to log/status/logwindow
dofile (global) - loads lua file from default mcabber location
main methods:
- run - run literal mcabber command
- beep - beep
- log - print to log w/specified priority
- print_info - print info into specified buffer
- config_file - format full file name from relative to mcabber's config dir
- status - get current user status and message
- roster - get list of roster jids (rooms, buddies and agents)
- current_buddy - get jid of current buddy
- buddy_info - get table with info about jid and its resources
- connection - get lightuserdata for mcabber's lm connection
- timer - run function periodically
- bgread - run command and read it's output in background
- add_feature - add string to feature list (for disco#info)
- del_feature - delete string from feature list
- add_completion - adds word to completions
- del_completion - removes word from completions
- command - adds/removes mcabber command
- option - sets/gets mcabber option
STRUCTURE
To allow your chunk of configuration (eg foo.lua) to play friendly with other, do:
- place it into a separate file, eg foo.lua
- if you need hooks, do
hook_d[hookname].foo = function ( args ) foo ( ) end
- if you register commands, also do
commands_help['foo'] = "arg1 arg2\n\nFoo does bar."
- append to the end of this file
dopath 'foo'
- try to be friendly to module reloads, eg unregister handlers, where appropriate,
reset bindings
- you can omit unregistering of commands and xmpp features - module will unregister
them automatically.
--]]
-- This is a hack to allow loading of lm.lua and loudmouth.so from ~/.mcabber
-- instead of installing them system-wide
-- FIXME to C. we now require this by require'ing interdependencies between modules.
if main.option ( 'lua_extra_include' ) then
package.path = main.fileoption ( 'lua_extra_include' ) .. '/?.lua;' .. package.path
package.cpath = main.fileoption ( 'lua_extra_include' ) .. '/?.so;' .. package.cpath
end
-- COMMON SUPPORT ROUTINES
-- unused :/
function shell_escape ( str )
if str then
return "'" .. str:gsub ( "'", "'\\''" ) .. "'"
else
return "''"
end
end
-- This is for debugging purposes, not for reloading. For that see jobs.
function table_to_string ( tab, pre )
local prefix = pre or ""
local tbls, jk = "", ""
for key, val in pairs ( tab ) do
if type ( val ) == 'table' then
tbls = string.format ( "%s %s%s = %s,\n", tbls, prefix, tostring(key), table_to_string ( val, " " .. prefix ) )
else
jk = string.format ( "%s %s = \"%s\",", jk, tostring(key), tostring(val) )
end
end
if tbls == "" then
return string.format ( "{%s }", jk:sub ( 1, -2 ) )
else
return string.format ( "{%s\n%s%s}", jk, tbls, prefix )
end
end
-- COMMANDS
-- Help strings should not contain command, only arguments. This is necessary to support soft aliases.
commands_help = {
post = "filename\n\nSends file as a message. Just shorthand.",
beep = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables beeping on all messages.\nIf state is omitted, prints current state.",
cmd = "shell_command\n\nRuns shell command in background and sends output to current buddy.\nWorks asynchroneously, and may break long output in the middle of line",
exthelp = "[command]\n\nPrints help for a given command, or list of available help topics.",
['join!'] = "\n\nForcibly joins to current buddy. Just saves you typing of full room name (that can be quite long) in a case of a non-bookmarked rooms.",
count = "\n\nPrints number of resources of current buddy. Useful to determine member count of large room.",
toggle = "\n\nToggles away/online status.",
}
main.command ( 'post',
function ( args )
main.run ( 'say_to -f ' .. args .. ' .' )
end, false, 'filename' )
main.command ( 'cmd',
function ( args )
local to = main.current_buddy ()
main.run ( ('send_to -q %q $ %s'):format ( to, args ) )
main.bgread ( args,
function ( data )
if data then
main.run ( ('send_to -q %q %s'):format ( to, data ) )
return true
else
return false
end
end )
end, false, 'filename' )
main.command ( 'exthelp',
function ( args )
if commands_help[args] then
print ( "\n /" .. args .. ' ' .. commands_help[args] )
else
print ( "No help for this command." )
local list = "Help available for commands: "
for k in pairs (commands_help) do
list = list .. k .. ', '
end
print ( list:sub ( 1, -3 ) )
print ( "For built-in mcabber commands see /help" )
end
end, false, 'cmd' )
main.command ( 'join!',
function ( args )
main.run ( 'room join ' .. main.current_buddy () )
end )
main.command ( 'count',
function ( args )
local count = 0
for resource in pairs ( main.buddy_info ( main.current_buddy () ).resources ) do
count = count + 1
end
print ( "Resource count: " .. count )
end )
main.command ( 'toggle',
function ( args )
local stat, mess = main.status ()
if stat == 'o' then
main.run ( 'status away ' .. mess )
else
main.run ( 'status online ' .. mess )
end
end )
-- commands to allow leading smileys
for k, arg in ipairs ( { ')', '/', '(', 'D', '-/', 'S', '1', ']', '[' } ) do
main.command ( arg,
function ( args )
main.run ( 'say :' .. arg .. ' ' .. args )
end )
end
-- HOOKS
hooks_d = {
['hook-message-in'] = { },
['hook-message-out'] = { },
['hook-status-change'] = { },
['hook-my-status-change'] = { },
['hook-post-connect'] = { },
['hook-pre-disconnect'] = { },
['hook-start'] = { },
['hook-quit'] = { },
}
-- hook:
-- - hook-message-in
-- jid
-- groupchat
-- message
-- - hook-message-out
-- jid
-- message
-- - hook-status-change
-- jid
-- resource
-- new_status
-- old_status
-- message
-- - hook-my-status-change
-- new_status
-- message
-- - hook-post-connect
-- - hook-pre-disconnect
-- - hook-start
-- - hook-quit
function hook_handler ( args )
if [hooks_d[args.hook] then
for mod, cb in pairs ( hooks_d[args.hook] ) do
if cb then
cb ( args )
end
end
end
end
-- FIXME
hooks_d['hook-post-connect'].fifoperms =
function ( args )
-- TODO: posix
os.execute ( 'chmod 0666 ' .. main.option ( 'fifo_name' ) )
hooks_d['hook-post-connect'].fifoperms = nil
end
-- SAVING URLS TO FILE
require 'urls'
-- TRANSPORTED BUDDIES AVAILABILITY INDICATION
require 'transports'
-- BEEPING ON ALL MESSAGES
require 'beep'
-- MARKING
require 'marking'
-- JOBS
require 'jobs'
-- ROOM NICK COMPLETION
require 'room_priv'
-- FORMS
require 'forms'
-- DATA FORMS (XEP-0004)
-- PRIVACY LISTS (XEP-0016)
require 'privacy'
-- SERVICE DISCOVERY (XEP-0030)
require 'disco'
-- MULTI-USER CHAT (XEP-0045)
require 'muc'
-- IN-BAND BYTESTREAMS (XEP-0047)
require 'ibb'
-- VCARD-TEMP (XEP-0054)
require 'vcard'
-- PUBLISH-SUBSRIBE (XEP-0060)
require 'pubsub'
-- OUT OF BAND DATA (XEP-0066)
require 'oob'
-- MALICIOUS STANZAS (XEP-0076)
require 'evil'
-- IN-BAND REGISTRATION (XEP-0077)
require 'register'
-- USER LOCATION (XEP-0080)
require 'geoloc'
-- USER AVATAR (XEP-0084)
require 'avatar'
-- USER MOOD (XEP-0107)
require 'mood'
-- USER ACTIVITY (XEP-0108)
require 'activity'
-- USER TUNE (XEP-0118)
require 'tune'
-- REMOTE CONTROLLING CLIENTS (XEP-0146)
require 'remote'
-- PERSONAL EVENTING PROTOCOL (XEP-0163)
-- XMPP PING (XEP-0199)
require 'ping'
-- ATTENTION (XEP-0224)
require 'attention'
-- The End -- vim: se ts=4: --