добавил обработку счетчиков

This commit is contained in:
2026-02-14 11:26:45 +03:00
parent 5f53bdcf96
commit 63b7fa4ea1
12 changed files with 796 additions and 131 deletions
+172 -8
View File
@@ -407,6 +407,22 @@ void uGeneral::initializeManagers()
ui->widget_3->setManagerType(FSingleGrid::TemplateManager);
ui->widget_3->setDatabase(db);
m_counterManager = new CounterManager(this);
if (db) {
m_counterManager->initialize(db);
}
// Настраиваем таблицу счётчиков (предполагаем, что она уже есть в .ui с objectName "sgCounters")
setupCountersTable();
// Подключаем сигналы для обновления таблицы при изменениях
connect(m_counterManager, &CounterManager::dataChanged, this, &uGeneral::updateCountersTable);
connect(m_counterManager, &CounterManager::counterAdded, this, [this](const QString&, int) { updateCountersTable(); });
connect(m_counterManager, &CounterManager::counterRemoved, this, [this](const QString&) { updateCountersTable(); });
connect(m_counterManager, &CounterManager::counterUpdated, this, [this](const QString&, const QString&) { updateCountersTable(); });
connect(m_counterManager, &CounterManager::counterIncremented, this, [this](const QString&, int) { updateCountersTable(); });
m_commandProcessor = new CommandProcessor(this);
if (db) {
@@ -428,9 +444,46 @@ void uGeneral::initializeManagers()
context.mediaFileManager = m_SoundFiles;
context.channel = ui->edtChannel->text();
context.notifyVolume = ui->tbNotifyVolume->value();
context.counterManager = m_counterManager;
m_commandProcessor->setContext(context);
}
}
void uGeneral::setupCountersTable(){
// Предполагаем, что sgCounters уже есть в ui
ui->sgCounters->setColumnCount(2);
QStringList headers;
headers << "Счётчик" << "Значение";
ui->sgCounters->setHorizontalHeaderLabels(headers);
ui->sgCounters->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->sgCounters->setSelectionMode(QAbstractItemView::SingleSelection);
ui->sgCounters->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->sgCounters->horizontalHeader()->setStretchLastSection(true);
ui->sgCounters->setColumnWidth(0, 200);
ui->sgCounters->setColumnWidth(1, 80);
updateCountersTable();
}
void uGeneral::updateCountersTable()
{
ui->sgCounters->setRowCount(0);
ui->cbCounters->clear();
if (!m_counterManager) return;
QVector<CounterManager::Counter> counters = m_counterManager->getAllCounters();
for (const auto &c : counters) {
int row = ui->sgCounters->rowCount();
ui->sgCounters->insertRow(row);
ui->sgCounters->setItem(row, 0, new QTableWidgetItem(c.name));
ui->sgCounters->setItem(row, 1, new QTableWidgetItem(QString::number(c.count)));
ui->cbCounters->addItem(c.name);
}
}
void uGeneral::loadCommandsFromTableWidget()
@@ -742,6 +795,7 @@ uGeneral::~uGeneral()
delete m_neuralTemplateManager;
m_neuralTemplateManager = nullptr;
}
delete m_counterManager;
delete m_createNotifyDialog;
delete m_createChatDialog;
delete ui;
@@ -1740,7 +1794,8 @@ void uGeneral::initializeNotificationSounds()
}
}
void uGeneral::handleNewMessage(const QString &message){
void uGeneral::handleNewMessage(const QString &message)
{
TwitchMessage msg = TwitchMessage::parse(message);
QString userId = m_userManager->checkUser(msg.displayName, msg);
@@ -1754,8 +1809,30 @@ void uGeneral::handleNewMessage(const QString &message){
QString processedMessage = processTwitchMessage(msg);
QString formattedNickname = formatNicknameWithBadges(msg);
addChatMessage(formattedNickname, processedMessage);
if (m_counterManager) {
m_counterManager->processMessage(msg.message); // или cleanedText
}
QString cleanedText = cleanMessageFromAllEmotes(msg.message);
// Удаляем ссылки (опционально)
cleanedText.remove(QRegularExpression("https?://\\S+"));
cleanedText = cleanedText.trimmed();
// Проверяем наличие русских букв
bool hasRussian = false;
for (const QChar& ch : cleanedText) {
if (ch.unicode() >= 0x0400 && ch.unicode() <= 0x04FF) {
hasRussian = true;
break;
}
}
if (!hasRussian && !cleanedText.isEmpty()) {
// Здесь нужно вызвать перевод (например, через API)
// sendToTranslate(cleanedText);
LogManager::instance()->debug("uGeneral", "handleNewMessage",
"Требуется перевод: " + cleanedText);
}
if (msg.message.startsWith("!!!")) {
QString cleanedMessage = msg.message.mid(3);
@@ -1766,6 +1843,14 @@ void uGeneral::handleNewMessage(const QString &message){
}
}
QString uGeneral::cleanMessageFromAllEmotes(const QString& message) const
{
QString cleaned = message;
cleaned = bttvProvider.cleanMessage(cleaned);
cleaned = sevenTVProvider.cleanMessage(cleaned);
return cleaned;
}
void uGeneral::processUserCommand(const QString &username, const QString &commandText)
{
if (!m_commandProcessor || !m_userManager) return;
@@ -1972,11 +2057,6 @@ void uGeneral::disconnectFromTwitch()
setTwitchConnected(false);
}
void uGeneral::execCommand(const QString &sender, const QString &message)
{
LogManager::instance()->debug("uGeneral", "execCommand",
QString("Обработка команды от %1: %2").arg(sender).arg(message));
}
void uGeneral::on_lbRandomGroup_itemClicked(QListWidgetItem *item)
{
@@ -3026,3 +3106,87 @@ void uGeneral::on_btnRmWebService_clicked()
.arg(serviceName));
}
}
void uGeneral::on_sgCounters_cellClicked(int row, int column)
{
Q_UNUSED(column);
QString name = ui->sgCounters->item(row, 0)->text();
int value = ui->sgCounters->item(row, 1)->text().toInt();
ui->edtWordCounter->setText(name);
ui->sbStartCounter->setValue(value);
}
void uGeneral::on_sgCounters_cellDoubleClicked(int row, int column)
{
}
void uGeneral::on_btnCounterAdd_clicked()
{
QString name = ui->edtWordCounter->text().trimmed(); // предположим, есть поле ввода
if (name.isEmpty()) {
QMessageBox::warning(this, "Ошибка", "Введите название счётчика!");
return;
}
int initial = ui->sbStartCounter->value(); // спинбокс для начального значения
if (m_counterManager->addCounter(name, initial)) {
ui->edtWordCounter->clear();
ui->sbStartCounter->setValue(0);
updateCountersTable();
} else {
QMessageBox::warning(this, "Ошибка", "Не удалось добавить счётчик (возможно, уже существует)");
}
}
void uGeneral::on_btnCounterDelete_clicked()
{
int row = ui->sgCounters->currentRow();
if (row < 0) {
QMessageBox::warning(this, "Ошибка", "Выберите счётчик для удаления!");
return;
}
QString name = ui->sgCounters->item(row, 0)->text();
if (m_counterManager->removeCounter(name)) {
updateCountersTable();
}
}
void uGeneral::on_btnCounterEdit_clicked()
{
int row = ui->sgCounters->currentRow();
if (row < 0) {
QMessageBox::warning(this, "Ошибка", "Выберите счётчик для редактирования!");
return;
}
QString oldName = ui->sgCounters->item(row, 0)->text();
QString newName = ui->edtWordCounter->text().trimmed();
int newValue = ui->sbStartCounter->value();
if (newName.isEmpty()) {
QMessageBox::warning(this, "Ошибка", "Введите новое название счётчика!");
return;
}
if (m_counterManager->updateCounter(oldName, newName, newValue)) {
ui->edtWordCounter->clear();
ui->sbStartCounter->setValue(0);
updateCountersTable();
} else {
QMessageBox::warning(this, "Ошибка", "Не удалось обновить счётчик");
}
}
void uGeneral::on_btnCounterAtoText_clicked()
{
QTextCursor cursor = ui->textBrowser->textCursor();
cursor.insertText("|)" + ui->cbCounters->currentText() + "|)");
}