Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Lua discord webhook inegration

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Bricked-Wall
How do I cheat?
Reputation: 0

Joined: 30 Mar 2023
Posts: 6

PostPosted: Thu Mar 30, 2023 2:44 pm    Post subject: Lua discord webhook inegration Reply with quote

So, I'm trying to send a message through a discord webhook using lua in cheat engine.
Problem is, this script always generates the error "Failed to send message: Could not connect to server. ". If anyone can help with this, that would be much appreciated!
PS: I have all the external librarires required downloaded but its just not going through.

Code:

-- Define the Discord webhook URL
local webhook_url = "(Redacted to avoid spammers)"

-- Define the message to send
local message = {
  content = "Hello from Lua!",
  username = "Lua Bot",
  avatar_url = "https://lua.org/images/lua-logo.png"
}

-- Encode the message as JSON
local json = require("json") -- Assuming you have a separate json.lua file
local message_json = json.encode(message)

-- Send the message to the webhook URL
local response_body = {}
local result, response_code = getInternet().postURL(webhook_url, message_json, {
  ["Content-Type"] = "application/json",
  ["Content-Length"] = tostring(#message_json)
}, response_body)

-- Check if the request was successful
if result and response_code and response_code == 204 then
  print("Message sent successfully!")
elseif not response_code then
  print("Failed to send message: Could not connect to server.")
else
  print("Failed to send message:")
  print("  Response code: " .. tostring(response_code))
  print("  Response body:")
  print(table.concat(response_body))
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Mar 30, 2023 3:41 pm    Post subject: Reply with quote

postURL only takes the url and the encoded data, and it only returns the data, no response codes or whatever

(let me guess, chatGPT? )

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu Mar 30, 2023 3:44 pm    Post subject: Reply with quote

This is like a dream..

Code:
local response_body = {}
local result, response_code = getInternet().postURL(webhook_url, message_json, {
  ["Content-Type"] = "application/json",
  ["Content-Length"] = tostring(#message_json)
}, response_body)


The facts are;
The platform you're trying to post on provides a "Login" requirement. It also does not allow "Spam" entries, account security policy is high. So remote access is a dream.

Finally; You never made any reference to "php" in your code. Take this into account.

And my advice is to choose a platform that is free and does not require login (Or you can chat with your own site php code).

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Bricked-Wall
How do I cheat?
Reputation: 0

Joined: 30 Mar 2023
Posts: 6

PostPosted: Thu Mar 30, 2023 4:37 pm    Post subject: Lua discord webhook inegration C code Reply with quote

Dark Byte wrote:
postURL only takes the url and the encoded data, and it only returns the data, no response codes or whatever

(let me guess, chatGPT? )


I see and yeah, gpt.

I'm wondering, if that won't work, would something like this be possible?
Code:
 {$c}
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main() {
    CURL *curl;
    CURLcode res;

    char *webhook_url = "Webhook here";
    char *message = "{\"content\": \"Webhook confirmation.\"}";

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, webhook_url);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, message);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

        curl_easy_cleanup(curl);
    }
    return 0;
}


This however generates the error: "In file included from include/curl/curl.h:54: include/curl/system.h:440: error: include file 'sys/socket.h' not found"
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Mar 30, 2023 4:39 pm    Post subject: Reply with quote

you need to implement the socket header yourself

anyhow, getInternet with postURL or even getURL will very likely work, you just need to understand what you're doing. (Read this: https://discord.com/developers/docs/resources/webhook and try to understand the API)

I do recommend hosting your own webserver if logins are needed (e.g oauth needs to callback on a server and an app alone can't do that) or any other callback.

that way you can also write wrapper scripts that work as an interface between CE and discord

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Bricked-Wall
How do I cheat?
Reputation: 0

Joined: 30 Mar 2023
Posts: 6

PostPosted: Thu Mar 30, 2023 5:03 pm    Post subject: Reply with quote

Dark Byte wrote:
you need to implement the socket header yourself

anyhow, getInternet with postURL or even getURL will very likely work, you just need to understand what you're doing. (Read this: discordcom/developers/docs/resources/webhook and try to understand the API)

I do recommend hosting your own webserver if logins are needed (e.g oauth needs to callback on a server and an app alone can't do that) or any other callback.

that way you can also write wrapper scripts that work as an interface between CE and discord


Okay i see. Final question, when trying to use luasocket this error always pops up: Error:error loading module 'socket.core' from file 'C:\Program Files\Cheat Engine 7.5\clibs64\socket\core.dll':

the core.dll is in that folder. Is it not working due to the lua version being 5.3?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Mar 30, 2023 5:04 pm    Post subject: Reply with quote

yes, you need to update luasocket to work with ce's lua naming scheme
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Bricked-Wall
How do I cheat?
Reputation: 0

Joined: 30 Mar 2023
Posts: 6

PostPosted: Thu Apr 06, 2023 12:36 pm    Post subject: Final Reply with quote

For those wondering how it worked out, I decided to instead make an application with node.js and then execute it through the Trainer. Much simpler
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites