Skip to content

Commit b139bc4

Browse files
authored
Merge branch 'nagisa77:main' into main
2 parents 6f80b6c + f8c0335 commit b139bc4

37 files changed

Lines changed: 2220 additions & 33 deletions

.github/workflows/coffee-bot.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Coffee Bot
2+
3+
on:
4+
schedule:
5+
- cron: "0 23 * * 0-4"
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-coffee-bot:
10+
environment: Bots
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "20"
20+
cache: "npm"
21+
22+
- name: Install dependencies
23+
run: npm install --no-save @openai/agents tsx typescript
24+
25+
- name: Run coffee bot
26+
env:
27+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
28+
OPENISLE_TOKEN: ${{ secrets.OPENISLE_TOKEN }}
29+
APIFY_API_TOKEN: ${{ secrets.APIFY_API_TOKEN }}
30+
run: npx tsx bots/instance/coffee_bot.ts

.github/workflows/news-bot.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Daily News Bot
2+
3+
on:
4+
schedule:
5+
- cron: "0 23 * * 0-4"
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-daily-news-bot:
10+
environment: Bots
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "20"
20+
cache: "npm"
21+
22+
- name: Install dependencies
23+
run: npm install --no-save @openai/agents tsx typescript
24+
25+
- name: Run daily news bot
26+
env:
27+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
28+
OPENISLE_TOKEN: ${{ secrets.OPENISLE_TOKEN }}
29+
APIFY_API_TOKEN: ${{ secrets.APIFY_API_TOKEN }}
30+
run: npx tsx bots/instance/daily_news_bot.ts
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Open Source Reply Bot
2+
3+
on:
4+
schedule:
5+
- cron: "*/30 * * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-open-source-reply-bot:
10+
environment: Bots
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "20"
20+
cache: "npm"
21+
22+
- name: Install dependencies
23+
run: npm install --no-save @openai/agents tsx typescript
24+
25+
- name: Run open source reply bot
26+
env:
27+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
28+
OPENISLE_TOKEN: ${{ secrets.OPENISLE_TOKEN_BOT_1 }}
29+
APIFY_API_TOKEN: ${{ secrets.APIFY_API_TOKEN }}
30+
run: npx tsx bots/instance/open_source_reply_bot.ts

.github/workflows/reply-bots.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Reply Bots
2+
3+
on:
4+
schedule:
5+
- cron: "*/30 * * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-reply-bot:
10+
environment: Bots
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "20"
20+
cache: "npm"
21+
22+
- name: Install dependencies
23+
run: npm install --no-save @openai/agents tsx typescript
24+
25+
- name: Run reply bot
26+
env:
27+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
28+
OPENISLE_TOKEN: ${{ secrets.OPENISLE_TOKEN }}
29+
APIFY_API_TOKEN: ${{ secrets.APIFY_API_TOKEN }}
30+
run: npx tsx bots/instance/reply_bot.ts

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OpenIsle 是一个使用 Spring Boot 和 Vue 3 构建的全栈开源社区平台
2626
- 集成 OpenAI 提供的 Markdown 格式化功能
2727
- 通过环境变量可调整密码强度、登录方式、保护码等多种配置
2828
- 支持图片上传,默认使用腾讯云 COS 扩展
29-
- 默认头像使用 DiceBear Avatars,可通过 `AVATAR_STYLE``AVATAR_SIZE` 环境变量自定义主题和大小
29+
- Bot 集成,可在平台内快速连接自定义机器人,并通过 Telegram 的 BotFather 创建和管理消息机器人,拓展社区互动渠道
3030
- 浏览器推送通知,离开网站也能及时收到提醒
3131

3232
## 🌟 项目优势
@@ -41,7 +41,7 @@ OpenIsle 是一个使用 Spring Boot 和 Vue 3 构建的全栈开源社区平台
4141

4242
## 🏘️ 社区
4343

44-
欢迎彼此交流和使用 OpenIsle,项目以开源方式提供,想了解更多可访问:<https://github.com/nagisa77/OpenIsle>
44+
- 欢迎彼此交流和使用 OpenIsle,项目以开源方式提供;如果遇到问题请到 GitHub 的 Issues 页面反馈,想发起话题讨论也可以前往源站 <https://www.open-isle.com>,这里提供更完整的社区板块与互动体验。
4545

4646
## 📋 授权
4747

backend/src/main/java/com/openisle/controller/CommentController.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.openisle.controller;
22

3+
import com.openisle.dto.CommentContextDto;
34
import com.openisle.dto.CommentDto;
45
import com.openisle.dto.CommentRequest;
56
import com.openisle.dto.PostChangeLogDto;
67
import com.openisle.dto.TimelineItemDto;
78
import com.openisle.mapper.CommentMapper;
89
import com.openisle.mapper.PostChangeLogMapper;
10+
import com.openisle.mapper.PostMapper;
911
import com.openisle.model.Comment;
1012
import com.openisle.model.CommentSort;
1113
import com.openisle.service.*;
@@ -40,6 +42,7 @@ public class CommentController {
4042
private final PointService pointService;
4143
private final PostChangeLogService changeLogService;
4244
private final PostChangeLogMapper postChangeLogMapper;
45+
private final PostMapper postMapper;
4346

4447
@Value("${app.captcha.enabled:false}")
4548
private boolean captchaEnabled;
@@ -184,6 +187,37 @@ public List<TimelineItemDto<?>> listComments(
184187
return itemDtoList;
185188
}
186189

190+
@GetMapping("/comments/{commentId}/context")
191+
@Operation(
192+
summary = "Comment context",
193+
description = "Get a comment along with its previous comments and related post"
194+
)
195+
@ApiResponse(
196+
responseCode = "200",
197+
description = "Comment context",
198+
content = @Content(schema = @Schema(implementation = CommentContextDto.class))
199+
)
200+
public ResponseEntity<CommentContextDto> getCommentContext(@PathVariable Long commentId) {
201+
log.debug("getCommentContext called for comment {}", commentId);
202+
Comment comment = commentService.getComment(commentId);
203+
CommentContextDto dto = new CommentContextDto();
204+
dto.setPost(postMapper.toSummaryDto(comment.getPost()));
205+
dto.setTargetComment(commentMapper.toDtoWithReplies(comment));
206+
dto.setPreviousComments(
207+
commentService
208+
.getCommentsBefore(comment)
209+
.stream()
210+
.map(commentMapper::toDtoWithReplies)
211+
.collect(Collectors.toList())
212+
);
213+
log.debug(
214+
"getCommentContext returning {} previous comments for comment {}",
215+
dto.getPreviousComments().size(),
216+
commentId
217+
);
218+
return ResponseEntity.ok(dto);
219+
}
220+
187221
@DeleteMapping("/comments/{id}")
188222
@Operation(summary = "Delete comment", description = "Delete a comment")
189223
@ApiResponse(responseCode = "200", description = "Deleted")

backend/src/main/java/com/openisle/controller/PostController.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ public List<PostSummaryDto> listPosts(
224224
.collect(Collectors.toList());
225225
}
226226

227+
@GetMapping("/recent")
228+
@Operation(
229+
summary = "Recent posts",
230+
description = "List posts created within the specified number of minutes"
231+
)
232+
@ApiResponse(
233+
responseCode = "200",
234+
description = "Recent posts",
235+
content = @Content(
236+
array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))
237+
)
238+
)
239+
public List<PostSummaryDto> recentPosts(@RequestParam("minutes") int minutes) {
240+
return postService
241+
.listRecentPosts(minutes)
242+
.stream()
243+
.map(postMapper::toSummaryDto)
244+
.collect(Collectors.toList());
245+
}
246+
227247
@GetMapping("/ranking")
228248
@Operation(summary = "Ranking posts", description = "List posts by view rankings")
229249
@ApiResponse(

backend/src/main/java/com/openisle/dto/AuthorDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ public class AuthorDto {
1313
private String username;
1414
private String avatar;
1515
private MedalType displayMedal;
16+
private boolean bot;
1617
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.openisle.dto;
2+
3+
import java.util.List;
4+
import lombok.Data;
5+
6+
/**
7+
* DTO representing the context of a comment including its post and previous comments.
8+
*/
9+
@Data
10+
public class CommentContextDto {
11+
12+
private PostSummaryDto post;
13+
private CommentDto targetComment;
14+
private List<CommentDto> previousComments;
15+
}

backend/src/main/java/com/openisle/dto/UserDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ public class UserDto {
2828
private int point;
2929
private int currentLevel;
3030
private int nextLevelExp;
31+
private boolean bot;
3132
}

0 commit comments

Comments
 (0)