Last active
August 29, 2015 14:15
-
-
Save rosshadden/8eaf321b1fe52acba72c to your computer and use it in GitHub Desktop.
Send IMs with Pidgin/Finch's DBUS interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env python3 | |
import dbus | |
bus = dbus.SessionBus() | |
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") | |
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") | |
# get list of accounts | |
accounts = purple.PurpleAccountsGetAll() | |
buddies = {} | |
for accountId in accounts: | |
# get list of buddies for an account | |
buddyIds = purple.PurpleFindBuddies(accountId, "") | |
for buddyId in buddyIds: | |
buddy = { | |
"id": buddyId, | |
"name": purple.PurpleBuddyGetName(buddyId), | |
"alias": purple.PurpleBuddyGetAlias(buddyId), | |
"accountId": accountId | |
} | |
# NOTE: this overwrites users if they are in multiple protocols | |
buddies[buddy["alias"]] = buddy | |
# Let's say I want to send a message to `bud`, which is some entry in `buddies` | |
def sendIm(buddy, message): | |
# First we make a new conversation | |
# (I think the `1` in the first arg is "IM", and a 2 would be "chat"...? | |
conversationId = purple.PurpleConversationNew(1, buddy["accountId"], buddy["name"]) | |
# Next we make a new IM out of the conversation (yep...) | |
imId = purple.PurpleConvIm(conversationId) | |
# Finally we send the IM | |
purple.PurpleConvImSend(imId, message) | |
# Let's try with Drew | |
drew = buddies["Andrew Oppenlander"] | |
sendIm(drew, "Why, hello there!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment