CLEO Help Discord WebHooks

CLEO related
Status
Not open for further replies.
Joined
Mar 17, 2020
Messages
19
Reaction score
2
Location
Narnia
Hey everyone, last weeks I've been trying to find a way to notify an event that a cleo could detect via Discord WebHooks.
It would use "fetch" function, in order to send something like POST "this is the place for webhook URL" MESSAGE. I don't know if this function exists on winnet.dll or URLMon.dll. Using PHP as well as it is used for keyloggers, I think it would be possible.
@monday @Opcode.eXe
 
Joined
Mar 17, 2020
Messages
19
Reaction score
2
Location
Narnia
Thanks monday!
I've done this to test it, but when I press X it returns true but it doesn't post the message on Discord channel.
PHP:
{$CLEO}
0000: NOP

repeat
    wait 0
until 0AFA:

// URL
alloc 0@ 360
0AD3: 0@ = format "http:%c/discordapp.com/api/webhooks/750444435199754270/S7lOQN42X7qy5Iec435CjjmLWzwDtIZ1uJZRVIQjTgSZOg4UGSgZM_xJdpatwj6sxoDo" 47
// Response buffer
alloc 1@ 1500
alloc 3@ 260

// DATA
alloc 2@ 260
0AD3: 2@ = format "Test"
while true
    wait 0
    if and
    not SAMP.ChatInputOpened()
    0ADC: "X"
    then
        0AB1: call_scm_func @HTTP_POST 4 host 0@ file_path 3@ response_buffer 1@ data 2@ _ret_is_success 31@
        if
        31@ == true
        then
            chatmsg "Respuesta = %s" 0xFFFFFF 1@
        else
            chatmsg "Fail" -1
        end
    end
end
{$INCLUDE includes/http_requests.txt}
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
149
It looks like webhooks discord api requires to use https instead of plain http. The http_requests snippet didn't support it so I edited it, so I suggest to update "includes/http_requests.txt" with the new code from:
http://ugbase.eu/index.php?threads/http-requests-without-sampfuncs.21152/

I just tested it with the following code:
Code:
{$CLEO}
0000: NOP

repeat
    wait 0
until 0AFA:

// host
alloc 0@ 30
0AD3: 0@ = format "discordapp.com" 

// path
alloc 1@ 200
call @construct_path 1 1@ // reads discord.ini and stores result at 1@

// data
alloc 2@ 1000
//0AD3: 2@ = format "content=testing message"
0AD3: 2@ = format "content=testing message&username=custom_username"

// response buffer
alloc 3@ 1500

while true
    wait 0
    if and
    not SAMP.ChatInputOpened()
    0ADC: "X"
    then
        0AB1: call_scm_func @HTTP_POST 5 host 0@ file_path 1@ response_buffer 3@ data 2@ is_https true _ret_is_success 31@
        if
        31@ == true
        then
            chatmsg "Respuesta = %s" 0xFFFFFF 3@
        else
            chatmsg "Fail" -1
        end
    end
end

:construct_path
{ 
    Params:
    0@ - pointer to path
}
alloc 30@ 200
alloc 31@ 200
0AF4: 30@ = read_string_from_ini_file "cleo\discord.ini" section "my_server" key "webhook_channel_id"
0AF4: 31@ = read_string_from_ini_file "cleo\discord.ini" section "my_server" key "webhook_token"
0AD3: 0@ = format "api/webhooks/%s/%s" 30@ 31@
free 30@ 
free 31@
ret 0 

{$INCLUDE includes/http_requests.txt}

...and it posted the message successfully. Btw that's the conent of "cleo/discord.ini" file I used:
[my_server]
webhook_token=QlcGaANQF3lqGKsz8tiOC69lMh2Yx_h0Hb_ZUiboSpxPQoUfapXxcp-MgaTbiaHGYEYa
webhook_channel_id=752302451636140141

(Notice how "0AB1: call_scm_func @HTTP_POST 5 " now has 5 parameters instead of 4)
 

Attachments

  • 1599439709992.png
    1599439709992.png
    7.6 KB · Views: 98
Status
Not open for further replies.
Top