prepare python-dbus, python-gobject
#!/usr/bin/env python
import dbus
import os
from dbus.mainloop.glib import DBusGMainLoop
class CheckedObject:
def __init__(self, obj):
self.obj = obj
def __getattr__(self, attr):
return CheckedAttribute(self, attr)
class CheckedAttribute:
def __init__(self, cobj, attr):
self.cobj = cobj
self.attr = attr
def __call__(self, *args):
result = self.cobj.obj.__getattr__(self.attr)(*args)
if result == 0:
raise Exception("Error: %s %s returned %s" %
(self.attr, args, result))
return result
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
for a in purple.PurpleAccountsGetAllActive():
protocolName = purple.PurpleAccountGetProtocolName(a)
cmd="echo '{}' ".format(protocolName)
os.system(cmd)
if purple.PurpleAccountGetProtocolName(a) == 'Discord':
account = a
cmd="echo '{}' ".format(a)
os.system(cmd)
# account=396
name = purple.PurpleAccountGetUsername(account)
cmd="echo '{}' ".format(name)
os.system(cmd)
# for online in purple.PurpleFindBuddies( (purple.PurpleAccountsGetAllActive())[0], '' ):
for online in purple.PurpleFindBuddies( account, '' ):
cmd="echo '{}' ".format(online)
os.system(cmd)
name_buddy=purple.PurpleBuddyGetAlias( online ).encode('utf-8')
if name_buddy=='prapop':
cmd="echo '{}' ".format(name_buddy)
os.system(cmd)
break
buddy=purple.PurpleBuddyGetName( online )
cmd="echo '{}' ".format(buddy)
os.system(cmd)
conv = purple.PurpleConversationNew(1, account,buddy)
im = purple.PurpleConvIm(conv)
msg='test'
# purple.PurpleConvImSend(im, msg)
cpurple=CheckedObject(purple)
xx=cpurple.PurpleAccountGetConnection(account)
# msginfo=purple.ServGetInfo(33043,buddy)
cmd="echo '{}' ".format(xx)
os.system(cmd)