Удаление отправки статистики

This commit is contained in:
Struchkov Mark 2024-01-26 13:37:48 +03:00
parent ef162456f1
commit 67e14ca2b5
No known key found for this signature in database
GPG Key ID: A3F0AC3F0FA52F3C

View File

@ -5,28 +5,21 @@ import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.bot.gitlab.core.config.properties.AppProperty;
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.SentBox;
import dev.struchkov.godfather.telegram.domain.ClientBotCommand;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
import static dev.struchkov.godfather.telegram.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN;
import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
/**
* @author upagge 19.01.2021
@ -36,8 +29,6 @@ import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
@RequiredArgsConstructor
public class StartNotify {
private final OkHttpClient client = new OkHttpClient();
private final TelegramSending sending;
private final TelegramService telegramService;
@ -67,53 +58,6 @@ public class StartNotify {
.payload(DISABLE_WEB_PAGE_PREVIEW)
.build();
sending.send(boxAnswer);
sendNotice();
}
registrationForStatistic();
}
/**
* Отправляет service_key для сбора анонимной статистики использования.
*/
private void registrationForStatistic() {
final UUID serviceKey = settingService.getServiceKey();
final boolean firstStart = settingService.isFirstStart();
final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/registration?key=" + serviceKey + "&initFlow=" + firstStart;
final Request request = new Request.Builder().get().url(requestUrl).build();
try {
client.newCall(request).execute();
} catch (Exception e) {
log.warn(e.getMessage());
}
}
/**
* Используется для уведомления пользователя о выходе новой версии.
*/
private void sendNotice() {
final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/start-notice";
final Request request = new Request.Builder().get().url(requestUrl).build();
try {
final Response response = client.newCall(request).execute();
if (response.code() == 200) {
final String noticeMessage = response.body().string();
if (checkNotBlank(noticeMessage)) {
final BoxAnswer notice = BoxAnswer.builder()
.message(noticeMessage)
.recipientPersonId(personProperty.getTelegramId())
.payload(DISABLE_WEB_PAGE_PREVIEW, true)
.build();
final Optional<SentBox> optSentBox = sending.send(notice);
if (optSentBox.isPresent()) {
final SentBox sentBox = optSentBox.get();
final String messageId = sentBox.getMessageId();
telegramService.pinMessage(personProperty.getTelegramId(), messageId);
}
}
}
} catch (Exception e) {
log.warn(e.getMessage());
}
}