Skip to content

Commit

Permalink
Update 0.1.1 -> 0.1.2
Browse files Browse the repository at this point in the history
更好的权限检查方式
  • Loading branch information
Takeoff0518 committed Sep 12, 2023
1 parent c132696 commit 700cf35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "takeoff0518"
version = "0.1.1"
version = "0.1.2"

repositories {
maven("https://maven.aliyun.com/repository/public")
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/takeoff0518/MuteMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class MuteMe extends JavaPlugin {
public static final MuteMe INSTANCE = new MuteMe();

private MuteMe() {
super(new JvmPluginDescriptionBuilder("takeoff.muteme", "0.1.1")
super(new JvmPluginDescriptionBuilder("takeoff.muteme", "0.1.2")
.name("MuteMe")
.author("takeoff0518")
.build());
Expand All @@ -37,23 +37,21 @@ public void onEnable() {
});
eventChannel.subscribeAlways(GroupMessageEvent.class, g -> {
if (g.getMessage().contentToString().contains("muteme")) {
try {
if (checkPermission(g)) {
int muteTime = Config.INSTANCE.getMinTime() + new Random().nextInt(Config.INSTANCE.getMaxTime());
g.getSender().mute(muteTime);
String message = "被禁名称:" + g.getSender().getNick() + "\n被禁时间:" + muteTime + "秒\n解禁时间:" + formatDate(System.currentTimeMillis() + ((long) muteTime * 1000));
g.getGroup().sendMessage(message);
} catch (Exception exception) {
g.getGroup().sendMessage("出现了一点意外呢~");
exception.printStackTrace();
} else {
g.getGroup().sendMessage("可惜我不能禁言呢~");
}
}
if (g.getMessage().contentToString().contains("我好了")) {
try {
if (checkPermission(g)) {
g.getSender().mute(30);
g.getGroup().sendMessage("不许好,憋回去!");
} catch (Exception exception) {
g.getGroup().sendMessage("出现了一点意外呢~");
exception.printStackTrace();
} else {
g.getGroup().sendMessage("好好好");
}
}
});
Expand All @@ -65,4 +63,8 @@ String formatDate(long timeStamp) {
Instant instant = Instant.ofEpochMilli(timeStamp);
return formatter.format(instant.atZone(ZoneId.systemDefault()));
}

boolean checkPermission(@NotNull GroupMessageEvent g) {
return g.getSender().getPermission().getLevel() < g.getGroup().getBotPermission().getLevel();
}
}

0 comments on commit 700cf35

Please sign in to comment.