Skip to content

Commit

Permalink
移除HTTP-API残留
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamVoid committed Aug 14, 2024
1 parent d30947d commit 999f984
Show file tree
Hide file tree
Showing 62 changed files with 144 additions and 1,365 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,5 @@ public void loadConfig() {
Database.Settings.Pool.MaximumPoolSize = plugin.getConfig().getInt("database.pool.maximumPoolSize", Database.Settings.Pool.MaximumPoolSize);
Database.Settings.Pool.KeepaliveTime = plugin.getConfig().getInt("database.pool.keepaliveTime", Database.Settings.Pool.KeepaliveTime);
Database.Settings.Pool.MinimumIdle = plugin.getConfig().getInt("database.pool.minimumIdle", Database.Settings.Pool.MinimumIdle);

HttpApi.Url = plugin.getConfig().getString("http-api.url", HttpApi.Url);
HttpApi.MessageFetch.Interval = plugin.getConfig().getInt("http-api.message-fetch.interval", HttpApi.MessageFetch.Interval);
HttpApi.MessageFetch.Count = plugin.getConfig().getInt("http-api.message-fetch.count", HttpApi.MessageFetch.Count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ public class BukkitPlugin extends JavaPlugin implements Platform {
private MiraiEvent MiraiEvent;
private MiraiAutoLogin MiraiAutoLogin;
private final LifeCycle lifeCycle;
private final PluginConfig platformConfig;
private final LibraryLoader loader;

public BukkitPlugin(){
lifeCycle = new LifeCycle(this);
lifeCycle.startUp(getLogger());
platformConfig = new BukkitConfig(this);
new BukkitConfig(this);
loader = new LibraryLoader((URLClassLoader) this.getClassLoader());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.dreamvoid.miraimc.bukkit.event.message.passive;

import me.dreamvoid.miraimc.event.EventType;
import me.dreamvoid.miraimc.httpapi.response.FetchMessage;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.code.MiraiCode;
import net.mamoe.mirai.message.data.MessageChainBuilder;
Expand All @@ -22,54 +20,10 @@ public AbstractMessageEvent(MessageEvent event){
super(true);
this.event = event;

type = EventType.CORE;
BotID = event.getBot().getId();

SenderID = event.getSender().getId();
SenderName = event.getSenderName();

MessageContent = event.getMessage().contentToString();
MessageMiraiCode = event.getMessage().serializeToMiraiCode();
Time = event.getTime();
}

public AbstractMessageEvent(long BotID, FetchMessage.Data data) {
super(true);

type = EventType.HTTPAPI;
this.BotID = BotID;

SenderID = data.sender.id;
SenderName = data.sender.nickname + data.sender.memberName;

for(FetchMessage.Data.MessageChain chain : data.messageChain){
switch (chain.type){
case "Source":
Time = chain.time;
break;
case "Code":
MessageMiraiCode = chain.code;
break;
case "Plain":
MessageContent = String.format("%s%s", MessageContent, chain.text);
break;
default:
MessageContent = String.format("%s[%s]", MessageContent, chain.type);
break;
}
}
}

private static final HandlerList handlers = new HandlerList();
private MessageEvent event;

private final EventType type;
private final long BotID;
private final long SenderID;
private final String SenderName;
private String MessageContent;
private String MessageMiraiCode;
private int Time;
private final MessageEvent event;

public @NotNull HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
Expand All @@ -79,23 +33,23 @@ public AbstractMessageEvent(long BotID, FetchMessage.Data data) {
* @return 机器人ID
*/
public long getBotID(){
return BotID;
return event.getBot().getId();
}

/**
* 返回发送这条信息的发送者ID
* @return 发送者ID
*/
public long getSenderID(){
return SenderID;
return event.getSender().getId();
}

/**
* 返回发送这条信息的发送者昵称
* @return 发送者昵称
*/
public String getSenderName(){
return SenderName;
return event.getSenderName();
}

/**
Expand All @@ -117,7 +71,7 @@ public String getSenderNick(){
* @return 转换字符串后的消息内容
*/
public String getMessage(){
return MessageContent;
return event.getMessage().contentToString();
}

/**
Expand Down Expand Up @@ -152,15 +106,15 @@ public String getMessageToString(){
* @return 带Mirai Code的消息内容
*/
public String getMessageToMiraiCode(){
return MessageMiraiCode;
return event.getMessage().serializeToMiraiCode();
}

/**
* 返回接收到这条信息的时间
* @return 发送时间
*/
public int getTime() {
return Time;
return event.getTime();
}

/**
Expand Down Expand Up @@ -274,11 +228,4 @@ public String getQuoteReplyMessageToMiraiCode() {
return !Objects.isNull(quoteReply) ? quoteReply.getSource().getOriginalMessage().serializeToMiraiCode() : null;
}

/**
* 获取事件类型(用于判断机器人工作模式)
* @return 事件类型
*/
public EventType getType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package me.dreamvoid.miraimc.bukkit.event.message.passive;

import me.dreamvoid.miraimc.api.bot.MiraiFriend;
import me.dreamvoid.miraimc.event.EventType;
import me.dreamvoid.miraimc.httpapi.MiraiHttpAPI;
import me.dreamvoid.miraimc.httpapi.exception.AbnormalStatusException;
import me.dreamvoid.miraimc.httpapi.response.FetchMessage;
import me.dreamvoid.miraimc.internal.Utils;
import net.mamoe.mirai.event.events.FriendMessageEvent;

import java.io.IOException;

/**
* (Bukkit) 消息 - 被动收到消息 - 好友消息
*/
Expand All @@ -18,69 +11,17 @@ public class MiraiFriendMessageEvent extends AbstractMessageEvent {
public MiraiFriendMessageEvent(FriendMessageEvent event) {
super(event);
this.event = event;

BotID = event.getBot().getId();

SenderID = event.getSender().getId();
NickName = event.getSender().getNick();
}

public MiraiFriendMessageEvent(long BotAccount, FetchMessage.Data data) {
super(BotAccount, data);

BotID = BotAccount;

SenderID = data.sender.id;
NickName = data.sender.nickname;
}

private FriendMessageEvent event;

private final long BotID;
private final long SenderID;
private final String NickName;
private final FriendMessageEvent event;

/**
* 返回发送这条信息的发送者昵称
* @return 发送者昵称
*/
@Override
public String getSenderName(){
return NickName;
}

/**
* 向发送来源发送消息(HTTPAPI下支持 Mirai Code)
* @param message 消息内容
*/
@Override
public void sendMessage(String message) {
if(getType() == EventType.CORE){
super.sendMessage(message);
} else if(getType() == EventType.HTTPAPI){
try {
MiraiHttpAPI.INSTANCE.sendFriendMessage(MiraiHttpAPI.Bots.get(BotID), SenderID, message);
} catch (IOException | AbnormalStatusException e) {
Utils.getLogger().warning("发送消息时出现异常,原因: " + e);
}
}
}

/**
* 向发送来源发送消息(支持 Mirai Code)
* @param message 消息内容
*/
@Override
public void sendMessageMirai(String message) {
if(getType() == EventType.CORE){
super.sendMessageMirai(message);
} else if(getType() == EventType.HTTPAPI){
try {
MiraiHttpAPI.INSTANCE.sendFriendMessage(MiraiHttpAPI.Bots.get(BotID), SenderID, message);
} catch (IOException | AbnormalStatusException e) {
Utils.getLogger().warning("发送消息时出现异常,原因: " + e);
}
}
return event.getSender().getNick();
}

/**
Expand Down
Loading

0 comments on commit 999f984

Please sign in to comment.