Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import axios, { AxiosRequestConfig } from 'axios'
import { handleDiscordError } from './errorHandler'
import { DiscordApiChannel } from '../types'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'

export const getChannel = async (
channelId: string,
token: string,
ctx: IProcessStreamContext,
): Promise<DiscordApiChannel> => {
const rateLimiter = getRateLimiter(ctx)
const config: AxiosRequestConfig = {
method: 'get',
url: `https://discord.com/api/v10/channels/${channelId}`,
Expand All @@ -19,8 +17,6 @@ export const getChannel = async (
}

try {
await rateLimiter.checkRateLimit('getChannel')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
return response.data
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { timeout } from '@crowd/common'
import { DiscordApiChannel, DiscordGetChannelsInput, DiscordGetMessagesInput } from '../types'
import getMessages from './getMessages'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'
import { handleDiscordError } from './errorHandler'

/**
Expand Down Expand Up @@ -33,8 +32,6 @@ async function getChannels(
ctx: IProcessStreamContext,
tryChannels = true,
): Promise<DiscordApiChannel[]> {
const rateLimiter = getRateLimiter(ctx)

const config = {
method: 'get',
url: `https://discord.com/api/v10/guilds/${input.guildId}/channels?`,
Expand All @@ -44,9 +41,6 @@ async function getChannels(
}

try {
await rateLimiter.checkRateLimit('getChannels')
await rateLimiter.incrementRateLimit()

const response = await axios(config)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import axios, { AxiosRequestConfig } from 'axios'
import { DiscordApiMember } from '../types'
import { handleDiscordError } from './errorHandler'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'

export const getMember = async (
guildId: string,
userId: string,
token: string,
ctx: IProcessStreamContext,
): Promise<DiscordApiMember> => {
const rateLimiter = getRateLimiter(ctx)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: AxiosRequestConfig<any> = {
method: 'get',
Expand All @@ -22,8 +19,6 @@ export const getMember = async (
}

try {
await rateLimiter.checkRateLimit('getMember')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
return response.data
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import axios from 'axios'
import { DiscordApiMember, DiscordGetMembersInput, DiscordGetMembersOutput } from '../types'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'
import { handleDiscordError } from './errorHandler'

async function getMembers(
input: DiscordGetMembersInput,
ctx: IProcessStreamContext,
): Promise<DiscordGetMembersOutput> {
const rateLimiter = getRateLimiter(ctx)

let url = `https://discord.com/api/v10/guilds/${input.guildId}/members?limit=${input.perPage}`
if (input.page !== undefined && input.page !== '') {
url += `&after=${input.page}`
Expand All @@ -23,8 +20,6 @@ async function getMembers(
},
}
try {
await rateLimiter.checkRateLimit('getMembers')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
const records: DiscordApiMember[] = response.data
const limit = parseInt(response.headers['x-ratelimit-remaining'], 10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import axios, { AxiosRequestConfig } from 'axios'
import { handleDiscordError } from './errorHandler'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'

export const getMessage = async (
channelId: string,
messageId: string,
token: string,
ctx: IProcessStreamContext,
) => {
const rateLimiter = getRateLimiter(ctx)

const config: AxiosRequestConfig = {
method: 'get',
url: `https://discord.com/api/v10/channels/${channelId}/messages/${messageId}`,
Expand All @@ -20,8 +17,6 @@ export const getMessage = async (
}

try {
await rateLimiter.checkRateLimit('getMessage')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
return response.data
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import axios from 'axios'
import { DiscordApiMessage, DiscordParsedReponse, DiscordGetMessagesInput } from '../types'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'
import { handleDiscordError } from './errorHandler'

async function getMessages(
input: DiscordGetMessagesInput,
ctx: IProcessStreamContext,
showErrors = true,
): Promise<DiscordParsedReponse> {
const rateLimiter = getRateLimiter(ctx)

let url = `https://discord.com/api/v10/channels/${input.channelId}/messages?limit=${input.perPage}`
if (input.page !== undefined && input.page !== '') {
url += `&before=${input.page}`
Expand All @@ -25,8 +22,6 @@ async function getMessages(
}

try {
await rateLimiter.checkRateLimit('getMessages')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
const records: DiscordApiMessage[] = response.data

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import axios from 'axios'
import { DiscordApiChannel, DiscordGetChannelsInput } from '../types'
import { IProcessStreamContext } from '../../../types'
import { getRateLimiter } from './handleRateLimit'
import { handleDiscordError } from './errorHandler'

async function getThreads(
input: DiscordGetChannelsInput,
ctx: IProcessStreamContext,
): Promise<DiscordApiChannel[]> {
const rateLimiter = getRateLimiter(ctx)
const config = {
method: 'get',
url: `https://discord.com/api/v10/guilds/${input.guildId}/threads/active?`,
Expand All @@ -17,8 +15,6 @@ async function getThreads(
},
}
try {
await rateLimiter.checkRateLimit('getThreads')
await rateLimiter.incrementRateLimit()
const response = await axios(config)
return response.data.threads
} catch (err) {
Expand Down