-
-
Notifications
You must be signed in to change notification settings - Fork 101
Member Count Display #1038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Member Count Display #1038
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b13eec2
Added MemberCounter Routine
devloves 877cb34
feat: use pattern compile
devloves f194f41
removed debug lines
devloves 7ba16c6
pattern fixes in config
devloves 53f1d2f
refactor: change cat to category
devloves dcc3ab3
feat: switch to findAny from forEach
devloves c5200c9
perf: remove pattern compilation for each call
christolis f6eeeae
perf: fixed solar linting error
devloves 31c85cd
perf: made memberCountCategoryPattern required
devloves 948cd96
Update application/config.json.template
devloves e9baabe
fixed: routine not updating channel name after first write
Taz03 13ed74d
fixed comment
Taz03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,5 +110,6 @@ | |
"special": [ | ||
] | ||
}, | ||
"memberCountCategoryPattern": "Info", | ||
"selectRolesChannelPattern": "select-your-roles" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...cation/src/main/java/org/togetherjava/tjbot/features/basic/MemberCountDisplayRoutine.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.togetherjava.tjbot.features.basic; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.channel.concrete.Category; | ||
|
||
import org.togetherjava.tjbot.config.Config; | ||
import org.togetherjava.tjbot.features.Routine; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Shows the guild member count on selected category, which updates everyday. | ||
*/ | ||
public class MemberCountDisplayRoutine implements Routine { | ||
private final Predicate<String> memberCountCategoryPredicate; | ||
|
||
/** | ||
* Creates an instance on member count display routine. | ||
* | ||
* @param config the config to use | ||
*/ | ||
public MemberCountDisplayRoutine(Config config) { | ||
christolis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
memberCountCategoryPredicate = | ||
Pattern.compile(config.getMemberCountCategoryPattern() + "( - \\d+ Members)?") | ||
.asMatchPredicate(); | ||
} | ||
|
||
private void updateCategoryName(Category category) { | ||
int totalMemberCount = category.getGuild().getMemberCount(); | ||
String baseName = category.getName().split("-")[0].trim(); | ||
|
||
category.getManager() | ||
.setName("%s - %d Members".formatted(baseName, totalMemberCount)) | ||
.queue(); | ||
} | ||
|
||
@Override | ||
public Schedule createSchedule() { | ||
return new Schedule(ScheduleMode.FIXED_RATE, 0, 24, TimeUnit.HOURS); | ||
} | ||
|
||
@Override | ||
public void runRoutine(JDA jda) { | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
jda.getGuilds() | ||
.forEach(guild -> guild.getCategories() | ||
.stream() | ||
.filter(category -> memberCountCategoryPredicate.test(category.getName())) | ||
.findAny() | ||
.ifPresent(this::updateCategoryName)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.