EionRobb / purple-discord

A libpurple/Pidgin plugin for Discord
GNU General Public License v3.0
381 stars 43 forks source link

[ FEATURE REQUEST ] purple-remote/purple-send documentation #377

Closed klikevil closed 3 years ago

klikevil commented 3 years ago

OS: gentoo software: Finch 2.13.0 (f07927902113041d6fa291293d9205ea4f05e9e6) order ~/h4x # ls -lash /usr/lib64/purple-2/libdiscord.so 792K -rwxr-xr-x. 1 root root 792K Sep 23 09:26 /usr/lib64/purple-2/libdiscord.so order ~/h4x # md5sum !$ md5sum /usr/lib64/purple-2/libdiscord.so 9828797d49339f1c2954c9e1cde491b6 /usr/lib64/purple-2/libdiscord.so

I'm not sure if I am just doing this wrong or what, I cannot seem to get purple-remote to send statuses.

This is the function i use to wrap purple remote and I launch finch with 'dbus-run-session finch'

purple-remote () 
{ 
    env "$(cat /proc/$(pgrep -n -P $(pgrep -f dbus-run-session.finch))/environ |tr '\0' '\n' | grep --color=never -i ^dbus)" /usr/bin/purple-remote "$@"
}

purple-remote can getstatus

order ~/h4x # purple-remote getstatus 2>/dev/null
away

But oddly it cannot seem to get active accounts

order ~/h4x # purple-remote 'PurpleAccountsFindConnected?protocol=prpl-discord&name=' 2>/dev/null
0
order ~/h4x #
order ~/h4x # DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-dY4KG6TfgT,guid=367dbd87d88f30c640b18d4861886bb1 purple-remote 
 'discord:goim?screenname=periodaltfinch#3690&message=message'
python-exec: Invalid impl in /etc/python-exec/python-exec.conf: python3.9
Traceback (most recent call last):
  File "/usr/bin/purple-remote", line 109, in findaccount
    account = cpurple.PurpleAccountsFindConnected(accountname, protocolname)
  File "/usr/bin/purple-remote", line 49, in __call__
    (self.attr, args, result))
Exception: Error: PurpleAccountsFindConnected ('', 'prpl-discord') returned 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/purple-remote", line 249, in <module>
    output = execute(arg)
  File "/usr/bin/purple-remote", line 137, in execute
    account = findaccount(accountname, protocol)
  File "/usr/bin/purple-remote", line 113, in findaccount
    account = cpurple.PurpleAccountsFindAny(accountname, protocolname)
  File "/usr/bin/purple-remote", line 49, in __call__
    (self.attr, args, result))
Exception: Error: PurpleAccountsFindAny ('', 'prpl-discord') returned 0

purple-send seems to be able to return something:

order ~/h4x # purple-send PurpleAccountsFindConnected string: string:prpl-discord
method return time=1636333550.408058 sender=:1.0 -> destination=:1.27 serial=2470 reply_serial=2
   int32 0

Anyway I was wondering if you could help me out with the correct syntax or documentation for purple-send/purple-remote for your discord plugin thanks a million!

EionRobb commented 3 years ago

Ah, so the protocol is prpl-eionrobb-discord (since it's not a built-in protocol, they get namespaced with the author of the plugin, generally)

The discord:goim syntax won't work with the plugin, since that's trying to do some uri handling, but the plugin doesn't have any uri's to handle

klikevil commented 3 years ago

Ah sweet!

purple-remote 'PurpleAccountsFindConnected?name=&protocol=prpl-eionrobb-discord' 2>/dev/null

229

Well that solved part of my question, would be cool to have some purple-remote/purple-send features documented for sending messages to others to this, but I understand that I'm probably like the only person that is asking for this so if you want to close it with prejudice you are more than welcome to. I really appreciate all your hard work on the project, it always impresses everyone seeing discord inside a console LOL.

  1. Add (or document if it already exists) the capability for sending messages via purple-remote/purple-send

From the looks of it, the goim will TRY to work, but it gives some weird results.

purple-remote attempted message send. image

This user isn't directly on my friend's list but we are in mutual servers. image

What I'm betting it is having trouble with is the 'discriminator'

image

image

Because manually through finch I can pull this information it just appears to be struggling with it when sent over the message bus for whatever reason.

image

All other functionalities work normally, can message this user fine without being mutual friends.

image

klikevil commented 3 years ago

Figured it out gotta use %23 instead of # in the discriminator, thanks so much for your help @EionRobb !!

For anyone trying to figure out sending messages on discord via purple-remote the following works:

convert_to_bytecode () 
{ 
    if [[ ! -x $(which hexdump) ]]; then
        echo "Doesn't have hexdump, in PATH, bailing out." && return 1;
    else
        if [[ ! -n $(sed --help |& grep -i regexp.extended) ]]; then
            echo "You are using a non-gnu version of sed that does not support extended regular  expressions and i am too lazy to write the check for this and make it switch to perl, bailing out." && return 1;
        fi;
    fi && if [[ $# -lt 1 ]] && [[ ! -p /dev/fd/0 ]]; then
        echo -e "Input what you want converted to hex followed by EOF [ ^D ] ( ctrl + d )\n";
        cat - | hexdump -x | awk '{$1="";if($0) print $0}' | sed -re 's/([a-fA-F0-9]{2})([a-fA-F0-9]{2})/\\x\2\\x\1/g;s/\s//g' | tr -d '\n';
        echo;
    else
        if [[ $# -gt 0 ]]; then
            local shit_to_gethex=($@);
        fi;
        ( if [[ ! -z ${shit_to_gethex[@]} ]]; then
            echo -ne "${shit_to_gethex[@]}";
        else
            cat -;
        fi ) | hexdump -x | awk '{$1="";if($0) print $0}' | sed -re 's/([a-fA-F0-9]{2})([a-fA-F0-9]{2})/\\x\2\\x\1/g;s/\s//g' | tr -d '\n';
        echo;
    fi
}

export username=their_user_name
export discriminator=their_4_digit_id
FOO=$(echo -e $'message' | convert_to_bytecode | sed -e 's/.x/%/g' -e 's/%00//g')
purple-remote "eionrobb-discord:goim?message=${FOO}&screenname=${username}%23${discriminator}"

I have not been able to figure out how to get chat messages to send though.