forked from cadence/out-of-your-element
Comparison of all the stuff I did. #6
1 changed files with 20 additions and 14 deletions
|
|
@ -97,16 +97,27 @@ function replyctx(execute) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Error & {code: string|number}} e
|
* @param {Error & {code?: string|number}} e
|
||||||
* @returns {e}
|
* @returns {e}
|
||||||
*/
|
*/
|
||||||
function unmarshallDiscordError(e) {
|
function unmarshallDiscordError(e) {
|
||||||
if (e.name === "DiscordAPIError"){
|
if (e.name === "DiscordAPIError"){
|
||||||
try{
|
try{
|
||||||
|
const unmarshaled = JSON.parse(e.message)
|
||||||
JSON.parse(e.message)
|
return {
|
||||||
} catch{
|
...e,
|
||||||
|
...unmarshaled
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
...err,
|
||||||
|
code: "JSON_PARSE_FAILED",
|
||||||
|
message: JSON.stringify({
|
||||||
|
original_error_where_message_failed_to_parse: e,
|
||||||
|
json_parser_error_message: err.message,
|
||||||
|
json_parser_error_code: err.code,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
|
|
@ -300,20 +311,15 @@ const commands = [{
|
||||||
if (attachedToMessage) await discord.snow.channel.createThreadWithMessage(channelID, attachedToMessage, {name: words.slice(1).join(" ")})
|
if (attachedToMessage) await discord.snow.channel.createThreadWithMessage(channelID, attachedToMessage, {name: words.slice(1).join(" ")})
|
||||||
else throw {code: "NO_ATTACH_TARGET", was_supposed_to_be: attachedToEvent};
|
else throw {code: "NO_ATTACH_TARGET", was_supposed_to_be: attachedToEvent};
|
||||||
}
|
}
|
||||||
catch (e){
|
catch (e_raw){
|
||||||
const what_how = typeof e
|
const e = unmarshallDiscordError(e_raw)
|
||||||
const but_im_done_with_you = typeof e.code
|
|
||||||
console.log("Type of "+e+" is "+what_how+" with keys "+Object.keys(e) + " and the value of that „code” key is "+e.code+" of type "+but_im_done_with_you)
|
|
||||||
console.log("MSG: "+e.message)
|
|
||||||
console.log("MST: "+typeof e.message)
|
|
||||||
console.log("NAM: "+e.name)
|
|
||||||
if (e.code === "NO_ATTACH_TARGET") {
|
if (e.code === "NO_ATTACH_TARGET") {
|
||||||
return api.sendEvent(event.room_id, "m.room.message", {
|
return api.sendEvent(event.room_id, "m.room.message", {
|
||||||
...ctx,
|
...ctx,
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
"body": "⚠️ Couldn't find a Discord representation of the message under which you're trying to attach this thread (event ID `"+e.was_supposed_to_be+"` on Matrix), so it wasn't created. Either you ran this command on an unbridged message (one sent by this bot or one that failed to bridge due to a previous error), or this is an error on our side and should be reported.",
|
"body": "⚠️ Couldn't find a Discord representation of the message under which you're trying to attach this thread (event ID `"+e_raw.was_supposed_to_be+"` on Matrix), so it wasn't created. Either you ran this command on an unbridged message (one sent by this bot or one that failed to bridge due to a previous error), or this is an error on our side and should be reported.",
|
||||||
"format": "org.matrix.custom.html",
|
"format": "org.matrix.custom.html",
|
||||||
"formatted_body": "⚠️ Couldn't find a Discord representation of the message under which you're trying to attach this thread (event ID <code>"+e.was_supposed_to_be+"</code> on Matrix), so it wasn't created. Either you ran this command on an unbridged message (one sent by this bot or one that failed to bridge due to a previous error), or this is an error on our side and should be reported."
|
"formatted_body": "⚠️ Couldn't find a Discord representation of the message under which you're trying to attach this thread (event ID <code>"+e_raw.was_supposed_to_be+"</code> on Matrix), so it wasn't created. Either you ran this command on an unbridged message (one sent by this bot or one that failed to bridge due to a previous error), or this is an error on our side and should be reported."
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (e.code === 160004) { // see: https://docs.discord.com/developers/topics/opcodes-and-status-codes
|
else if (e.code === 160004) { // see: https://docs.discord.com/developers/topics/opcodes-and-status-codes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue