Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]: default session and jar name #22

Merged
merged 2 commits into from
Oct 10, 2024
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
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,18 @@ All settings tables contain 4 columns:

### Session properties

| Name | Description | Default Value | Required |
|-------------------------|-----------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|----------|
| maxUserParallelRequests | Max number of threads used for consumption messages from a telegram for concrete user. 0 - no restrictions | 1 | true |
| consumeMaxThreads | Max number of threads used for consumption messages from a telegram | 1 | true |
| updateStrategy | The strategy to receive updates from Telegram API. Long polling or webhooks. | LONG_POLLING | true |
| backOffStrategy | Backoff strategy for failed requests to Telegram API. Impl of BackOff interface must be with public empty constructor | ExponentialBackOff | true |
| proxyType | The proxy type for executing requests to Telegram API. | NO_PROXY | true |
| proxyUrl | The proxy url in format `host:port` or if auth needed `host:port:username:password`. | - | false |
| cacheLiveDuration | Cache lifetime used in `DefaultTelegramBotSession` | 1 | true |
| cacheLiveDurationUnit | The `TimeUnit` which will be applied to `cacheLiveDuration` | hours | true |
| longPolling | LongPolling properties. | [LongPolling properties](#Longpolling-properties) | false |
| Name | Description | Default Value | Required |
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|----------|
| maxUserParallelRequests | Max number of threads used for consumption messages from a telegram for concrete user. 0 - no restrictions | 1 | true |
| consumeMaxThreads | Max number of threads used for consumption messages from a telegram | 10 | true |
| maxMessagesInQueue | Limits the number of updates to be store in memory queue for update processing. 0 - no limit. Defaults to (consumeMaxThreads * 1.5). | 15 | true |
| updateStrategy | The strategy to receive updates from Telegram API. Long polling or webhooks. | LONG_POLLING | true |
| backOffStrategy | Backoff strategy for failed requests to Telegram API. Impl of BackOff interface must be with public empty constructor | ExponentialBackOff | true |
| proxyType | The proxy type for executing requests to Telegram API. | NO_PROXY | true |
| proxyUrl | The proxy url in format `host:port` or if auth needed `host:port:username:password`. | - | false |
| cacheLiveDuration | Cache lifetime used in `DefaultTelegramBotSession` | 1 | true |
| cacheLiveDurationUnit | The `TimeUnit` which will be applied to `cacheLiveDuration` | hours | true |
| longPolling | LongPolling properties. | [LongPolling properties](#Longpolling-properties) | false |

#### LongPolling properties

Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ sourceCompatibility = '17'

bootJar.enabled = false

jar {
enabled = true
archiveClassifier = ''
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.drednote.telegram.filter.post.PostUpdateFilter;
import io.github.drednote.telegram.filter.pre.PreUpdateFilter;
import io.github.drednote.telegram.handler.UpdateHandler;
import io.github.drednote.telegram.response.AbstractTelegramResponse;
import io.github.drednote.telegram.response.SimpleMessageTelegramResponse;
import io.github.drednote.telegram.response.TelegramResponse;
import io.github.drednote.telegram.utils.Assert;
Expand All @@ -23,12 +24,12 @@
import org.telegram.telegrambots.meta.generics.TelegramClient;

/**
* The {@code DefaultTelegramBot} class extends the {@code TelegramLongPollingBot} class and
* serves as the main bot implementation for handling updates. The bot overrides the
* `onUpdateReceived()` method to handle incoming updates. Within the {@link #onUpdateReceived}
* method, a {@link DefaultUpdateRequest} is created to encapsulate the {@link Update}. The request
* is then processed through a series of steps: pre-filtering, handling, post-filtering, and
* answering. Any exceptions thrown during processing are handled by the exception handler
* The {@code DefaultTelegramBot} class extends the {@code TelegramBot} class and serves as the main
* bot implementation for handling updates. The bot overrides the `onUpdateReceived()` method to
* handle incoming updates. Within the {@link #onUpdateReceived} method, a
* {@link DefaultUpdateRequest} is created to encapsulate the {@link Update}. The request is then
* processed through a series of steps: pre-filtering, handling, post-filtering, and answering. Any
* exceptions thrown during processing are handled by the exception handler
*
* @author Ivan Galushko
* @see UpdateHandler
Expand Down Expand Up @@ -69,8 +70,8 @@
private final TelegramClient telegramClient;

/**
* Creates a new instance of the {@code DefaultTelegramBot} class with the provided
* properties and dependencies
* Creates a new instance of the {@code DefaultTelegramBot} class with the provided properties
* and dependencies
*
* @param properties the Telegram properties, not null
* @param updateHandlers the collection of update handlers, not null
Expand Down Expand Up @@ -222,6 +223,10 @@
if (response instanceof SimpleMessageTelegramResponse simpleMessageTelegramResponse) {
simpleMessageTelegramResponse.setMessageSource(messageSource);
}
if (response instanceof AbstractTelegramResponse abstractTelegramResponse) {
abstractTelegramResponse.setParseMode(
telegramProperties.getUpdateHandler().getParseMode());

Check warning on line 228 in src/main/java/io/github/drednote/telegram/core/DefaultTelegramBot.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/drednote/telegram/core/DefaultTelegramBot.java#L227-L228

Added lines #L227 - L228 were not covered by tests
}
response.process(request);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
*/
public class ParsedUpdateRequest extends AbstractUpdateRequest {

public ParsedUpdateRequest(Update update) {
private final TelegramClient telegramClient;

public ParsedUpdateRequest(Update update, TelegramClient telegramClient) {
super(update);
this.telegramClient = telegramClient;
}

@Override
public TelegramClient getAbsSender() {
throw new UnsupportedOperationException("Not supported in this implementation");
return telegramClient;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.github.drednote.telegram.filter.pre.PriorityPreUpdateFilter;
import io.github.drednote.telegram.filter.pre.RoleFilter;
import io.github.drednote.telegram.filter.pre.ScenarioUpdateHandlerPopular;
import io.github.drednote.telegram.filter.pre.UserRateLimitRequestFilter;
import java.util.Map;
import org.springframework.core.Ordered;

Expand All @@ -24,7 +23,7 @@ public final class FilterOrder {

// ------- Orders for priority pre filters ------- //
public static final Map<Class<? extends PriorityPreUpdateFilter>, Integer> PRIORITY_PRE_FILTERS = Map.of(
UserRateLimitRequestFilter.class, FilterOrder.HIGHEST_PRECEDENCE,
// UserRateLimitRequestFilter.class, FilterOrder.HIGHEST_PRECEDENCE,
RoleFilter.class, FilterOrder.HIGHEST_PRECEDENCE + 100,
ScenarioUpdateHandlerPopular.class, FilterOrder.HIGHEST_PRECEDENCE + 200,
ControllerUpdateHandlerPopular.class, FilterOrder.HIGHEST_PRECEDENCE + 300
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.drednote.telegram.filter.post.NotHandledUpdateFilter;
import io.github.drednote.telegram.filter.pre.AccessPermissionFilter;
import io.github.drednote.telegram.filter.pre.UserRateLimitRequestFilter;
import io.github.drednote.telegram.session.UserRateLimitRequestFilter;
import io.github.drednote.telegram.response.NotHandledTelegramResponse;
import java.time.temporal.ChronoUnit;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.github.drednote.telegram.filter.pre.HasRoleRequestFilter;
import io.github.drednote.telegram.filter.pre.PreUpdateFilter;
import io.github.drednote.telegram.filter.pre.RoleFilter;
import io.github.drednote.telegram.filter.pre.UserRateLimitRequestFilter;
import io.github.drednote.telegram.handler.UpdateHandlerAutoConfiguration;
import io.github.drednote.telegram.utils.FieldProvider;
import org.springframework.beans.factory.ObjectProvider;
Expand Down Expand Up @@ -56,12 +55,6 @@ public AccessPermissionFilter accessPermissionFilter(PermissionProperties permis
return new AccessPermissionFilter(permissionProperties);
}

@Bean
@ConditionalOnMissingBean
public UserRateLimitRequestFilter concurrentUserRequestFilter(FilterProperties properties) {
return new UserRateLimitRequestFilter(properties);
}

@Bean
@ConditionalOnMissingBean
public NotHandledUpdateFilter notHandledUpdateFilter() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.drednote.telegram.response.InternalErrorTelegramResponse;
import io.github.drednote.telegram.session.SessionProperties;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -55,11 +56,28 @@ public class UpdateHandlerProperties {
*/
@NonNull
private boolean serializeJavaObjectWithJackson = true;
/**
* Default parse mode of a text message sent to telegram. Applies only if you return raw string
* from update processing ({@link UpdateHandler})
*/
@NonNull
private ParseMode parseMode = ParseMode.NO;
/**
* If scenario is enabled and {@link SessionProperties#getMaxThreadsPerUser} is set value other
* than 1, throws an error with a warning about using scenario safe only when
* getMaxThreadsPerUser is set to 1.
*/
@NonNull
private boolean enabledWarningForScenario = true;

@RequiredArgsConstructor
@Getter
public enum ParseMode {
NO(null),
MARKDOWN("Markdown"),
MARKDOWN_V2("MarkdownV2"),
HTML("html");

private final String value;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.drednote.telegram.response;

import static org.telegram.telegrambots.meta.api.methods.ParseMode.MARKDOWN;

import io.github.drednote.telegram.core.request.UpdateRequest;
import io.github.drednote.telegram.handler.UpdateHandlerProperties.ParseMode;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.message.Message;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
Expand All @@ -15,6 +14,8 @@
*/
public abstract class AbstractTelegramResponse implements TelegramResponse {

protected ParseMode parseMode = ParseMode.NO;

/**
* Sends a text message to the specified chat using the provided string
*
Expand All @@ -28,7 +29,11 @@
TelegramClient absSender = request.getAbsSender();
Long chatId = request.getChatId();
SendMessage sendMessage = new SendMessage(chatId.toString(), string);
sendMessage.setParseMode(MARKDOWN);
sendMessage.setParseMode(parseMode.getValue());
return absSender.execute(sendMessage);
}

public void setParseMode(ParseMode parseMode) {
this.parseMode = parseMode;
}

Check warning on line 38 in src/main/java/io/github/drednote/telegram/response/AbstractTelegramResponse.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/drednote/telegram/response/AbstractTelegramResponse.java#L37-L38

Added lines #L37 - L38 were not covered by tests
}
Loading
Loading