forked from fca-unofficial/fca-unofficial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added "getCurrentTimestamp()" * Added new methods. * Added types for new methods. * Create changeBlockedStatusMqtt.js * Create createPollMqtt.js * Create forwardMessage.js * Create pinMessage.js * Create sendTypingIndicatorMqtt.js * Create setMessageReactionMqtt.js * Create setTheme.js * Create unsendMessageMqtt.js
- Loading branch information
Nessie
authored
Mar 20, 2024
1 parent
8138b18
commit 0cbe674
Showing
11 changed files
with
765 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
const { generateOfflineThreadingID, getCurrentTimestamp, getGUID } = require('@xaviabot/fca-unofficial/utils'); | ||
|
||
function isCallable(func) { | ||
try { | ||
Reflect.apply(func, null, []); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = function (defaultFuncs, api, ctx) { | ||
return function changeBlockedStatusMqtt(userID, status, type, callback) { | ||
if (!ctx.mqttClient) { | ||
throw new Error('Not connected to MQTT'); | ||
} | ||
|
||
ctx.wsReqNumber += 1; | ||
ctx.wsTaskNumber += 1; | ||
|
||
const label = '334'; | ||
let userBlockAction = 0; | ||
|
||
switch (type) { | ||
case 'messenger': | ||
if (status) { | ||
userBlockAction = 1; // Block | ||
} else { | ||
userBlockAction = 0; // Unblock | ||
} | ||
break; | ||
case 'facebook': | ||
if (status) { | ||
userBlockAction = 3; // Block | ||
} else { | ||
userBlockAction = 2; // Unblock | ||
} | ||
break; | ||
default: | ||
throw new Error('Invalid type'); | ||
} | ||
|
||
const taskPayload = { | ||
blockee_id: userID, | ||
request_id: getGUID(), | ||
user_block_action: userBlockAction, | ||
}; | ||
|
||
const payload = JSON.stringify(taskPayload); | ||
const version = '25393437286970779'; | ||
|
||
const task = { | ||
failure_count: null, | ||
label: label, | ||
payload: payload, | ||
queue_name: 'native_sync_block', | ||
task_id: ctx.wsTaskNumber, | ||
}; | ||
|
||
const content = { | ||
app_id: '2220391788200892', | ||
payload: JSON.stringify({ | ||
tasks: [task], | ||
epoch_id: parseInt(generateOfflineThreadingID()), | ||
version_id: version, | ||
}), | ||
request_id: ctx.wsReqNumber, | ||
type: 3, | ||
}; | ||
|
||
if (isCallable(callback)) { | ||
ctx.reqCallbacks[ctx.wsReqNumber] = callback; | ||
} | ||
|
||
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false }); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
const { generateOfflineThreadingID, getCurrentTimestamp } = require('@xaviabot/fca-unofficial/utils'); | ||
|
||
function isCallable(func) { | ||
try { | ||
Reflect.apply(func, null, []); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = function (defaultFuncs, api, ctx) { | ||
return function createPollMqtt(title, options, threadID, callback) { | ||
if (!ctx.mqttClient) { | ||
throw new Error('Not connected to MQTT'); | ||
} | ||
|
||
ctx.wsReqNumber += 1; | ||
ctx.wsTaskNumber += 1; | ||
|
||
const taskPayload = { | ||
question_text: title, | ||
thread_key: threadID, | ||
options: options, | ||
sync_group: 1, | ||
}; | ||
|
||
const task = { | ||
failure_count: null, | ||
label: '163', | ||
payload: JSON.stringify(taskPayload), | ||
queue_name: 'poll_creation', | ||
task_id: ctx.wsTaskNumber, | ||
}; | ||
|
||
const content = { | ||
app_id: '2220391788200892', | ||
payload: JSON.stringify({ | ||
data_trace_id: null, | ||
epoch_id: parseInt(generateOfflineThreadingID()), | ||
tasks: [task], | ||
version_id: '7158486590867448', | ||
}), | ||
request_id: ctx.wsReqNumber, | ||
type: 3, | ||
}; | ||
|
||
if (isCallable(callback)) { | ||
ctx.reqCallbacks[ctx.wsReqNumber] = callback; | ||
} | ||
|
||
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false }); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const { generateOfflineThreadingID, getCurrentTimestamp } = require('../utils'); | ||
|
||
function isCallable(func) { | ||
try { | ||
Reflect.apply(func, null, []); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = function (defaultFuncs, api, ctx) { | ||
return function forwardMessage(messageID, threadID, callback) { | ||
if (!ctx.mqttClient) { | ||
throw new Error('Not connected to MQTT'); | ||
} | ||
|
||
ctx.wsReqNumber += 1; | ||
ctx.wsTaskNumber += 1; | ||
|
||
const taskPayload = { | ||
thread_id: threadID, | ||
otid: parseInt(generateOfflineThreadingID()), | ||
source: 65544, | ||
send_type: 5, | ||
sync_group: 1, | ||
forwarded_msg_id: messageID, | ||
strip_forwarded_msg_caption: 0, | ||
initiating_source: 1, | ||
}; | ||
|
||
const task = { | ||
failure_count: null, | ||
label: '46', | ||
payload: JSON.stringify(taskPayload), | ||
queue_name: `${threadID}`, | ||
task_id: ctx.wsTaskNumber, | ||
}; | ||
|
||
const content = { | ||
app_id: '2220391788200892', | ||
payload: JSON.stringify({ | ||
data_trace_id: null, | ||
epoch_id: parseInt(generateOfflineThreadingID()), | ||
tasks: [task], | ||
version_id: '25095469420099952', | ||
}), | ||
request_id: ctx.wsReqNumber, | ||
type: 3, | ||
}; | ||
|
||
if (isCallable(callback)) { | ||
ctx.reqCallbacks[ctx.wsReqNumber] = callback; | ||
} | ||
|
||
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false }); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
const { generateOfflineThreadingID, getCurrentTimestamp } = require('../utils'); | ||
|
||
function isCallable(func) { | ||
try { | ||
Reflect.apply(func, null, []); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = function (defaultFuncs, api, ctx) { | ||
return function pinMessage(pinMode, messageID, threadID, callback) { | ||
if (!ctx.mqttClient) { | ||
throw new Error('Not connected to MQTT'); | ||
} | ||
|
||
ctx.wsReqNumber += 1; | ||
ctx.wsTaskNumber += 1; | ||
|
||
const taskLabel = pinMode ? '430' : '431'; | ||
const queueNamePrefix = pinMode ? 'pin_msg_v2_' : 'unpin_msg_v2_'; | ||
|
||
const taskPayload = { | ||
thread_key: threadID, | ||
message_id: messageID, | ||
timestamp_ms: getCurrentTimestamp(), | ||
}; | ||
|
||
const task = { | ||
failure_count: null, | ||
label: taskLabel, | ||
payload: JSON.stringify(taskPayload), | ||
queue_name: `${queueNamePrefix}${threadID}`, | ||
task_id: ctx.wsTaskNumber, | ||
}; | ||
|
||
const content = { | ||
app_id: '2220391788200892', | ||
payload: JSON.stringify({ | ||
data_trace_id: null, | ||
epoch_id: parseInt(generateOfflineThreadingID()), | ||
tasks: [task], | ||
version_id: '25095469420099952', | ||
}), | ||
request_id: ctx.wsReqNumber, | ||
type: 3, | ||
}; | ||
|
||
if (isCallable(callback)) { | ||
ctx.reqCallbacks[ctx.wsReqNumber] = callback; | ||
} | ||
|
||
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false }); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const { generateOfflineThreadingID, getCurrentTimestamp } = require('../utils'); | ||
|
||
function isCallable(func) { | ||
try { | ||
Reflect.apply(func, null, []); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = function (defaultFuncs, api, ctx) { | ||
return function sendTypingIndicatorMqtt(isTyping, threadID, callback) { | ||
if (!ctx.mqttClient) { | ||
throw new Error('Not connected to MQTT'); | ||
} | ||
|
||
ctx.wsReqNumber += 1; | ||
|
||
api.getThreadInfo(threadID).then(threadData => { | ||
const label = '3'; | ||
const isGroupThread = threadData.isGroup ? 1 : 0; | ||
const attribution = 0; | ||
|
||
const taskPayload = { | ||
thread_key: threadID, | ||
is_group_thread: isGroupThread, | ||
is_typing: isTyping ? 1 : 0, | ||
attribution: attribution, | ||
}; | ||
|
||
const payload = JSON.stringify(taskPayload); | ||
const version = '25393437286970779'; | ||
|
||
const content = { | ||
app_id: '2220391788200892', | ||
payload: JSON.stringify({ | ||
label: label, | ||
payload: payload, | ||
version: version, | ||
}), | ||
request_id: ctx.wsReqNumber, | ||
type: 4, | ||
}; | ||
|
||
if (isCallable(callback)) { | ||
ctx.reqCallbacks[ctx.wsReqNumber] = callback; | ||
} | ||
|
||
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false }); | ||
}).catch(error => { | ||
throw new Error('Failed to get thread info'); | ||
}); | ||
}; | ||
}; |
Oops, something went wrong.