package org.jebot.handler.impl.change;

import com.pengrad.telegrambot.request.SendMessage;
import org.jebot.handler.AbstractHandler;
import org.jebot.handler.dto.BotMessage;

public class GroupChangeHandler extends AbstractHandler {
    @Override
    public boolean msgHandler(BotMessage message) {
        // 群组名称变更
        if (message.isGroupAuthenticated() && !message.getBotGroup().getGroupName().equals(message.getMessage().chat().title())) {
            String oldGroupName = message.getBotGroup().getGroupName();
            message.getBotGroup().setGroupName(message.getMessage().chat().title());
            this.handlerManager.getGroupRepository().save(message.getBotGroup());
            String msg = String.format("群组名称[%s]已更新为: %s", oldGroupName, message.getMessage().chat().title());
            SendMessage sendMessage = new SendMessage(message.getMessage().chat().id(), msg);
            message.getTelegramBot().execute(sendMessage);
        }

        return false;
    }
}
