Skip to content

Commit

Permalink
完善q群管理api
Browse files Browse the repository at this point in the history
完善q群管理api
Reformat code
  • Loading branch information
mcdoeswhat committed Mar 10, 2022
1 parent 22eec7c commit d5fddfd
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>me.albert</groupId>
<artifactId>AmazingBot</artifactId>
<packaging>jar</packaging>
<version>4.0.3</version>
<version>4.0.4</version>
<name>AmazingBot</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public boolean isKickMe() {
public long getOperatorID() {
return operator_id;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.albert.amazingbot.events.notice.group;

import me.albert.amazingbot.bot.Bot;
import me.albert.amazingbot.objects.contact.Member;
import org.jetbrains.annotations.Nullable;

public class GroupMemberIncreaseEvent extends GroupNoticeEvent {

protected String sub_type;
Expand All @@ -16,4 +20,17 @@ public String getSubType() {
public long getOperatorID() {
return operator_id;
}

public @Nullable Member getMember(boolean... noCache) {
return Bot.getApi().getMemberInfo(group_id, user_id, noCache.length > 0);
}

public boolean kick(boolean rejectAddRequest) {
return Bot.getApi().groupKick(group_id, user_id, rejectAddRequest);
}

public boolean mute(int duration) {
return Bot.getApi().groupMute(group_id, user_id, duration);
}

}
13 changes: 6 additions & 7 deletions src/me/albert/amazingbot/listeners/OnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.albert.amazingbot.AmazingBot;
import me.albert.amazingbot.events.message.GroupMessageEvent;
import me.albert.amazingbot.events.message.MessageReceiveEvent;
import me.albert.amazingbot.utils.command.ConsoleSender;
import me.albert.amazingbot.utils.command.ConsoleSenderLegacy;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -40,25 +39,25 @@ private static String getLabel(Long groupID) {
return AmazingBot.getInstance().getConfig().getString("groups." + groupID + ".command") + " ";
}

public static CommandSender getSender(long contactID,boolean isGroup) {
public static CommandSender getSender(long contactID, boolean isGroup) {
CommandSender sender = null;
if (spigot == 1) {
sender = new ConsoleSenderLegacy(contactID,isGroup);
sender = new ConsoleSenderLegacy(contactID, isGroup);
}
if (spigot == 2) {
sender = new ConsoleSender(contactID,isGroup);
sender = new ConsoleSender(contactID, isGroup);
}
if (spigot == 0) {
try {
Class.forName("org.bukkit.command.CommandSender$Spigot");
} catch (Exception ignored) {
spigot = 1;
AmazingBot.getInstance().getLogger().info("§a检测到旧版本Minecraft,启用旧版本指令信息返回...");
sender = new ConsoleSenderLegacy(contactID,isGroup);
sender = new ConsoleSenderLegacy(contactID, isGroup);
}
if (sender == null) {
spigot = 2;
sender = new ConsoleSender(contactID,isGroup);
sender = new ConsoleSender(contactID, isGroup);
}
}
return sender;
Expand All @@ -77,7 +76,7 @@ public void onCommand(GroupMessageEvent e) {
e.response("命令已提交");
Bukkit.getScheduler().runTaskAsynchronously(AmazingBot.getInstance(), () -> {
String cmd = msg.substring(label.length());
CommandSender sender = getSender(e.getGroupID(),true);
CommandSender sender = getSender(e.getGroupID(), true);
Bukkit.getScheduler().runTask(AmazingBot.getInstance(), () -> Bukkit.dispatchCommand(sender, cmd));
String log = AmazingBot.getInstance().getConfig().getString("messages.log_command")
.replace("%user%", String.valueOf(e.getUserID())).replace("%cmd%", cmd)
Expand Down
12 changes: 12 additions & 0 deletions src/me/albert/amazingbot/objects/contact/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public List<Member> getMemberList() {
return Bot.getApi().getGroupMemberList(group_id);
}

public boolean kick(long userID, boolean rejectAddRequest) {
return Bot.getApi().groupKick(group_id, userID, rejectAddRequest);
}

public boolean mute(int duration, long user_id) {
return Bot.getApi().groupMute(group_id, user_id, duration);
}

public Member getMember(long userID, boolean... noCache) {
return Bot.getApi().getMemberInfo(group_id, userID, noCache.length > 0);
}

public boolean toggleWholeMute(boolean enable) {
return Bot.getApi().toggleGroupWholeMute(group_id, enable);
}
Expand Down
8 changes: 8 additions & 0 deletions src/me/albert/amazingbot/objects/contact/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,13 @@ public long sendMsg(String msg, boolean... auto_escape) {
return Bot.getApi().sendPrivateMsg(user_id, group_id, msg, auto_escape);
}

public boolean mute(int duration) {
return Bot.getApi().groupMute(group_id, user_id, duration);
}

public boolean kick(boolean rejectAddRequest) {
return Bot.getApi().groupKick(group_id, user_id, rejectAddRequest);
}


}
9 changes: 4 additions & 5 deletions src/me/albert/amazingbot/utils/command/ConsoleSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.albert.amazingbot.AmazingBot;
import me.albert.amazingbot.bot.Bot;
import me.albert.amazingbot.events.message.MessageReceiveEvent;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.Server;
Expand All @@ -28,7 +27,7 @@ public class ConsoleSender implements ConsoleCommandSender {
private final ConsoleSender instance;
private BukkitTask task = null;

public ConsoleSender(long contactID,boolean isGroup) {
public ConsoleSender(long contactID, boolean isGroup) {
this.contactID = contactID;
this.isGroup = isGroup;
instance = this;
Expand Down Expand Up @@ -69,10 +68,10 @@ public void sendMessage(@NotNull String message) {
}
String msg = response.toString().trim();
if (!msg.isEmpty()) {
if (isGroup){
Bot.getApi().sendGroupMsg(contactID,msg,true);
if (isGroup) {
Bot.getApi().sendGroupMsg(contactID, msg, true);
} else {
Bot.getApi().sendPrivateMsg(contactID,msg,true);
Bot.getApi().sendPrivateMsg(contactID, msg, true);
}
output.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.albert.amazingbot.AmazingBot;
import me.albert.amazingbot.bot.Bot;
import me.albert.amazingbot.events.message.MessageReceiveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.ConsoleCommandSender;
Expand All @@ -26,7 +25,7 @@ public class ConsoleSenderLegacy implements ConsoleCommandSender {
private final ArrayList<String> tempOutPut = new ArrayList<>();
private BukkitTask task = null;

public ConsoleSenderLegacy(long contactID,boolean isGroup) {
public ConsoleSenderLegacy(long contactID, boolean isGroup) {
this.contactID = contactID;
this.isGroup = isGroup;
}
Expand Down Expand Up @@ -72,10 +71,10 @@ public void sendMessage(@NotNull String message) {
}
String msg = response.toString().trim();
if (!msg.isEmpty()) {
if (isGroup){
Bot.getApi().sendGroupMsg(contactID,msg,true);
if (isGroup) {
Bot.getApi().sendGroupMsg(contactID, msg, true);
} else {
Bot.getApi().sendPrivateMsg(contactID,msg,true);
Bot.getApi().sendPrivateMsg(contactID, msg, true);
}
output.clear();
}
Expand Down

0 comments on commit d5fddfd

Please sign in to comment.