-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
fabric/src/main/java/cn/evole/mods/mcbot/command/RecallCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.evole.mods.mcbot.command; | ||
|
||
import cn.evole.mods.mcbot.McBot; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.commands.CommandSourceStack; | ||
|
||
public class RecallCommand { | ||
|
||
public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException { | ||
int id = context.getArgument("MessageId", Integer.class); | ||
McBot.bot.deleteMsg(id); | ||
return 1; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
fabric/src/main/java/cn/evole/mods/mcbot/data/ChatRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.evole.mods.mcbot.data; | ||
|
||
import com.xykj.easycsv.entity.CsvProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* @Project: McBot-fabric | ||
* @Author: cnlimiter | ||
* @CreateTime: 2024/2/21 13:59 | ||
* @Description: | ||
*/ | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class ChatRecord { | ||
@CsvProperty("消息ID") | ||
private String messageId; | ||
@CsvProperty("添加日期") | ||
private long createTime; | ||
@CsvProperty("qq") | ||
private String qqId; | ||
@CsvProperty("群号") | ||
private String groupId; | ||
@CsvProperty("消息") | ||
private String message; | ||
} |
60 changes: 60 additions & 0 deletions
60
fabric/src/main/java/cn/evole/mods/mcbot/data/ChatRecordApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cn.evole.mods.mcbot.data; | ||
|
||
import com.xykj.easycsv.EasyCsv; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.*; | ||
|
||
/** | ||
* @Project: McBot-fabric | ||
* @Author: cnlimiter | ||
* @CreateTime: 2024/2/20 15:35 | ||
* @Description: | ||
*/ | ||
|
||
public class ChatRecordApi { | ||
private static final String FILE_NAME = "chat.csv"; | ||
private static final EasyCsv easyCsv = new EasyCsv(); | ||
public static Map<String, ChatRecord> users; | ||
|
||
public static void load(Path folder){ | ||
Path bindFile = folder.resolve(FILE_NAME); | ||
List<ChatRecord> chatRecords = new ArrayList<>(); | ||
Map<String, ChatRecord> chatRecordMap = new HashMap<>(); | ||
try { | ||
if (!bindFile.toFile().isFile()) Files.createFile(bindFile); | ||
chatRecords = easyCsv.readAll(bindFile.toFile().getAbsolutePath() | ||
, ChatRecord.class); | ||
for (ChatRecord chatRecord : chatRecords){ | ||
chatRecordMap.put(chatRecord.getMessageId(), chatRecord); | ||
} | ||
} catch (IOException ignored) { | ||
} | ||
|
||
users = chatRecordMap; | ||
} | ||
|
||
public static void save(Path folder){ | ||
Path bindFile = folder.resolve(FILE_NAME); | ||
try { | ||
Files.deleteIfExists(bindFile); | ||
easyCsv.write(bindFile.toFile().getAbsolutePath() | ||
, Arrays.asList(users.values().toArray())); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
|
||
public static boolean has(String message_id){ | ||
return users.containsKey(message_id); | ||
} | ||
|
||
public static void add(String message_id, String group_name, String qq_id, String message){ | ||
if (!has(qq_id)) users.put(qq_id, new ChatRecord(message_id, System.currentTimeMillis(), qq_id, group_name, message)); | ||
} | ||
|
||
public static void del(String message_id){ | ||
if (has(message_id)) users.remove(message_id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters