Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
given committed Mar 28, 2023
1 parent 4bc3802 commit d26c01f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'given'
version '1.0-SNAPSHOT'
version '0.0.3'

repositories {
mavenCentral()
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/MyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ public void onEnable() {
EventChannel<BotEvent> channel = GlobalEventChannel.INSTANCE
.parentScope(INSTANCE)
.filterIsInstance(BotEvent.class);
//命令转接
channel.subscribeAlways(MessageSyncEvent.class,event -> {
CommandSender sender = null;
if (event instanceof GroupMessageSyncEvent) {
sender = CommandSender.of((Member) event.getSender());
} else if (event instanceof GroupTempMessageSyncEvent) {
sender = CommandSender.of((NormalMember) event.getSender());
}
if (sender == null) return;
final var exception = CommandManager.INSTANCE.executeCommand(sender,event.getMessage(),false).getException();
if (exception == null) return;
exception.printStackTrace();
event.getSender().sendMessage(exception.toString());
});
//bind命令
channel.subscribeAlways(UserMessageEvent.class,event -> {
MessageChain chain = event.getMessage();
Expand All @@ -55,21 +41,6 @@ public void onEnable() {
}
}
});
//入群申请
final var pattern = Pattern.compile("^(?:问题:rks多少?\n答案:)(1?\\d\\.\\d\\d?)$");
channel.subscribeAlways(MemberJoinRequestEvent.class, event->{
final var matcher = pattern.matcher(event.getMessage());
if (matcher.matches() && Float.parseFloat(matcher.group(1)) <= 16.12) {
event.accept();
} else event.getGroup().sendMessage("新成员来了,快去审核。");
});
//离群通知
channel.subscribeAlways(MemberLeaveEvent.class, event -> {
if (event.getGroup().getId() == 282781491 || event.getGroup().getId() == 1047497524) {
String nick = event.getMember().getNick();
event.getGroup().sendMessage(nick+"离开了。");
}
});
//戳一戳
channel.filterIsInstance(NudgeEvent.class)
.filter(event -> event.getTarget().getId() == event.getBot().getId())
Expand Down
33 changes: 8 additions & 25 deletions src/main/java/TestCommand.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import net.mamoe.mirai.console.command.*;
import net.mamoe.mirai.console.command.java.JRawCommand;
import net.mamoe.mirai.console.command.java.JSimpleCommand;
import net.mamoe.mirai.contact.*;
import net.mamoe.mirai.message.data.*;
import org.jetbrains.annotations.NotNull;

public final class TestCommand extends JRawCommand {
public final class TestCommand extends JSimpleCommand {
public static final TestCommand INSTANCE = new TestCommand();
private TestCommand() {
super(MyPlugin.INSTANCE,"test");
}

@Override
public void onCommand(@NotNull CommandContext context, @NotNull MessageChain args) {
if (args.size() == 0) return;
CommandSender sender = context.getSender();
System.out.println(sender);
Contact contact = sender.getSubject();
int i = 1;
if (sender instanceof MemberCommandSender) {
Group group = (Group) sender.getSubject();
SingleMessage memberMessage = args.get(0);
Member member;
if (memberMessage instanceof At) {
member = group.getOrFail(((At) memberMessage).getTarget());
} else {
member = group.getOrFail(Long.parseLong(memberMessage.contentToString()));
}
sender = CommandSender.of(member);
} else {
i = 0;
sender = CommandSender.of((User) contact,false);
}
@Handler
public void onCommand(@NotNull CommandContext context,Member member,String... args) {
if (args.length == 0) return;
CommandSender sender = CommandSender.of(member);
StringBuilder stringBuilder = new StringBuilder();
for (; i < args.size(); i++) {
String s = args.get(i).contentToString();
for (String arg : args) {
String s = arg;
if (s.contains(" ")) {
s = "\"" + s + "\"";
}
Expand Down

0 comments on commit d26c01f

Please sign in to comment.