<commit_before>package top.quantic.sentry.discord;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.api.events.Event;
import sx.blah.discord.api.events.EventSubscriber;
import sx.blah.discord.handle.impl.events.DisconnectedEvent;
import sx.blah.discord.handle.impl.events.ReadyEvent;
import sx.blah.discord.handle.impl.events.ReconnectFailureEvent;
import sx.blah.discord.handle.impl.events.ReconnectSuccessEvent;
import sx.blah.discord.handle.obj.IChannel;
import top.quantic.sentry.config.SentryProperties;
import top.quantic.sentry.discord.module.DiscordSubscriber;

import static top.quantic.sentry.discord.util.DiscordUtil.ourBotHash;
import static top.quantic.sentry.discord.util.DiscordUtil.sendMessage;

@Component
public class Supervisor implements DiscordSubscriber {

    private static final Logger log = LoggerFactory.getLogger(Supervisor.class);

    private final SentryProperties sentryProperties;

    @Autowired
    public Supervisor(SentryProperties sentryProperties) {
        this.sentryProperties = sentryProperties;
    }

    @EventSubscriber
    public void onReady(ReadyEvent event) {
        log.info("[{}] Discord bot is ready", getOurName(event));
        signalReady(event.getClient());
    }

    private void signalReady(IDiscordClient client) {
        IChannel channel = client.getChannelByID(sentryProperties.getDiscord().getCoordinatorChannelId());
        if (channel != null) {
            sendMessage(channel, ".logout " + ourBotHash(client));
        }<commit_msg>Ready announcements can be disabled now<commit_after>package top.quantic.sentry.discord;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.api.events.Event;
import sx.blah.discord.api.events.EventSubscriber;
import sx.blah.discord.handle.impl.events.DisconnectedEvent;
import sx.blah.discord.handle.impl.events.ReadyEvent;
import sx.blah.discord.handle.impl.events.ReconnectFailureEvent;
import sx.blah.discord.handle.impl.events.ReconnectSuccessEvent;
import sx.blah.discord.handle.obj.IChannel;
import top.quantic.sentry.config.SentryProperties;
import top.quantic.sentry.discord.module.DiscordSubscriber;
import top.quantic.sentry.service.SettingService;

import static top.quantic.sentry.discord.util.DiscordUtil.ourBotHash;
import static top.quantic.sentry.discord.util.DiscordUtil.sendMessage;

@Component
public class Supervisor implements DiscordSubscriber {

    private static final Logger log = LoggerFactory.getLogger(Supervisor.class);

    private final SentryProperties sentryProperties;
    private final SettingService settingService;

    @Autowired
    public Supervisor(SentryProperties sentryProperties, SettingService settingService) {
        this.sentryProperties = sentryProperties;
        this.settingService = settingService;
    }

    @EventSubscriber
    public void onReady(ReadyEvent event) {
        log.info("[{}] Discord bot is ready", getOurName(event));
        signalReady(event.getClient());
    }

    private void signalReady(IDiscordClient client) {
        if (sentryProperties.getDiscord().isAnnounceReady()) {
            IChannel channel = client.getChannelByID(sentryProperties.getDiscord().getCoordinatorChannelId());
            if (channel != null) {
            settingService.getPrefixes(channel.getGuild().getID()).stream()
                .findAny()
                .ifPresent(pre -> sendMessage(channel, pre + "logout " + ourBotHash(client)));
            }
        }
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0010526315789473684, 'mean_word_length': 4.524709302325581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4150501', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1128, 'n_words': 187}