Skip to content

Commit

Permalink
debug stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Awesome-E committed Apr 20, 2024
1 parent 1cd5a8e commit a965318
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/listeners/inviteroles.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function addInviteRolesToNewMember (member) {
// const invite = newInvites.find(i => i.uses > oldInvites.get(i.code))
// updateGuildInvites(member.guild)
let source
for (let i = 0; i < 3; i++) {
for (let i = 0; i < 5; i++) {
const result = await searchByID(member.guild, member.id)
source = result?.source_invite_code
console.log(i, !!source)
Expand Down Expand Up @@ -130,3 +130,5 @@ async function addInviteRolesToNewMember (member) {

client.on(Events.GuildMemberAdd, addInviteRolesToNewMember)
client.on(Events.GuildMemberAvailable, m => console.log('member available'))
client.on(Events.GuildMemberUpdate, m => console.log('member updated', m.displayName))
client.addListener(Events.Raw, m => console.log('EVENT:', m.t))
23 changes: 21 additions & 2 deletions src/modules/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ async function searchByID (guild, id) {
const userIDQuery = { user_id: { or_query: [id] } }
const rest = new REST({ version: '10' }).setToken(client.token)
const response = await rest.post(`/guilds/${guild.id}/members-search`, {
body: { and_query: userIDQuery, limit: 1 }
body: { and_query: userIDQuery, limit: 1, sort: 1 }
})
console.log(response, guild.id, id)
const result = response.members[0]
if (result) result.member = new GuildMember(client, result.member, guild)
return result
}

module.exports = { searchByID }
/**
* Returns a search result with invite information
* @param {Guild} guild The guild to search
* @returns {Promise<GuildMemberIDSearchResult>}
*/
async function searchByRecent (guild) {
const range = { gte: Date.now() - 3600000 }
const rest = new REST({ version: '10' }).setToken(client.token)
const response = await rest.post(`/guilds/${guild.id}/members-search`, {
body: { and_query: { guild_joined_at: { range } }, limit: 5, sort: 1 }
})
console.log(response, guild.id)
const results = response.members
if (results) {
results.forEach(m => { m.member = new GuildMember(client, m.member, guild) })
}
return results
}

module.exports = { searchByID, searchByRecent }
8 changes: 8 additions & 0 deletions src/routes/api/guilds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const router = express.Router()
const Joi = require('joi')

const { validateAPIKey } = require('../../../modules/api-key-validation')
const { searchByID, searchByRecent } = require('../../../modules/members')

router.get('/:guild/user-ids', validateAPIKey, async (req, res) => {
if (req.query.users == null || !/^([^#]+#\d{4}(,|$))*/.test(req.query.users)) {
Expand Down Expand Up @@ -90,4 +91,11 @@ router.get('/:guild/announcements-for', validateAPIKey, async (req, res) => {
res.send(result)
})

router.get('/member-test', async (req, res) => {
const guild = await client.guilds.fetch('957408720088891473')
const member = (await searchByID(guild, '437808476106784770')) ?? null
const recent = await searchByRecent(guild, 3)
res.send({ member, recent })
})

module.exports = router

0 comments on commit a965318

Please sign in to comment.