Skip to content

Commit

Permalink
feat: add tag aristocrata when receiving a tip
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMedeiros committed Jan 27, 2024
1 parent 2a38b1c commit d09bde6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/discord.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class DiscordConfigService implements DiscordOptionsFactory {
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildPresences,
],
},
registerCommandOptions: [
Expand Down
1 change: 1 addition & 0 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default () => ({
port: parseInt(process.env.PORT, 10) || 4000,
DISCORD_API_KEY: parseInt(process.env.DISCORD_API_KEY, 10) || 3000,
TBD_GUILD_ID: process.env.TBD_GUILD_ID,
})
15 changes: 14 additions & 1 deletion src/domain/webhooks/webhooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { progressBar } from 'src/utils'
import { createResponse } from 'src/utils/default-response'
import { NumbersService } from 'src/utils/numbers/numbers.service'
import { PriceBodyDto, BlockBodyDto, MessageResponseDto, FeesBodyDto, MempoolBodyDto } from './dto'
import { ConfigService } from '@nestjs/config'

@Injectable()
export class WebhooksService {
private readonly tbdGuildId = this.cfgService.get<string>('TBD_GUILD_ID')

private readonly logger = new Logger(WebhooksService.name)
constructor(
@InjectDiscordClient()
private readonly client: Client,
private readonly numbersService: NumbersService,
private readonly cfgService: ConfigService,
) {}

sendAlertPrices(userId: string, alertPrice: MessageResponseDto) {
Expand Down Expand Up @@ -139,7 +143,16 @@ export class WebhooksService {
try {
this.client.users.fetch(userId).then(async (user) => {
user.send(await createResponse(payload))
this.logger.debug(`NEW WEBHOOK - Tip: ${userId} - ${payload.fields.satoshis.value}`)
this.logger.debug(`NEW WEBHOOK - Tip: ${user.id} - ${payload.fields.satoshis.value}`)

const server = this.client.guilds.cache.get(this.tbdGuildId)
const memberRole = server.roles.cache.find((role) => role.name === 'Aristocrata')
const member = server.members.cache.get(user.id)

if (member) {
member.roles.add(memberRole)
this.logger.debug(`New Aristocrata: ${user.username}`)
}
})

return true
Expand Down

0 comments on commit d09bde6

Please sign in to comment.