Skip to content

Commit

Permalink
create github-actions.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
XD-cods committed Jun 26, 2024
1 parent 1f63e01 commit 3978e8b
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 198 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build project
on:
push:
branches:
- master
pull_request:
branches:
- *
jobs:

Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- name: Set up JDK 17 for x64
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
architecture: x64


- name: Build & Test
run:
mvn -B clean package
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mBuild:
mvn clean -Dmaven.test.skip package -e
run:
java -jar target/knowBot-1.0-SNAPSHOT-jar-with-dependencies.jar
doc:
docker-compose up -d --build
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
- SPRING_DATA_MONGODB_DATABASE=${SPRING_DATA_MONGODB_DATABASE}
- SPRING_DATA_MONGODB_URI=${SPRING_DATA_MONGODB_URI}


grafana:
image: "grafana/grafana-enterprise:10.4.2"
ports:
- "3000:3000"
depends_on:
- bot
- bot
- prometheus
29 changes: 17 additions & 12 deletions src/main/java/org/example/QuizBotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ public class QuizBotListener implements UpdatesListener {
public QuizBotListener(TelegramBot bot, QuizService quizService) {
this.bot = bot;
this.quizService = quizService;
this.sessionCache = Cache2kBuilder.of(Long.class, QuizBotSession.class).expireAfterWrite(120, TimeUnit.SECONDS).addListener((CacheEntryExpiredListener<Long, QuizBotSession>) (cache, entry) -> {
clearLastMessageKeyboard(cache.get(entry.getKey()), entry.getKey());
sendMessage(entry.getKey(), "You've been thinking too long, so you'll have to start over." + " Write /start or /choice.");
}).addListener((CacheEntryCreatedListener<Long, QuizBotSession>) (cache, entry) -> sendMessage(entry.getKey(), UserBotConstants.STARTING_MESSAGE)).build();
}

private static String getQuizStatText(int quizAmount, int rightAnswerCounter) {
return String.format("❓ <b>Question number:</b> %d" + "\n\n" + "✅ <b>Right answers:</b> %d\\%d" + "\n\n" + "Input " + UserBotConstants.START_QUIZ_COMMAND + " to start quiz or chose quiz another quiz " + UserBotConstants.CHOOSE_TOPIC_COMMAND, quizAmount, rightAnswerCounter, quizAmount);
}

private static String getCanceledQuizStatText(int questionCount, int rightAnswerCounter) {
return String.format("❓<b>You canceled quiz</b>\n" + "\n" + "<b>The questions were:</b> %d\n\n" + "✅ <b>Right answers:</b> %d\\%d\n" + "\n" + "Input " + UserBotConstants.START_QUIZ_COMMAND + " to start quiz or chose quiz another quiz " + UserBotConstants.CHOOSE_TOPIC_COMMAND, questionCount, rightAnswerCounter, questionCount);
this.sessionCache = Cache2kBuilder.of(Long.class, QuizBotSession.class)
.expireAfterWrite(120, TimeUnit.SECONDS)
.addListener((CacheEntryExpiredListener<Long, QuizBotSession>) (cache, entry) -> {
clearLastMessageKeyboard(cache.get(entry.getKey()), entry.getKey());
sendMessage(entry.getKey(), "You've been thinking too long, so you'll have " +
"to start over." + " Write /start or /choice.");
})
.build();
}

@Override
Expand Down Expand Up @@ -101,6 +97,7 @@ public int process(List<Update> updates) throws NullPointerException {
switch (messageText) {
case UserBotConstants.START_BOT_COMMAND -> {
clearLastMessageKeyboard(quizBotSession, userId);
sendMessage(userId, UserBotConstants.STARTING_MESSAGE);
sessionCache.remove(userId);
sessionCache.put(userId, new QuizBotSession(QuizBotSessionMode.SESSION_CREATED));
return UpdatesListener.CONFIRMED_UPDATES_ALL;
Expand Down Expand Up @@ -129,6 +126,14 @@ public int process(List<Update> updates) throws NullPointerException {
return UpdatesListener.CONFIRMED_UPDATES_ALL;
}

private static String getQuizStatText(int quizAmount, int rightAnswerCounter) {
return String.format("❓ <b>Question number:</b> %d" + "\n\n" + "✅ <b>Right answers:</b> %d\\%d" + "\n\n" + "Input " + UserBotConstants.START_QUIZ_COMMAND + " to start quiz or chose quiz another quiz " + UserBotConstants.CHOOSE_TOPIC_COMMAND, quizAmount, rightAnswerCounter, quizAmount);
}

private static String getCanceledQuizStatText(int questionCount, int rightAnswerCounter) {
return String.format("❓<b>You canceled quiz</b>\n" + "\n" + "<b>The questions were:</b> %d\n\n" + "✅ <b>Right answers:</b> %d\\%d\n" + "\n" + "Input " + UserBotConstants.START_QUIZ_COMMAND + " to start quiz or chose quiz another quiz " + UserBotConstants.CHOOSE_TOPIC_COMMAND, questionCount, rightAnswerCounter, questionCount);
}

private void setCountOfQuiz(String messageText, Long userId, QuizBotSession quizBotSession) {
if (!messageText.matches("^[1-9][0-9]*$")) {
sendMessage(userId, "Input a number or input " + UserBotConstants.CANCEL_COMMAND + " for cancel count of question choice");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/example/configs/MongoDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public ChangeStreamIterable<Document> runEventListener(MongoTemplate mongoTempla
}
case "delete" -> quizService.updateTopics();
}

});
return changeStream;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/example/model/PermanentUserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
public class PermanentUserInfo {
@Id
@Field(name = "userId")
private Long userId;
private Long userId = 0L;
@Field(name = "userName")
private String userName;
private String userName = "";

public PermanentUserInfo() {
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/example/model/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Question {
@Id
@JsonIgnore
private ObjectId id;
private ObjectId id = new ObjectId();
private String question = "";
private String answerDescription = "";
private List<QuestionOption> optionList = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/example/model/QuizBotSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class QuizBotSession {
private UserQuizSession userQuizSession;
private String currentTopicName = "";
private int lastKeyboardBotMessageId = 0;
private String lastKeyboardBotMessageText;
private String lastKeyboardBotMessageText ="";
private int countOfQuestion = 0;

public QuizBotSession(QuizBotSessionMode botSessionMode) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/example/services/QuizService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<String> getTopics() {
return topicsCache.get("topics");
}

public synchronized void addTopic(String topicName){
public void addTopic(String topicName){
lock.lock();
try {
List<String> topics = new ArrayList<>(topicsCache.get("topics"));
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="125 MB"/>
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
</RollingFile>
</Appenders>
Expand All @@ -17,6 +17,5 @@
<AppenderRef ref="RollingFile"/>
<AppenderRef ref="console"/>
</Root>
<Logger name="org.springframework.data.redis.core.RedisConnectionUtils" level="ERROR"/>
</Loggers>
</Configuration>
4 changes: 0 additions & 4 deletions src/main/resources/topics

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/java/org/example/QuizQuestionsBotListenerTest.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/java/org/example/model/QuestionOptionTest.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/test/java/org/example/model/QuestionTest.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/test/java/org/example/model/QuizQuestionsTest.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/test/java/org/example/model/UserQuizQuestionsSessionTest.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/test/java/services/QuizServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package services;

public class QuizServiceTest {

}
4 changes: 4 additions & 0 deletions src/test/java/services/UsersService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package services;

public class UsersService {
}

0 comments on commit 3978e8b

Please sign in to comment.