Skip to content

Commit

Permalink
remove slack from discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Nov 10, 2023
1 parent 3accaa5 commit 39d76b4
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 115 deletions.
1 change: 0 additions & 1 deletion discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"discord.js": "^14.12.1",
"ethers": "^5.7.2",
"faunadb": "^4.8.0",
"slack-utility": "^0.1.29",
"tweetnacl": "^1.0.3"
},
"devDependencies": {
Expand Down
26 changes: 1 addition & 25 deletions discord-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,30 @@ import { BigNumber, utils } from 'ethers'
import nacl from 'tweetnacl'
import {
CommandNames,
buildSlackStatsMessage,
config,
createStats,
faucetBalanceLowSlackMessage,
findRequest,
findStats,
formatSeconds,
log,
queries,
requestTokens,
saveRequest,
sendSlackMessage,
updateStats,
} from './utils'

const incrementFaucetRequestsCount = async (address: string, requestDate: string) => {
const stats = await findStats(requestDate)
log('stats', stats)
if (!stats || stats === null || stats.length === 0) {
const slackMessageId = await sendSlackMessage(
'Current week evm-faucet requests',
buildSlackStatsMessage('update', 1, 1),
)
await createStats(address, slackMessageId, requestDate)
await createStats(address, requestDate)
} else {
const statsFound = stats[0].data
const isExistingAddresses = statsFound.addresses.find((a: string) => a === address)
await sendSlackMessage(
'Current week evm-faucet requests',
buildSlackStatsMessage(
'update',
statsFound.requests + 1,
isExistingAddresses ? statsFound.uniqueAddresses : statsFound.uniqueAddresses + 1,
statsFound.requestsByType,
),
statsFound.slackMessageId,
)
await updateStats(stats[0].ref, statsFound, address)
}
}

const sendLowBalanceWarning = async (faucetBalance: BigNumber) =>
await faucetBalanceLowSlackMessage(utils.formatEther(faucetBalance))

const tagUser = (userId: string) => '<@' + userId + '>'

const buildDiscordInteractionResponse = (content: string, originalInteraction: any) =>
Expand Down Expand Up @@ -157,10 +137,6 @@ export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPr
const withdrawalAmount = await queries.withdrawalAmount()
const faucetBalance = await queries.verifyFaucetBalance()

// if faucetBalance is lower than withdrawalAmount * SLACK_BALANCE_NOTIFICATION_THRESHOLD, then send a slack message
if (faucetBalance.lt(withdrawalAmount.mul(BigNumber.from(config.SLACK_BALANCE_NOTIFICATION_THRESHOLD))))
await sendLowBalanceWarning(faucetBalance)

// if faucetBalance is lower than withdrawalAmount, then the faucet needs to be refilled
if (faucetBalance.lt(withdrawalAmount)) {
await postDiscordMessage(
Expand Down
4 changes: 2 additions & 2 deletions discord-bot/src/utils/fauna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const findStats = async (
return stats
}

export const createStats = async (address: string, slackMessageId: string | undefined, requestDate: string) => {
export const createStats = async (address: string, requestDate: string) => {
await faunaDbClient
.query(
faunaQuery.Create(faunaQuery.Ref('classes/stats'), {
Expand All @@ -98,7 +98,7 @@ export const createStats = async (address: string, slackMessageId: string | unde
discord: 1,
},
requestDate,
slackMessageId: slackMessageId || '',
slackMessageId: '',
createdAt: faunaQuery.Now(),
},
}),
Expand Down
1 change: 0 additions & 1 deletion discord-bot/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from './commands'
export * from './config'
export * from './contracts'
export * from './fauna'
export * from './slack'
export * from './time'
86 changes: 0 additions & 86 deletions discord-bot/src/utils/slack.ts

This file was deleted.

0 comments on commit 39d76b4

Please sign in to comment.