Skip to content

Commit

Permalink
feat: discord executor
Browse files Browse the repository at this point in the history
  • Loading branch information
nftchance committed Oct 20, 2023
1 parent e95a4b8 commit aff7942
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Engine<
if (execution === undefined) return

// * Pass the need for Execution to the Executors.
this.stream.emit('Execution', execution)
this.stream.emit(execution.key, execution.execution)
}
)
}
Expand Down
36 changes: 36 additions & 0 deletions src/core/executors/discord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import axios from 'axios'

import { Executor } from '@/core/executor'
import { logger } from '@/lib/logger'

const key = 'Discord'

export type DiscordExecution = {
webhookUrl: string
data: {
embeds: Array<Record<string, any>>
}
}

export class DiscordExecutor<
TExecution extends DiscordExecution = DiscordExecution
> extends Executor<typeof key, TExecution> {
constructor() {
super(key)
}

execute = async ({ webhookUrl, data }: TExecution) => {
axios
.post(webhookUrl, data, {
headers: { 'Content-Type': 'application/json' }
})
.then(() => {
logger.info(`Discord message sent to ${webhookUrl}`)
})
.catch(error => {
logger.error(
`Discord message failed to send to ${webhookUrl}: ${error}`
)
})
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export {

// ! Executors
export { Executor } from '@/core/executor'
export { DiscordExecution, DiscordExecutor } from '@/core/executors/discord'
export {
FlashbotsExecution,
FlashbotsExecutor
Expand Down
23 changes: 16 additions & 7 deletions src/lib/functions/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ const generateStaticReferences = async ({
import { ${imports} } from 'ethers'
export const ${bigName}_NAME = '${name}' as const
export const ${bigName}_ABI = ${abi} as const
`

if (abi)
protocolGeneration += `\n
export const ${bigName}_ABI = ${abi} as const
`

if (bytecode)
protocolGeneration += `\n
export const ${bigName}_BYTECODE = '${bytecode}' as const
Expand All @@ -47,12 +51,17 @@ const generateStaticReferences = async ({

if (address !== undefined)
protocolGeneration += `\n
export const ${bigName}_ADDRESS = '${address}' as const
export const ${bigName}_CONTRACT = new Contract(
'${address}',
${bigName}_ABI
)
export const ${bigName}_INTERFACE = ${bigName}_CONTRACT.interface`
export const ${bigName}_ADDRESS = '${address}' as const
`

if (address !== undefined && abi !== undefined)
protocolGeneration += `\n
export const ${bigName}_CONTRACT = new Contract(
'${address}',
${bigName}_ABI
)
export const ${bigName}_INTERFACE = ${bigName}_CONTRACT.interface
`

if (address === undefined && abi !== undefined)
protocolGeneration += `
Expand Down

0 comments on commit aff7942

Please sign in to comment.