examples/mcabberrc.lua
changeset 7 eb6d89bf1fbf
parent 6 90dceae3ed1f
child 8 fc9060b9b7cc
equal deleted inserted replaced
6:90dceae3ed1f 7:eb6d89bf1fbf
    53 - connection    - get lightuserdata for mcabber's lm connection
    53 - connection    - get lightuserdata for mcabber's lm connection
    54 - timer         - run function periodically
    54 - timer         - run function periodically
    55 - bgread        - run command and read it's output in background
    55 - bgread        - run command and read it's output in background
    56 - add_feature   - add string to feature list (for disco#info)
    56 - add_feature   - add string to feature list (for disco#info)
    57 - del_feature   - delete string from feature list
    57 - del_feature   - delete string from feature list
    58 - add_command   - adds mcabber command
    58 - command       - adds/removes mcabber command
    59 - del_command   - remove mcabber command
       
    60 
    59 
    61 --]]
    60 --]]
    62 
    61 
    63 -- This is a hack to allow loading of lm.lua and loudmouth.so from ~/.mcabber
    62 -- This is a hack to allow loading of lm.lua and loudmouth.so from ~/.mcabber
    64 -- instead of installing them system-wide
    63 -- instead of installing them system-wide
   181 
   180 
   182 -- COMMANDS
   181 -- COMMANDS
   183 
   182 
   184 -- Help strings should not contain command, only arguments. This is necessary to support soft aliases.
   183 -- Help strings should not contain command, only arguments. This is necessary to support soft aliases.
   185 commands_help = {
   184 commands_help = {
   186 	file      = "filename\n\nSends file as a message. Just shorthand.",
   185 	post      = "filename\n\nSends file as a message. Just shorthand.",
   187 	s         = "status [message]\n\nSets your status, but takes into account mpd (if enabled).",
   186 	s         = "status [message]\n\nSets your status, but takes into account mpd (if enabled).",
   188 	beep      = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables beeping on all messages.\nIf state is omitted, prints current state.",
   187 	beep      = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables beeping on all messages.\nIf state is omitted, prints current state.",
   189 	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",
   188 	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",
   190 	exthelp   = "[command]\n\nPrints help for a given command, or list of available help topics.",
   189 	exthelp   = "[command]\n\nPrints help for a given command, or list of available help topics.",
   191 	reload    = "\n\nJust a shorthand to reload lua config file. Note, that for now this discards all changes to configuration, open forms, transferred files.",
   190 	reload    = "\n\nJust a shorthand to reload lua config file. Note, that for now this discards all changes to configuration, open forms, transferred files.",
   192 	['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.",
   191 	['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.",
   193 	count     = "\n\nPrints number of resources of current buddy. Useful to determine member count of large room."
   192 	count     = "\n\nPrints number of resources of current buddy. Useful to determine member count of large room."
   194 }
   193 }
   195 
   194 
   196 main.add_command ( "lua",
   195 main.command ( 'post',
   197 	function ( args )
       
   198 		assert ( loadstring ( args ) ) ()
       
   199 	end )
       
   200 main.add_command ( 'file',
       
   201 	function ( args )
   196 	function ( args )
   202 		main.run ( 'say_to -f ' .. args .. ' .' )
   197 		main.run ( 'say_to -f ' .. args .. ' .' )
   203 	end )
   198 	end )
   204 main.add_command ( 's',
   199 main.command ( 's',
   205 	function ( args )
   200 	function ( args )
   206 		main.run ( ('status %s %s'):format ( args, mpd_getstatus () ) )
   201 		main.run ( ('status %s %s'):format ( args, mpd_getstatus () ) )
   207 	end )
   202 	end )
   208 main.add_command ( 'beep',
   203 main.command ( 'beep',
   209 	function ( args )
   204 	function ( args )
   210 		local enable = yesno ( args )
   205 		local enable = yesno ( args )
   211 		if enable == nil then
   206 		if enable == nil then
   212 			if beep_enable then
   207 			if beep_enable then
   213 				print ( "Beep on message is enabled" )
   208 				print ( "Beep on message is enabled" )
   216 			end
   211 			end
   217 		else
   212 		else
   218 			beep_enable = enable
   213 			beep_enable = enable
   219 		end
   214 		end
   220 	end )
   215 	end )
   221 main.add_command ( 'cmd',
   216 main.command ( 'cmd',
   222 	function ( args )
   217 	function ( args )
   223 		local to = main.current_buddy ()
   218 		local to = main.current_buddy ()
   224 		main.run ( ('send_to -q %q $ %s'):format ( to, args ) )
   219 		main.run ( ('send_to -q %q $ %s'):format ( to, args ) )
   225 		main.bgread ( args,
   220 		main.bgread ( args,
   226 			function ( data )
   221 			function ( data )
   230 				else
   225 				else
   231 					return false
   226 					return false
   232 				end
   227 				end
   233 			end )
   228 			end )
   234 	end )
   229 	end )
   235 main.add_command ( 'exthelp',
   230 main.command ( 'exthelp',
   236 	function ( args )
   231 	function ( args )
   237 		if commands_help[args] then
   232 		if commands_help[args] then
   238 			print ( "\n /" .. args .. ' ' .. commands_help[args] )
   233 			print ( "\n /" .. args .. ' ' .. commands_help[args] )
   239 		else
   234 		else
   240 			print ( "No help for this command." )
   235 			print ( "No help for this command." )
   244 			end
   239 			end
   245 			print ( list:sub ( 1, -3 ) )
   240 			print ( list:sub ( 1, -3 ) )
   246 			print ( "For built-in mcabber commands see /help" )
   241 			print ( "For built-in mcabber commands see /help" )
   247 		end
   242 		end
   248 	end )
   243 	end )
   249 main.add_command ( 'reload',
   244 main.command ( 'reload',
   250 	function ( args )
   245 	function ( args )
   251 		dofile ( main.config_file ( 'mcabberrc.lua' ) )
   246 		dofile ( main.config_file ( 'mcabberrc.lua' ) )
   252 	end )
   247 	end )
   253 main.add_command ( 'join!',
   248 main.command ( 'join!',
   254 	function ( args )
   249 	function ( args )
   255 		main.run ( 'room join ' .. main.current_buddy () )
   250 		main.run ( 'room join ' .. main.current_buddy () )
   256 	end )
   251 	end )
   257 main.add_command ( 'count',
   252 main.command ( 'count',
   258 	function ( args )
   253 	function ( args )
   259 		local count = 0
   254 		local count = 0
   260 		for resource in pairs ( main.buddy_info ( main.current_buddy () ).resources ) do
   255 		for resource in pairs ( main.buddy_info ( main.current_buddy () ).resources ) do
   261 			count = count + 1
   256 			count = count + 1
   262 		end
   257 		end
   263 		print ( "Resource count: " .. count )
   258 		print ( "Resource count: " .. count )
   264 	end )
   259 	end )
   265 
   260 
   266 for k, arg in ipairs ( { ')', '/', '(', 'D', '-/', 'S', '1', ']', '[' } ) do
   261 for k, arg in ipairs ( { ')', '/', '(', 'D', '-/', 'S', '1', ']', '[' } ) do
   267 	main.add_command ( arg,
   262 	main.command ( arg,
   268 		function ( args )
   263 		function ( args )
   269 			main.run ( 'say :' .. arg .. ' ' .. args )
   264 			main.run ( 'say :' .. arg .. ' ' .. args )
   270 		end )
   265 		end )
   271 end
   266 end
   272 
   267 
   322 	end
   317 	end
   323 	h:write ( "}\n" )
   318 	h:write ( "}\n" )
   324 	h:close ()
   319 	h:close ()
   325 end
   320 end
   326 
   321 
   327 main.add_command ( 'delay',
   322 main.command ( 'delay',
   328 	function ( args )
   323 	function ( args )
   329 		args = parse_args ( args )
   324 		args = parse_args ( args )
   330 		local who
   325 		local who
   331 		if args.t then
   326 		if args.t then
   332 			who = args.t
   327 			who = args.t
   341 			function ()
   336 			function ()
   342 				main.run ( 'say_to -q ' .. who .. ' ' .. rebuild_args_string ( args ) )
   337 				main.run ( 'say_to -q ' .. who .. ' ' .. rebuild_args_string ( args ) )
   343 			end
   338 			end
   344 	end )
   339 	end )
   345 
   340 
   346 main.add_command ( 'job',
   341 main.command ( 'job',
   347 	function ( args )
   342 	function ( args )
   348 		local action, jid, stat = args:match ( "(%w+)%s+(%w+)%s+(%w)" )
   343 		local action, jid, stat = args:match ( "(%w+)%s+(%w+)%s+(%w)" )
   349 		if action == 'del' then
   344 		if action == 'del' then
   350 			delayed_jobs[jid][stat] = nil
   345 			delayed_jobs[jid][stat] = nil
   351 		else
   346 		else