Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Pushbullet Integration
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Wyth
(5 posts) Bio
|
Date
| Wed 02 Mar 2016 01:17 AM (UTC) |
Message
| First off, if this all seems incredibly janky, I apologize. At this point my brain is kind of fried. I'd like to set up pushbullet notifications where if someone says my name on a specific channel, it will push that line to me.
I was originally trying to do it just in lua, but was having a hell of a time getting https (which is required by pushbullet) to work. After wasting a lot of time there, I decided to move on and just figure out how to have the trigger execute a shell script which I know will work. So I set it up to pass a parameter on.
Here is the trigger I'm using:
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^(.+) gossip \'.*(wyth|Wyth|WythDryden).*\'$"
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "%0", nil, nil, 0))</send>
</trigger>
</triggers>
and this is the shell script I'm using:
!/bin/bash
# The API Key
API_KEY="####################"
# Note Title
NOTE_TITLE="Emperia"
# Body of the Message
BODY="$1"
curl -k -u "$API_KEY": https://api.pushbullet.com/v2/pushes -d device_iden=#################### -d type=note -d title="$NOTE_TITLE" -d body="$BODY"
The trigger will successfully go off, but when I receive the pushbullet notification it only sends the first word on the line. I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word which is picked up at the $1 in the script. I tried using $a in the script but that didn't work. I also tried putting '' in various spots to no avail. Maybe it's a really easy thing I'm overlooking, or maybe it's not possible, but at this point I can't wrap my brain around it. Would anyone perhaps be able to shed some insight into which direction I should go in? | Top |
|
Posted by
| Wuggly
USA (112 posts) Bio
|
Date
| Reply #1 on Wed 02 Mar 2016 03:56 AM (UTC) |
Message
| I'm a Lua newbie so I'm just saying this to perhaps help your line of thinking into figuring this out until one of the superhero's show up.
I notice in the trigger you have two groupings.
(.+) and (wyth|Wyth|WythDryden)
The first one would account for the $1, however I know nothing about shell scripting so I could be wrong on that, but in lua %1 is the first wildcard and makes sense why you are only getting one word as that's the only wildcard being passed along to the shell.
Maybe make a trigger to capture everything and use an if statement to pass it on? | Top |
|
Posted by
| Wyth
(5 posts) Bio
|
Date
| Reply #2 on Wed 02 Mar 2016 04:08 AM (UTC) |
Message
|
Wuggly said:
I'm a Lua newbie so I'm just saying this to perhaps help your line of thinking into figuring this out until one of the superhero's show up.
I notice in the trigger you have two groupings.
(.+) and (wyth|Wyth|WythDryden)
The first one would account for the $1, however I know nothing about shell scripting so I could be wrong on that, but in lua %1 is the first wildcard and makes sense why you are only getting one word as that's the only wildcard being passed along to the shell.
Maybe make a trigger to capture everything and use an if statement to pass it on?
Well in the trigger itself I'm actually using %0 to use the entire line, and not just the phrase that triggers it. If I try changing the shell script to use $0 instead of $1 then the string sent in the pushbullet note is actually the file/filepath of the script itself.
Also, for the record, if I try sending an entire string with "" from the command line it works.
C:\Users\Wyth\Desktop>sh pushbullet.sh "This is a string." | Top |
|
Posted by
| Wuggly
USA (112 posts) Bio
|
Date
| Reply #3 on Wed 02 Mar 2016 04:15 AM (UTC) Amended on Wed 02 Mar 2016 04:21 AM (UTC) by Wuggly
|
Message
| Have you tried putting it into a variable then pass the variable to the shell?
So it's like this..
<send>
matched_line = "%0"
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", matched_line, nil, nil, 0))
</send>
My line of thinking is since it's passing the whole line, that maybe it's passing along the wildcards too and perhaps putting it into a variable will put those matches into the string. | Top |
|
Posted by
| Wyth
(5 posts) Bio
|
Date
| Reply #4 on Wed 02 Mar 2016 04:41 AM (UTC) |
Message
|
Wuggly said:
Have you tried putting it into a variable then pass the variable to the shell?
So it's like this..
<send>
matched_line = "%0"
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", matched_line, nil, nil, 0))
</send>
I did try that, and unfortunately it doesn't make a difference.
I'm pretty certain that the %0 is catching the whole line:
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^(.+) gossip \'.*(wyth|Wyth|WythDryden).*\'$"
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "%0", nil, nil, 0))
print("%0")</send>
</trigger>
</triggers>
<4249/11517 36hp 2409/2409 100m 811/1586 2502tnl 7105hps>
go wyth saying a thing
You gossip 'wyth saying a thing'
<4252/11517 36hp 2409/2409 100m 823/1586 2502tnl 7105hps>
The "You gossip 'wyth saying a thing'" is printed from %0. But the body of the pushbullet message sends only the word 'You'. I'm pretty sure this would be an easy solve if I had the syntax of the shellexecute correct to send the entire string as a parameter within "", (which is working if I do that manually from a prompt) but I can't seem to figure it out right now. Also, the window does pop up when running and then disappears when it's done, despite putting the "0" at the end of the command. So this also leads me to believe my syntax might be the problem.
Also, thanks for taking the time to reply. I'd try to get back to you sooner, but the forum software will only let me respond like every 20 minutes. I thought I had an account here before from all the lurking I did, but apparently I didn't. | Top |
|
Posted by
| Wuggly
USA (112 posts) Bio
|
Date
| Reply #5 on Wed 02 Mar 2016 05:01 AM (UTC) Amended on Wed 02 Mar 2016 05:37 AM (UTC) by Wuggly
|
Message
| Have you tried using %10 in the trigger instead of %0?
While reviewing the triggers page.
http://www.gammon.com.au/scripts/doc.php?general=triggers
I saw this..
Quote: Wildcard 10 is the entire matching sequence, which is not necessarily the same as the matching line in the case of regular expressions.
Then of course the %0 is...
Quote: Wildcard subscript 0 is the entire matching line.
EDIT: Actually I believe that would only make it worse since you are using a regex.
Plus since you said
Wyth said:
The "You gossip 'wyth saying a thing'" is printed from %0.
which means everything lua-wise is doing it's job. Seems more likely a shell scripting problem. Maybe you'll luck out with someone here who also knows shell or you could always ask at the stackexchange website. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #6 on Wed 02 Mar 2016 05:48 AM (UTC) |
Message
|
Quote:
I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word ...
You could embed quotes, eg.
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "\"%0\"", nil, nil, 0))
Not sure if that will help.
Quote:
Have you tried using %10 in the trigger instead of %0?
The 10th wildcard would be %<10> |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Wyth
(5 posts) Bio
|
Date
| Reply #7 on Wed 02 Mar 2016 07:26 AM (UTC) |
Message
|
Nick Gammon said:
Quote:
I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word ...
You could embed quotes, eg.
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "\"%0\"", nil, nil, 0))
Not sure if that will help.
Quote:
Have you tried using %10 in the trigger instead of %0?
The 10th wildcard would be %<10>
Thank you! I knew it had to be some manner of that syntax, I kept messing around with it, but with single ' and double ". My brain was just fried, but that makes perfect sense. My only other question is that the window still pops up to run the script, even though I am passing 0 as the 5th argument. Any idea why?
Thanks again in advance! | Top |
|
Posted by
| Wuggly
USA (112 posts) Bio
|
Date
| Reply #8 on Wed 02 Mar 2016 06:18 PM (UTC) |
Message
| |
Posted by
| Wyth
(5 posts) Bio
|
Date
| Reply #9 on Wed 02 Mar 2016 06:25 PM (UTC) |
Message
|
It produces the same effect. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
26,272 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top