Skip to content

Commit

Permalink
add(*): *
Browse files Browse the repository at this point in the history
  • Loading branch information
monyuan committed Jan 11, 2024
1 parent 260751a commit d77d63e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Notify Me

当有新评论、新文章、等待审核的评论、等待审核的文章时将消息推送到微信、企业微信、飞书、钉钉等12个应用
当有新评论、新文章、等待审核的评论、等待审核的文章时将消息推送到微信、QQ、企业微信、飞书、钉钉等12个应用

- 使用了AnPush推送服务,有免费额度,个人博客够用
- 不够用可以多注册几个账号薅羊毛,但是不建议,多支持下开发者
Expand All @@ -10,8 +10,8 @@
安装插件后,会在halo后台左侧生成一个"通知我"的菜单(往下拉),然后点击进入设置页面。

- 站点地址就是你的域名,比如:https://baidu.com
- API密钥 [在这里获取](https://anpush.com/ApPush)
- 通道ID [在这里获取](https://anpush.com/ApChannel)
- API密钥 [在这里获取](https://anpush.com/push/tool)
- 通道ID [在这里获取](https://anpush.com/push/setting)

**注意**
如果你用的是微信公众号通道,请一定要勾选这个选项,其他通道不要勾选!
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.0.2
version=1.1.0
#org.gradle.java.home=/Users/mon/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home
3 changes: 3 additions & 0 deletions src/main/java/org/xiqi/notifyme/domain/NotifyMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ public class NotifyMe extends AbstractExtension {
@Schema(defaultValue = "false")
private Boolean postAuditsStatus; // 文章审核通知开关

@Schema(defaultValue = "false")
private Boolean postDelStatus; // 文章删除通知开关

}
5 changes: 5 additions & 0 deletions src/main/java/org/xiqi/notifyme/event/PushEventNotify.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public void onAdd(Extension extension) {
eventPublisher.publishEvent(NotifyBaseEvent.getEx(this, extension));
}

@Override
public void onDelete(Extension extension) {
eventPublisher.publishEvent(NotifyBaseEvent.getEx(this, extension));
}

@Override
public void registerDisposeHook(Runnable dispose) {
this.disposeHook = dispose;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/xiqi/notifyme/strategy/CommentStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class CommentStrategy implements NotifyStrategy {
public void process(NotifyBaseEvent event, NotifyMe setting) {
Comment commentInfo = (Comment) event.getExtension();
Comment.CommentSpec commentSpec = commentInfo.getSpec();
if (!commentSpec.getOwner().getName().equals("admin")) {
if (!commentSpec.getOwner().getName().equals("admin") &&
commentInfo.getMetadata().getDeletionTimestamp() == null) { // 这里有点坑爹,删除文章了也发通知删除评论通知
// 不是管理员的话就推送通知
String postMetaName = commentSpec.getSubjectRef().getName();
Optional<Post> postInfo = client.fetch(Post.class, postMetaName);
Expand All @@ -35,7 +36,6 @@ public void process(NotifyBaseEvent event, NotifyMe setting) {
}
}
});

}
}

Expand Down
39 changes: 33 additions & 6 deletions src/main/java/org/xiqi/notifyme/strategy/PostStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class PostStrategy implements NotifyStrategy {

private final PushUtil pushUtil;

private Integer counter = 0;

@Override
public void process(NotifyBaseEvent event, NotifyMe setting) {
/*
Expand All @@ -36,11 +34,19 @@ public void process(NotifyBaseEvent event, NotifyMe setting) {
Extension extension = event.getExtension();
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.schedule(() -> {
if (extension.getMetadata().getLabels().containsKey("content.halo.run/deleted") &&
extension.getMetadata().getLabels().get("content.halo.run/deleted").equals("true")
) {
//删除文章到这里就终止了
delete((Post) extension, setting);
return;
}
Optional<Post> postInfo = client.fetch(Post.class, extension.getMetadata().getName());
postInfo.ifPresent(post -> {
if (post.getStatus().getPhase().equals("DRAFT") && !post.getSpec().getOwner()
.equals("admin")) { // 管理员的不管
audits(post, setting);
return;
}
if (post.getStatus().getPhase().equals("PUBLISHED")) {
publish(post, setting);
Expand All @@ -54,18 +60,32 @@ public void process(NotifyBaseEvent event, NotifyMe setting) {
private void publish(Post post, NotifyMe setting) { // 文章发布通知
if (setting.getPostStatus()) {
String title = "有新文章发布";
String content = "您的站点有新文章发布:" + String.format("[%s](%s)",
String content = String.format("您的站点有新文章发布:[%s](%s)\n\n %s",
post.getSpec().getTitle(),
setting.getSiteUrl() + post.getStatus().getPermalink());
setting.getSiteUrl() + post.getStatus().getPermalink(),
getExcerpt(post.getStatus().getExcerpt()));
push(title, content, setting);
}
}

private void audits(Post post, NotifyMe setting) { // 文章审核通知
if (setting.getPostAuditsStatus()) {
String title = "有新文章待审核: " + post.getSpec().getTitle();
String content = "您的站点有新文文章等待审核,\n\n " + String.format("[立刻审核](%s)",
setting.getSiteUrl() + "/console/posts");
String content =
String.format("%s...\n\n%s", getExcerpt(post.getStatus().getExcerpt()),
String.format("[立刻审核](%s)",
setting.getSiteUrl() + "/console/posts"));
push(title, content, setting);
}
}

private void delete(Post post, NotifyMe setting) { // 文章删除通知
if (setting.getPostDelStatus()) {
String title = "文章被删除";
String content = String.format("您的站点有新文章被删除:[%s](%s)\n\n %s",
post.getSpec().getTitle(),
setting.getSiteUrl() + post.getStatus().getPermalink(),
getExcerpt(post.getStatus().getExcerpt()));
push(title, content, setting);
}
}
Expand All @@ -76,5 +96,12 @@ private void push(String title, String content, NotifyMe setting) { // 推送
pushDo.setContent(content);
pushUtil.sendRequest(pushDo, setting);
}

private String getExcerpt(String excerpt) {
if (excerpt.length() > 50) {
return excerpt.substring(0, 50) + "...";
}
return excerpt;
}
}

2 changes: 1 addition & 1 deletion src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
logo: /notify.png
homepage: https://github.com/monyuan/notify-me
displayName: "通知我"
description: "当有评论时、新闻章时推送通知到微信、企业微信、飞书、钉钉、微信测试号、Slack等12个应用,使用了AnPush服务。"
description: "当有评论时、新闻章等事件时推送通知到微信、QQ、企业微信、飞书、钉钉、微信测试号、Slack等12个应用,使用了AnPush服务。"
license:
- name: "GPL-3.0"
url: "https://raw.githubusercontent.com/monyuan/notify-me/main/LICENSE"
18 changes: 12 additions & 6 deletions ui/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
wechatStatus: false,
commentAuditsStatus: false,
postAuditsStatus: false,
postDelStatus: false,
apiVersion: "org.xiqi.notifyme/v1alpha1",
kind: "NotifyMe",
metadata: {
Expand Down Expand Up @@ -154,7 +155,7 @@ export default {
<div class="!p-0 card-body">
<div style="padding: 40px;">
<div class="tip">
🎈 通过AnPush的接口实现的通知推送, 免费套餐已足够博客使用。 <a href="https://anpush.com/welcome?halo" target="_blank"
🎈 通过AnPush的接口实现的通知推送, 免费套餐已足够博客使用。 <a href="https://anpush.com/?halo" target="_blank"
style="text-decoration: underline;color: #000000;"> 获取密钥 > </a>
<br>
<div>根据官网描述可以推送至12个应用,我测试了微信、企业微信、微信测试号、飞书、钉钉都没有问题</div>
Expand Down Expand Up @@ -252,28 +253,33 @@ export default {
d="M2 12c0-.865.11-1.704.316-2.504A3 3 0 0 0 4.99 4.867a9.99 9.99 0 0 1 4.335-2.506a3 3 0 0 0 5.348 0a9.99 9.99 0 0 1 4.335 2.506a3 3 0 0 0 2.675 4.63c.206.8.316 1.638.316 2.503c0 .864-.11 1.703-.316 2.503a3 3 0 0 0-2.675 4.63a9.99 9.99 0 0 1-4.335 2.505a3 3 0 0 0-5.348 0a9.99 9.99 0 0 1-4.335-2.505a3 3 0 0 0-2.675-4.63C2.11 13.703 2 12.864 2 12Zm4.804 3c.63 1.091.81 2.346.564 3.524c.408.29.842.541 1.297.75A4.993 4.993 0 0 1 12 18c1.26 0 2.438.471 3.335 1.274c.455-.209.889-.46 1.297-.75A4.993 4.993 0 0 1 17.196 15a4.993 4.993 0 0 1 2.77-2.25a8.142 8.142 0 0 0 0-1.5A4.993 4.993 0 0 1 17.196 9a4.993 4.993 0 0 1-.564-3.524a7.991 7.991 0 0 0-1.297-.75A4.993 4.993 0 0 1 12 6a4.993 4.993 0 0 1-3.335-1.274a7.99 7.99 0 0 0-1.297.75A4.993 4.993 0 0 1 6.804 9a4.993 4.993 0 0 1-2.77 2.25a8.125 8.125 0 0 0 0 1.5A4.993 4.993 0 0 1 6.805 15ZM12 15a3 3 0 1 1 0-6a3 3 0 0 1 0 6Zm0-2a1 1 0 1 0 0-2a1 1 0 0 0 0 2Z">
</path>
</svg>
<span class="icon-title">功能设置</span>
<span class="icon-title">通知功能设置</span>
</div>
<div style="padding: 20px;"
class="formkit-inner inline-flex items-center w-full relative box-border border border-gray-300 formkit-invalid:border-red-500 h-9 rounded-base overflow-hidden focus-within:border-primary focus-within:shadow-sm sm:max-w-lg transition-all">
<div class="nm-checkbox">
<input class="toggle-all" type="checkbox" :checked="data.commentStatus"
v-model="data.commentStatus"/>
<label for="toggle-all"><span class="nm-checkbox-text">新评论通知</span></label>
<label for="toggle-all"><span class="nm-checkbox-text">新评论</span></label>
</div>
<div class="nm-checkbox">
<input class="toggle-all" type="checkbox" :checked="data.commentAuditsStatus"
v-model="data.commentAuditsStatus"/>
<label for="toggle-all"><span class="nm-checkbox-text">评论审核通知</span></label>
<label for="toggle-all"><span class="nm-checkbox-text">评论审核</span></label>
</div>
<div class="nm-checkbox">
<input class="toggle-all" type="checkbox" :checked="data.postStatus" v-model="data.postStatus"/>
<label for="toggle-all"><span class="nm-checkbox-text">文章发布通知</span></label>
<label for="toggle-all"><span class="nm-checkbox-text">文章发布</span></label>
</div>
<div class="nm-checkbox">
<input class="toggle-all" type="checkbox" :checked="data.postAuditsStatus"
v-model="data.postAuditsStatus"/>
<label for="toggle-all"><span class="nm-checkbox-text">投稿审核通知</span></label>
<label for="toggle-all"><span class="nm-checkbox-text">投稿审核</span></label>
</div>
<div class="nm-checkbox">
<input class="toggle-all" type="checkbox" :checked="data.postDelStatus"
v-model="data.postDelStatus"/>
<label for="toggle-all"><span class="nm-checkbox-text">文章删除</span></label>
</div>
</div>
</div>
Expand Down

0 comments on commit d77d63e

Please sign in to comment.