forked from cadence/out-of-your-element
Comparison of all the stuff I did. #6
2 changed files with 20 additions and 2 deletions
|
|
@ -158,11 +158,12 @@ async function sendError(roomID, source, type, e, payload) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} type
|
* @param {string} type
|
||||||
* @param {(event: any, ...args: any)=>any} fn
|
* @param {(event: Ty.Event.Outer<any> & {type: any, redacts:any, state_key:any}, ...args: any)=>any} fn
|
||||||
*/
|
*/
|
||||||
function guard(type, fn) {
|
function guard(type, fn) {
|
||||||
return async function(/** @type {Ty.Event.Outer<any>} */ event, /** @type {any} */ ...args) {
|
return async function(/** @type {Ty.Event.Outer<any>} */ event, /** @type {any} */ ...args) {
|
||||||
try {
|
try {
|
||||||
|
// @ts-ignore
|
||||||
return await fn(event, ...args)
|
return await fn(event, ...args)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await sendError(event.room_id, "Matrix", type, e, event)
|
await sendError(event.room_id, "Matrix", type, e, event)
|
||||||
|
|
@ -216,7 +217,7 @@ async event => {
|
||||||
let executedCommand
|
let executedCommand
|
||||||
if (event.type === "m.room.message" && event.content.msgtype === "m.text") {
|
if (event.type === "m.room.message" && event.content.msgtype === "m.text") {
|
||||||
executedCommand = await matrixCommandHandler.parseAndExecute(
|
executedCommand = await matrixCommandHandler.parseAndExecute(
|
||||||
// @ts-ignore - TypeScript doesn't know that the event.content.msgtype === "m.text" ensures that event isn't of type Ty.Event.Outer_M_Room_Message_File (which, indeed, wouldn't fit here)
|
// @ts-ignore - TypeScript doesn't know that the event.content.msgtype === "m.text" check ensures that event isn't of type Ty.Event.Outer_M_Room_Message_File (which, indeed, wouldn't fit here)
|
||||||
event
|
event
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,22 @@ function replyctx(execute) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Error & {code: string|number}} e
|
||||||
|
* @returns {e}
|
||||||
|
*/
|
||||||
|
function unmarshallDiscordError(e) {
|
||||||
|
if (e.name === "DiscordAPIError"){
|
||||||
|
try{
|
||||||
|
|
||||||
|
JSON.parse(e.message)
|
||||||
|
} catch{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
/** @type {Command[]} */
|
/** @type {Command[]} */
|
||||||
const commands = [{
|
const commands = [{
|
||||||
aliases: ["emoji"],
|
aliases: ["emoji"],
|
||||||
|
|
@ -289,6 +305,7 @@ const commands = [{
|
||||||
const but_im_done_with_you = typeof e.code
|
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("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("MSG: "+e.message)
|
||||||
|
console.log("MST: "+typeof e.message)
|
||||||
console.log("NAM: "+e.name)
|
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", {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue