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:
parent
e5e727b6c4
commit
92d1d158b3
5 changed files with 27 additions and 30 deletions
3
TODO.md
3
TODO.md
|
|
@ -242,7 +242,6 @@ feature/economy/
|
|||
---
|
||||
|
||||
### Приоритет 1
|
||||
- [ ] Система достижений (Achievements)
|
||||
- [x] Система экономики (Economy) — **✅**
|
||||
|
||||
### Приоритет 2
|
||||
|
|
@ -255,8 +254,6 @@ feature/economy/
|
|||
|
||||
### Приоритет 3
|
||||
- [ ] Статистика сервера — графики, CSV export
|
||||
- [ ] Система квестов
|
||||
- [ ] Wiki по установке и командам
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -14,25 +14,13 @@ import org.slf4j.LoggerFactory;
|
|||
/** Менеджер счетчика участников */
|
||||
public class CounterManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CounterManager.class);
|
||||
private static final String DEFAULT_FORMAT = "【👥】Участники: {count}";
|
||||
private final CounterStatsRepository statsRepo;
|
||||
private final ConfigRepository configRepo;
|
||||
|
||||
private String counterChannelId;
|
||||
private String format = "【👥】Участники: {count}";
|
||||
|
||||
public CounterManager(CounterStatsRepository statsRepo, ConfigRepository configRepo) {
|
||||
this.statsRepo = statsRepo;
|
||||
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) {
|
||||
String counterChannelId = configRepo.get("counter.channel_id");
|
||||
if (counterChannelId == null || counterChannelId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,7 +62,8 @@ public class CounterManager {
|
|||
return;
|
||||
}
|
||||
|
||||
int memberCount = guild.getMemberCount();
|
||||
String format = getFormat();
|
||||
int memberCount = countMembers(guild);
|
||||
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) {
|
||||
return statsRepo.getHistory(days);
|
||||
|
|
@ -94,10 +93,11 @@ public class CounterManager {
|
|||
|
||||
// Getters
|
||||
public String getCounterChannelId() {
|
||||
return counterChannelId;
|
||||
return configRepo.get("counter.channel_id");
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
String savedFormat = configRepo.get("counter.format");
|
||||
return savedFormat != null ? savedFormat : DEFAULT_FORMAT;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class CounterSetupPrefixCommand implements Command {
|
|||
|
||||
configRepo.set("counter.channel_id", channel.getId());
|
||||
|
||||
int memberCount = context.getGuild().getMemberCount();
|
||||
int memberCount = counterManager.getMemberCount(context.getGuild());
|
||||
String format = configRepo.get("counter.format");
|
||||
if (format == null) {
|
||||
format = "【👥】Участники: {count}";
|
||||
|
|
@ -119,7 +119,7 @@ public class CounterSetupPrefixCommand implements Command {
|
|||
if (channelId != null) {
|
||||
VoiceChannel channel = context.getGuild().getVoiceChannelById(channelId);
|
||||
if (channel != null) {
|
||||
int memberCount = context.getGuild().getMemberCount();
|
||||
int memberCount = counterManager.getMemberCount(context.getGuild());
|
||||
channel
|
||||
.getManager()
|
||||
.setName(format.replace("{count}", String.valueOf(memberCount)))
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ public class VoiceChannelManager {
|
|||
Permission.VOICE_MOVE_OTHERS, Permission.VOICE_MUTE_OTHERS);
|
||||
private final VoiceChannelRepository channelRepo;
|
||||
private final VoiceChannelActions channelActions;
|
||||
private String triggerChannelId;
|
||||
private String categoryId;
|
||||
private final ConfigRepository configRepo;
|
||||
|
||||
public VoiceChannelManager(
|
||||
VoiceChannelRepository channelRepo,
|
||||
|
|
@ -31,12 +30,12 @@ public class VoiceChannelManager {
|
|||
final ConfigRepository configRepo) {
|
||||
this.channelRepo = channelRepo;
|
||||
this.channelActions = new VoiceChannelActions(presetRepo);
|
||||
this.triggerChannelId = configRepo.get("voice.trigger_channel_id");
|
||||
this.categoryId = configRepo.get("voice.category_id");
|
||||
this.configRepo = configRepo;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
@ -56,6 +55,7 @@ public class VoiceChannelManager {
|
|||
}
|
||||
|
||||
private VoiceChannel buildPersonalChannel(final Member member, final Guild guild) {
|
||||
String categoryId = configRepo.get("voice.category_id");
|
||||
return guild
|
||||
.createVoiceChannel("Канал: " + member.getEffectiveName())
|
||||
.setParent(guild.getCategoryById(categoryId))
|
||||
|
|
@ -82,11 +82,11 @@ public class VoiceChannelManager {
|
|||
}
|
||||
|
||||
public String getTriggerChannelId() {
|
||||
return triggerChannelId;
|
||||
return configRepo.get("voice.trigger_channel_id");
|
||||
}
|
||||
|
||||
public String getCategoryId() {
|
||||
return categoryId;
|
||||
return configRepo.get("voice.category_id");
|
||||
}
|
||||
|
||||
public void updatePresetSetting(final String userId, final String setting, final Object value) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ class VoiceChannelManagerTest {
|
|||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
when(configRepo.get("voice.trigger_channel_id")).thenReturn("trigger-123");
|
||||
when(configRepo.get("voice.category_id")).thenReturn("cat-456");
|
||||
lenient().when(configRepo.get("voice.trigger_channel_id")).thenReturn("trigger-123");
|
||||
lenient().when(configRepo.get("voice.category_id")).thenReturn("cat-456");
|
||||
manager = new VoiceChannelManager(channelRepo, presetRepo, configRepo);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue