Skip to content

Commit

Permalink
Bug fixes fo og_Data and url image thumbs nails
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzoneill committed Oct 5, 2024
1 parent 17f5f96 commit 95bf6a9
Show file tree
Hide file tree
Showing 9 changed files with 913 additions and 680 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
**/strategies/FilipinoCupid.js
**/strategies/Pornhub.js
**/strategies/backup/**
**/Session Storage/**
**/state.json
# end managed by open-wa
55 changes: 35 additions & 20 deletions MessageStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class MessageStrategy {
static http_cache_folder = 'strategies/http_cache_folder'
static browser_config = browserConfig;
static flags = worldFlags;
static chuckclient = null;

static client = {
client: null,
log: function () {
// let output = new Error().stack.toString().match(/at \w+\.\w+/)[0].split('.')[1].padEnd(20, ' ');
// for (let u = 0; u < arguments.length; u++) {
Expand All @@ -81,72 +81,71 @@ class MessageStrategy {
sendText: function sendText() {
const args = Array.from(arguments)
this.log(args[0], args[1])
return this.client.sendText(args[0], args[1])
return MessageStrategy.chuckclient.sendText(args[0], args[1])
},
sendImage: function sendImage() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3])
return this.client.sendImage(args[0], args[1], args[2], args[3])
return MessageStrategy.chuckclient.sendImage(args[0], args[1], args[2], args[3])
},
sendLinkWithAutoPreview: function sendLinkWithAutoPreview() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3])
return this.client.sendLinkWithAutoPreview(args[0], args[1], args[2], args[3])
return MessageStrategy.chuckclient.sendLinkWithAutoPreview(args[0], args[1], args[2], args[3])
},
sendMessageWithThumb: function sendMessageWithThumb() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3], args[4], args[5])
console.log("send message with thumb")
return this.client.sendMessageWithThumb(args[0], args[1], args[2], args[3], args[4], args[5])
return MessageStrategy.chuckclient.sendMessageWithThumb(args[0], args[1], args[2], args[3], args[4], args[5])
},
reply: function reply() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3])
return this.client.reply(args[0], args[1], args[2], args[3])
return MessageStrategy.chuckclient.reply(args[0], args[1], args[2], args[3])
},
getAllChats: function getAllChats() {
const args = Array.from(arguments)
return this.client.getAllChats()
return MessageStrategy.chuckclient.getAllChats()
},
getAllGroups: function getAllGroups() {
const args = Array.from(arguments)
this.log(args[0], args[1])
return this.client.getAllGroups(args[0], args[1])
return MessageStrategy.chuckclient.getAllGroups(args[0], args[1])
},
getGroupMembers: function getGroupMembers() {
const args = Array.from(arguments)
this.log(args[0])
return this.client.getGroupMembers(args[0])
return MessageStrategy.chuckclient.getGroupMembers(args[0])
},
sendYoutubeLink: function sendYoutubeLink() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3])
return this.client.sendYoutubeLink(args[0], args[1], args[2], args[3])
return MessageStrategy.chuckclient.sendYoutubeLink(args[0], args[1], args[2], args[3])
},
decryptMedia: function decryptMedia() {
const args = Array.from(arguments)
this.log(args[0])
return this.client.decryptMedia(args[0])
return MessageStrategy.chuckclient.decryptMedia(args[0])
},
sendFile: function sendFile() {
const args = Array.from(arguments)
this.log(args[0], args[1], args[2], args[3])
return this.client.sendFile(args[0], args[1], args[2], args[3])
return MessageStrategy.chuckclient.sendFile(args[0], args[1], args[2], args[3])
},
sendSeen: function sendSeen() {
const args = Array.from(arguments)
this.log(args[0])
return this.client.sendSeen(args[0])
return MessageStrategy.chuckclient.sendSeen(args[0])
},
simulateTyping: function simulateTyping() {
const args = Array.from(arguments)
this.log(args[0], args[1])
return this.client.simulateTyping(args[0], args[1])
return MessageStrategy.chuckclient.simulateTyping(args[0], args[1])
},
leaveGroup: function leaveGroup() {
const args = Array.from(arguments)
this.log(args[0])
return this.client.leaveGroup(args[0])
return MessageStrategy.chuckclient.leaveGroup(args[0])
}
}

Expand Down Expand Up @@ -300,7 +299,7 @@ class MessageStrategy {

if (module.provides == null) continue

console.log(" >> " + keys[y])
console.log(" >> trying: " + keys[y])

const actions_keys = Object.keys(module.provides)
for (let x = 0; x < actions_keys.length; x++) {
Expand Down Expand Up @@ -329,11 +328,11 @@ class MessageStrategy {
}

let action_result = action_obj.action(message)
console.log(" >>>> " + keys[y] + " - " + actions_keys[x])
console.log(" >>>> Activated: " + keys[y] + " - " + actions_keys[x])
action_result = action_result == undefined ? false : action_result

if (action_result) {
console.log("break")
console.log("Actioned: ")
console.log(action_result)
y = keys.length
break
Expand Down Expand Up @@ -478,6 +477,23 @@ class MessageStrategy {

browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true })
const page = await browser.newPage()
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36');
await page.setExtraHTTPHeaders({
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
'pragma': 'no-cache',
'sec-ch-ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
'upgrade-insecure-requests': '1',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'dnt': '1'
});

await page.goto(fullurl)
await page.setViewport({ width: 1366, height: 768 })

Expand Down Expand Up @@ -531,7 +547,6 @@ class MessageStrategy {
}

const data = await page.evaluate(() => document.querySelector('*').outerHTML);
// console.log(data)

const description = await page.evaluate(() => {
const desc = document.head.querySelector('meta[property="og:description"]')
Expand Down
28 changes: 2 additions & 26 deletions chuckbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ class ChuckBot {
static source_dir = './'
static chuck = null
static Strategies = null
static chuck_express = null
static message_strategy_file = './MessageStrategy.js'
static web_file = './web.js'
static last_update = new Date(0)

constructor () {
fs.watch(ChuckBot.source_dir, (event, filename) => {
if (filename == ChuckBot.message_strategy_file.substring(2) || filename == ChuckBot.web_file.substring(2)) {
if (filename == ChuckBot.message_strategy_file.substring(2)) {
if (ChuckBot.last_update.valueOf() == Date.now()) {
return
}
ChuckBot.update_strategies()
ChuckBot.update_web()
ChuckBot.last_update = Date.now()
}
})
Expand Down Expand Up @@ -47,7 +44,6 @@ class ChuckBot {
static start (client) {
ChuckBot.chuck = client
ChuckBot.update_strategies()
ChuckBot.update_web()

const event_message = {
id: 'chuck',
Expand Down Expand Up @@ -97,29 +93,9 @@ class ChuckBot {
static async update_strategies () {
delete require.cache[require.resolve(ChuckBot.message_strategy_file)]
ChuckBot.Strategies = require(ChuckBot.message_strategy_file)
ChuckBot.Strategies.client.client = ChuckBot.chuck
ChuckBot.Strategies.chuckclient = ChuckBot.chuck
ChuckBot.Strategies.update_strategies()
}

static async update_web () {
try {
await new Promise(r => setTimeout(r, 1000))

if (ChuckBot.chuck_express != null) {
ChuckBot.chuck_express.stop()
await new Promise(r => setTimeout(r, 1000))
ChuckBot.chuck_express = null
}

delete require.cache[require.resolve(ChuckBot.web_file)]
const Web = require(ChuckBot.web_file)

ChuckBot.chuck_express = new Web.Web(ChuckBot.Strategies)
ChuckBot.chuck_express.launch(ChuckBot.Strategies)
} catch (err) {
console.log(err)
}
}
}

new ChuckBot()
Loading

0 comments on commit 95bf6a9

Please sign in to comment.