fix: counter/voice-setup read config live + exclude bots from counter; drop quests/achievements/wiki from roadmap

- VoiceChannelManager: read trigger_channel_id/category_id live from ConfigRepository instead of caching at construction, so !voice-setup takes effect immediately without restart
- CounterManager: read channel_id/format live from config (same stale-cache fix); count members excluding bots
- CounterSetupPrefixCommand: use bot-excluding member count
- VoiceChannelManagerTest: lenient stubbing for live config reads
- TODO: remove quests, achievements, wiki from roadmap
This commit is contained in:
loki5512344 2026-08-19 12:21:42 +02:00
parent e5e727b6c4
commit 92d1d158b3
Signed by: boba
GPG key ID: 253067914055423B
5 changed files with 27 additions and 30 deletions

View file

@ -242,7 +242,6 @@ feature/economy/
--- ---
### Приоритет 1 ### Приоритет 1
- [ ] Система достижений (Achievements)
- [x] Система экономики (Economy) — **✅** - [x] Система экономики (Economy) — **✅**
### Приоритет 2 ### Приоритет 2
@ -255,8 +254,6 @@ feature/economy/
### Приоритет 3 ### Приоритет 3
- [ ] Статистика сервера — графики, CSV export - [ ] Статистика сервера — графики, CSV export
- [ ] Система квестов
- [ ] Wiki по установке и командам
--- ---

View file

@ -14,25 +14,13 @@ import org.slf4j.LoggerFactory;
/** Менеджер счетчика участников */ /** Менеджер счетчика участников */
public class CounterManager { public class CounterManager {
private static final Logger logger = LoggerFactory.getLogger(CounterManager.class); private static final Logger logger = LoggerFactory.getLogger(CounterManager.class);
private static final String DEFAULT_FORMAT = "【👥】Участники: {count}";
private final CounterStatsRepository statsRepo; private final CounterStatsRepository statsRepo;
private final ConfigRepository configRepo; private final ConfigRepository configRepo;
private String counterChannelId;
private String format = "【👥】Участники: {count}";
public CounterManager(CounterStatsRepository statsRepo, ConfigRepository configRepo) { public CounterManager(CounterStatsRepository statsRepo, ConfigRepository configRepo) {
this.statsRepo = statsRepo; this.statsRepo = statsRepo;
this.configRepo = configRepo; this.configRepo = configRepo;
loadConfig();
}
/** Загрузить конфигурацию */
private void loadConfig() {
this.counterChannelId = configRepo.get("counter.channel_id");
String savedFormat = configRepo.get("counter.format");
if (savedFormat != null) {
this.format = savedFormat;
}
} }
/** Получить текущую дневную статистику */ /** Получить текущую дневную статистику */
@ -63,6 +51,7 @@ public class CounterManager {
/** Обновить счетчик участников */ /** Обновить счетчик участников */
public void updateCounter(final Guild guild) { public void updateCounter(final Guild guild) {
String counterChannelId = configRepo.get("counter.channel_id");
if (counterChannelId == null || counterChannelId.isEmpty()) { if (counterChannelId == null || counterChannelId.isEmpty()) {
return; return;
} }
@ -73,7 +62,8 @@ public class CounterManager {
return; return;
} }
int memberCount = guild.getMemberCount(); String format = getFormat();
int memberCount = countMembers(guild);
String newName = format.replace("{count}", String.valueOf(memberCount)); String newName = format.replace("{count}", String.valueOf(memberCount));
// Обновляем название канала только если оно изменилось // Обновляем название канала только если оно изменилось
@ -87,6 +77,15 @@ public class CounterManager {
} }
} }
private int countMembers(final Guild guild) {
return (int) guild.getMembers().stream().filter(m -> !m.getUser().isBot()).count();
}
/** Количество людей на сервере (без ботов) */
public int getMemberCount(final Guild guild) {
return countMembers(guild);
}
/** Получить историю статистики */ /** Получить историю статистики */
public List<DailyStats> getHistory(final int days) { public List<DailyStats> getHistory(final int days) {
return statsRepo.getHistory(days); return statsRepo.getHistory(days);
@ -94,10 +93,11 @@ public class CounterManager {
// Getters // Getters
public String getCounterChannelId() { public String getCounterChannelId() {
return counterChannelId; return configRepo.get("counter.channel_id");
} }
public String getFormat() { public String getFormat() {
return format; String savedFormat = configRepo.get("counter.format");
return savedFormat != null ? savedFormat : DEFAULT_FORMAT;
} }
} }

View file

@ -85,7 +85,7 @@ public class CounterSetupPrefixCommand implements Command {
configRepo.set("counter.channel_id", channel.getId()); configRepo.set("counter.channel_id", channel.getId());
int memberCount = context.getGuild().getMemberCount(); int memberCount = counterManager.getMemberCount(context.getGuild());
String format = configRepo.get("counter.format"); String format = configRepo.get("counter.format");
if (format == null) { if (format == null) {
format = "【👥】Участники: {count}"; format = "【👥】Участники: {count}";
@ -119,7 +119,7 @@ public class CounterSetupPrefixCommand implements Command {
if (channelId != null) { if (channelId != null) {
VoiceChannel channel = context.getGuild().getVoiceChannelById(channelId); VoiceChannel channel = context.getGuild().getVoiceChannelById(channelId);
if (channel != null) { if (channel != null) {
int memberCount = context.getGuild().getMemberCount(); int memberCount = counterManager.getMemberCount(context.getGuild());
channel channel
.getManager() .getManager()
.setName(format.replace("{count}", String.valueOf(memberCount))) .setName(format.replace("{count}", String.valueOf(memberCount)))

View file

@ -22,8 +22,7 @@ public class VoiceChannelManager {
Permission.VOICE_MOVE_OTHERS, Permission.VOICE_MUTE_OTHERS); Permission.VOICE_MOVE_OTHERS, Permission.VOICE_MUTE_OTHERS);
private final VoiceChannelRepository channelRepo; private final VoiceChannelRepository channelRepo;
private final VoiceChannelActions channelActions; private final VoiceChannelActions channelActions;
private String triggerChannelId; private final ConfigRepository configRepo;
private String categoryId;
public VoiceChannelManager( public VoiceChannelManager(
VoiceChannelRepository channelRepo, VoiceChannelRepository channelRepo,
@ -31,12 +30,12 @@ public class VoiceChannelManager {
final ConfigRepository configRepo) { final ConfigRepository configRepo) {
this.channelRepo = channelRepo; this.channelRepo = channelRepo;
this.channelActions = new VoiceChannelActions(presetRepo); this.channelActions = new VoiceChannelActions(presetRepo);
this.triggerChannelId = configRepo.get("voice.trigger_channel_id"); this.configRepo = configRepo;
this.categoryId = configRepo.get("voice.category_id");
} }
public boolean isTriggerChannel(final String channelId) { public boolean isTriggerChannel(final String channelId) {
return channelId != null && channelId.equals(triggerChannelId); String trigger = configRepo.get("voice.trigger_channel_id");
return channelId != null && channelId.equals(trigger);
} }
public VoiceChannel createPersonalChannel(final Member member, final Guild guild) { public VoiceChannel createPersonalChannel(final Member member, final Guild guild) {
@ -56,6 +55,7 @@ public class VoiceChannelManager {
} }
private VoiceChannel buildPersonalChannel(final Member member, final Guild guild) { private VoiceChannel buildPersonalChannel(final Member member, final Guild guild) {
String categoryId = configRepo.get("voice.category_id");
return guild return guild
.createVoiceChannel("Канал: " + member.getEffectiveName()) .createVoiceChannel("Канал: " + member.getEffectiveName())
.setParent(guild.getCategoryById(categoryId)) .setParent(guild.getCategoryById(categoryId))
@ -82,11 +82,11 @@ public class VoiceChannelManager {
} }
public String getTriggerChannelId() { public String getTriggerChannelId() {
return triggerChannelId; return configRepo.get("voice.trigger_channel_id");
} }
public String getCategoryId() { public String getCategoryId() {
return categoryId; return configRepo.get("voice.category_id");
} }
public void updatePresetSetting(final String userId, final String setting, final Object value) { public void updatePresetSetting(final String userId, final String setting, final Object value) {

View file

@ -28,8 +28,8 @@ class VoiceChannelManagerTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
when(configRepo.get("voice.trigger_channel_id")).thenReturn("trigger-123"); lenient().when(configRepo.get("voice.trigger_channel_id")).thenReturn("trigger-123");
when(configRepo.get("voice.category_id")).thenReturn("cat-456"); lenient().when(configRepo.get("voice.category_id")).thenReturn("cat-456");
manager = new VoiceChannelManager(channelRepo, presetRepo, configRepo); manager = new VoiceChannelManager(channelRepo, presetRepo, configRepo);
} }