xchat command line remote control

Mon 11 October 2010

I use this as part of my 'lockit' script (which will be posted soon) to automatically set/unset my afk status for xchat.

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python

#Xchat/dbus based remote-control app for RHEL and Fedora

# howto use:
# xchat-command msg #helpdesk This is a test
#     - Send "This is a test" to the #helpdesk channel
# xchat-command afk
#    - Set self as NICK|afk
# xchat-command return
#    - Set self as NICK



import dbus, sys, re
bus = dbus.SessionBus()
object = bus.get_object("org.xchat.service", "/org/xchat/Remote")
xchat = dbus.Interface(object, "org.xchat.plugin")
oldStyle=False
command=sys.argv[1]

try:
    nickname=xchat.GetInfo("nick")
except:
    # Maybe we're using the old style
    try:
        object = bus.get_object("org.xchat.service", "/org/xchat/RemoteObject")
        xchat = dbus.Interface(object, "org.xchat.interface")
        nickname=xchat.GetInfo("nick")
        oldStyle=True
    except:
        print "xchat not running"
        sys.exit(1)


def setNick(newNick):
    if oldStyle:
        xchat.command('anick %s'%newNick)
    else:
        xchat.Command('anick %s'%newNick)


if command == "afk":
    if not re.compile("afk").search(nickname):
        newNick="%s|afk"%nickname
        setNick(newNick)    
        sys.exit(0)
    else:
        print "sorry, already afk"

if command == "return":
    oldNick,afk = nickname.rsplit('|')
    newNick=oldNick
    setNick(newNick)
    sys.exit(0)

for arg in sys.argv[2:]:
    command= "%s %s"%(command, arg)
print "Command is %s"%command
if oldStyle:
    xchat.command(command)
else:
    xchat.Command(command)

Category: Linux Tagged: bash irc linux scripting shell

Comments