File: adccommands.lua

package info (click to toggle)
eiskaltdcpp 2.2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,372 kB
  • ctags: 12,362
  • sloc: cpp: 94,068; ansic: 8,832; perl: 1,523; xml: 1,378; sh: 685; php: 661; makefile: 101
file content (38 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--// adccommands.lua: rev005/20080510
--// adccommands.lua: Let you change your nick on ADC hubs

local adccommands = {}

function adccommands.tokenize(text)
	local ret = {}
	string.gsub(text, "([^ ]+)", function(s) table.insert(ret, s) end )
	return ret
end

function adccommands.changeNick(hub, newnick)
	local sid = hub:getOwnSid()
	newnick = dcu:AdcEscape(newnick)
	DC():SendHubMessage( hub:getId(), "BINF " .. sid .. " NI" .. newnick .. "\n" )
end

dcpp:setListener( "ownChatOut", "adccommands",
	function( hub, text )
		if (hub:getProtocol() == "adc" and string.sub(text, 1, 1) == "/") then
			local params = adccommands.tokenize(text)
			if params[1] == "/help" then
				hub:addLine( "(adccommands.lua) /nick <nick>", true )
				return nil
			elseif params[1] == "/nick" then
				if params[2] then
					adccommands.changeNick(hub, string.sub(text, 7))
					return true
				else
					hub:addLine("Usage: /nick <nick>")
					return true
				end
			end
		end
	end
)

DC():PrintDebug( "  ** Loaded adccommands.lua **" )