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}
|
||||
*/
|
||||
function unmarshallDiscordError(e) {
|
||||
if (e.name === "DiscordAPIError"){
|
||||
try{
|
||||
|
||||
JSON.parse(e.message)
|
||||
} catch{
|
||||
|
||||
const unmarshaled = JSON.parse(e.message)
|
||||
return {
|
||||
...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;
|
||||
|
|
@ -300,20 +311,15 @@ const commands = [{
|
|||
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};
|
||||
}
|
||||
catch (e){
|
||||
const what_how = typeof e
|
||||
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)
|
||||
catch (e_raw){
|
||||
const e = unmarshallDiscordError(e_raw)
|
||||
if (e.code === "NO_ATTACH_TARGET") {
|
||||
return api.sendEvent(event.room_id, "m.room.message", {
|
||||
...ctx,
|
||||
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",
|
||||
"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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue