Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions .github/workflows/portainer-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
- master
tags:
- '**'
pull_request:
branches:
- '**'
Expand All @@ -13,24 +15,38 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: mrmigles/pakhombot
TAG: latest

jobs:
pr-docker-build:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image (no push)
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Determine image tag
run: |
TAG="${GITHUB_HEAD_REF}"
TAG="${TAG//\//_}"
TAG="${TAG//\\/_}"
echo "TAG=$TAG" >> "$GITHUB_ENV"

- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}

build-and-deploy:
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -63,6 +79,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Determine image tag
run: |
REF="${GITHUB_REF}"
if [[ "$REF" == refs/tags/* ]]; then
TAG="${REF#refs/tags/}"
elif [[ "$REF" == refs/heads/main || "$REF" == refs/heads/master ]]; then
TAG="latest"
else
TAG="${REF#refs/heads/}"
TAG="${TAG//\//_}"
TAG="${TAG//\\/_}"
fi
echo "TAG=$TAG" >> "$GITHUB_ENV"

- name: Build and push image
uses: docker/build-push-action@v6
with:
Expand Down
85 changes: 32 additions & 53 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<version>3.4.4</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>21</java.version>
<groovy.version>4.0.20</groovy.version>
<groovy.version>4.0.24</groovy.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -59,6 +59,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -71,10 +83,18 @@
<version>5.14.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>6.9.7.1</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>6.9.7.1</version>
</dependency>

<dependency>
<groupId>ru.stachek66.nlp</groupId>
<artifactId>mystem-scala</artifactId>
Expand All @@ -90,30 +110,11 @@
<artifactId>skype4j</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.10-b01</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<version>20240303</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
Expand All @@ -123,55 +124,35 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>ai.api</groupId>
<artifactId>libai</artifactId>
<version>1.4.8</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.7</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.1</version>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
Expand All @@ -181,7 +162,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
Expand All @@ -191,17 +171,16 @@
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.4.11</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.1</version>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>us.codecraft</groupId>
<artifactId>xsoup</artifactId>
<version>0.3.2</version>
<version>0.3.7</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/ru/holyway/botplatform/BotPlatformApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import ru.holyway.botplatform.core.Bot;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableMethodSecurity
@EnableCaching
@SpringBootApplication
@EnableAutoConfiguration(exclude = {GroovyTemplateAutoConfiguration.class})
@SpringBootApplication(exclude = {GroovyTemplateAutoConfiguration.class})
public class BotPlatformApplication {

private final Bot bots;
Expand Down
59 changes: 16 additions & 43 deletions src/main/java/ru/holyway/botplatform/config/BotConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package ru.holyway.botplatform.config;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.ssl.TrustStrategy;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand All @@ -19,6 +20,7 @@
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import ru.holyway.botplatform.core.Bot;
import ru.holyway.botplatform.core.CommonHandler;
import ru.holyway.botplatform.core.CommonMessageHandler;
Expand All @@ -41,9 +43,6 @@
import java.util.List;
import java.util.Map;

/**
* Created by Sergey on 1/17/2017.
*/
@Configuration
public class BotConfiguration {

Expand Down Expand Up @@ -104,12 +103,6 @@ public List<MessageHandler> orderedMessageHandlers(
final Map<String, MessageHandler> messageHandlers) {
final List<MessageHandler> orderedMessageHandlers = new ArrayList<>();
orderedMessageHandlers.add(messageHandlers.get("settingsHandler"));
//orderedMessageHandlers.add(messageHandlers.get("authenticationHandler"));
//orderedMessageHandlers.add(messageHandlers.get("skiperHandler"));
//orderedMessageHandlers.add(messageHandlers.get("messageAnalyzerHandler"));
//orderedMessageHandlers.add(messageHandlers.get("recordsHandler"));
//orderedMessageHandlers.add(messageHandlers.get("wikiHandler"));
//orderedMessageHandlers.add(messageHandlers.get("simpleQuestionHandler"));
return orderedMessageHandlers;
}

Expand All @@ -136,19 +129,20 @@ private HttpComponentsClientHttpRequestFactory buildRequestFactory()
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();

SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(sslContext)
.build())
.build())
.build();

HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
return requestFactory;
}
Expand All @@ -157,8 +151,9 @@ private HttpComponentsClientHttpRequestFactory buildRequestFactory()
public RestTemplate instaproviderTemplate()
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
HttpComponentsClientHttpRequestFactory requestFactory = buildRequestFactory();
return new RestTemplateBuilder().requestFactory(requestFactory).rootUri(instaproviderUrl)
.build();
RestTemplate template = new RestTemplate(requestFactory);
template.setUriTemplateHandler(new DefaultUriBuilderFactory(instaproviderUrl));
return template;
}

private void setProxy(final String host, final String port, final String user,
Expand Down Expand Up @@ -187,28 +182,6 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
}

// @Bean
// public DefaultBotOptions botOptions() {
// if (!org.apache.commons.lang3.StringUtils
// .isEmpty(proxyUser) && !org.apache.commons.lang3.StringUtils.isEmpty(proxyPass)) {
// Authenticator.setDefault(new Authenticator() {
// @Override
// protected PasswordAuthentication getPasswordAuthentication() {
// return new PasswordAuthentication(proxyUser, proxyPass.toCharArray());
// }
// });
// }
//
// DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
//
// if (!StringUtils.isEmpty(proxyHost) && !StringUtils.isEmpty(proxyPort)) {
// botOptions.setProxyHost(proxyHost);
// botOptions.setProxyPort(Integer.valueOf(proxyPort));
// botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS5);
// }
// return botOptions;
// }

@Bean
public RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ru.holyway.botplatform.scripting.entity.*;
import ru.holyway.botplatform.scripting.util.*;

import javax.annotation.Nonnull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Loading
Loading