flytegg / ls-discord-bot

The Discord bot powering the LearnSpigot.com support server.
https://learnspigot.com/discord
21 stars 19 forks source link

Implement searching threads by creator. #256

Open ShreyasAyyengar opened 3 months ago

ShreyasAyyengar commented 3 months ago

Explain your idea.

Discord does not natively support searching forum channels for a post created by a specific user. The discord bot can facilitate doing so because the JDA provides this functionality:

ForumChannel channel = {...} // get the #help channel.
String creatorId = {...} // requested discord user who created a help thread post.
List<ThreadChannel> foundThreads = new ArrayList<>();

for (ThreadChannel threadChannel : channel.getThreadChannels()) {
    if (threadChannel.getOwnerId().equalsIgnoreCase(creatorId)) {
        foundThreads.add(threadChannel);
    }
}

I realise the Discord bot is written in Kotlin, but I wanted to help anyone who wishes to PR this in finding the proper JDA methods.

Anything else?

No response

granpacho commented 2 months ago

i mean whats the point

granpacho commented 2 months ago

anyways this is the code in kotlin

val helpChannel: ForumChannel = guild.getChannelById(1234)
val creatorID = userId
val threads: MutableList<ThreadChannel> = mutableListOf()

for (thread in helpChannel.threadChannels) {
    if (thread.ownerId.equals(creatorID)) {
        threads.add(thread)
    }
}
ShreyasAyyengar commented 2 months ago

support searching forum channels for a post created by a specific user.

"support searching forum channels for a post created by a specific user."

granpacho commented 2 months ago

i mean i guess i could make a pr later I'm bored anyways

granpacho commented 2 months ago

so how should we make this work, like have three per page and have a button that changes pages or just the top 5 recent

Tofpu commented 2 months ago

so how should we make this work, like have three per page and have a button that changes pages or just the top 5 recent

I personally think that having it three per page with a button to change pages would be a nicer addition. You're the one PRing it though, so up to you

MLGPenguin commented 2 months ago

anyways this is the code in kotlin

val helpChannel: ForumChannel = guild.getChannelById(1234)
val creatorID = userId
val threads: MutableList<ThreadChannel> = mutableListOf()

for (thread in helpChannel.threadChannels) {
  if (thread.ownerId.equals(creatorID)) {
      threads.add(thread)
  }
}

Here's the code in Kotlin but easier and uses our existing utils:

Server.helpChannel.threadChannels.filter { it.ownerId == userId }

I also think 5 per page, in line with the /reputation command would be nice and consistent.

granpacho commented 2 months ago

Here's the code in Kotlin but easier and uses our existing utils:

Yeah I didn't look at any of the codebase I was just changing their code into kotlin, but that'll help actually I don't need to create a new postregistry method then