Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
64f8a222
Unverified
Commit
64f8a222
authored
Feb 06, 2020
by
Victor Huang
Committed by
GitHub
Feb 06, 2020
Browse files
Add support for CQHTTP QQ bot API
parent
8e6c4e1a
Changes
1
Show whitespace changes
Inline
Side-by-side
notify/cqhttp.sh
0 → 100644
View file @
64f8a222
#!/bin/bash
#Support for CQHTTP api. Push notification on CoolQ
#CQHTTP_TOKEN="" Required, QQ application token
#CQHTTP_USER="" Required, QQ reciever ID
#CQHTTP_APIROOT="" Required, CQHTTP Server URL (without slash suffix)
#CQHTTP_CUSTOM_MSGHEAD="" Optional, custom message header
CQHTTP_APIPATH
=
"/send_private_msg"
cqhttp_send
()
{
_subject
=
"
$1
"
_content
=
"
$2
"
_statusCode
=
"
$3
"
#0: success, 1: error 2($RENEW_SKIP): skipped
_debug
"_statusCode"
"
$_statusCode
"
CQHTTP_TOKEN
=
"
${
CQHTTP_TOKEN
:-
$(
_readaccountconf_mutable CQHTTP_TOKEN
)
}
"
if
[
-z
"
$CQHTTP_TOKEN
"
]
;
then
CQHTTP_TOKEN
=
""
_err
"You didn't specify a CQHTTP application token yet. If it's empty please pass
\"
__ACME_SH_TOKEN_EMPTY__
\"
(without quote)."
return
1
fi
_saveaccountconf_mutable CQHTTP_TOKEN
"
$CQHTTP_TOKEN
"
if
[
"
$CQHTTP_TOKEN
"
=
"__ACME_SH_TOKEN_EMPTY__"
]
;
then
CQHTTP_TOKEN
=
""
fi
CQHTTP_USER
=
"
${
CQHTTP_USER
:-
$(
_readaccountconf_mutable CQHTTP_USER
)
}
"
if
[
-z
"
$CQHTTP_USER
"
]
;
then
CQHTTP_USER
=
""
_err
"You didn't specify a QQ user yet."
return
1
fi
_saveaccountconf_mutable CQHTTP_USER
"
$CQHTTP_USER
"
CQHTTP_APIROOT
=
"
${
CQHTTP_APIROOT
:-
$(
_readaccountconf_mutable CQHTTP_APIROOT
)
}
"
if
[
-z
"
$CQHTTP_APIROOT
"
]
;
then
CQHTTP_APIROOT
=
""
_err
"You didn't specify a QQ user yet."
return
1
fi
_saveaccountconf_mutable CQHTTP_APIROOT
"
$CQHTTP_APIROOT
"
CQHTTP_APIROOT
=
"
${
CQHTTP_APIROOT
:-
$(
_readaccountconf_mutable CQHTTP_APIROOT
)
}
"
if
[
-z
"
$CQHTTP_APIROOT
"
]
;
then
CQHTTP_APIROOT
=
""
_err
"You didn't specify a QQ user yet."
return
1
fi
_saveaccountconf_mutable CQHTTP_APIROOT
"
$CQHTTP_APIROOT
"
CQHTTP_CUSTOM_MSGHEAD
=
"
${
CQHTTP_CUSTOM_MSGHEAD
:-
$(
_readaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD
)
}
"
if
[
-z
"
$CQHTTP_CUSTOM_MSGHEAD
"
]
;
then
CQHTTP_CUSTOM_MSGHEAD
=
"A message from acme.sh:"
else
_saveaccountconf_mutable CQHTTP_CUSTOM_MSGHEAD
"
$CQHTTP_CUSTOM_MSGHEAD
"
fi
_access_token
=
"
$(
printf
"%s"
"
$CQHTTP_TOKEN
"
| _url_encode
)
"
_user_id
=
"
$(
printf
"%s"
"
$CQHTTP_USER
"
| _url_encode
)
"
_message
=
"
$(
printf
"
$CQHTTP_CUSTOM_MSGHEAD
%s
\\
n%s"
"
$_subject
"
"
$_content
"
| _url_encode
)
"
_finalUrl
=
"
$CQHTTP_APIROOT$CQHTTP_APIPATH
?access_token=
$_access_token
&user_id=
$_user_id
&message=
$_message
"
response
=
"
$(
_get
"
$_finalUrl
"
)
"
if
[
"
$?
"
=
"0"
]
&&
_contains
"
$response
"
"
\"
retcode
\"
:0,
\"
status
\"
:
\"
ok
\"
"
;
then
_info
"QQ send success."
return
0
fi
_err
"QQ send error."
_err
"URL:
$_finalUrl
"
_err
"Response:
$response
"
return
1
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment