Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 将群管功能设为内置工具 #92

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[feat] 将群管功能设为内置工具
  • Loading branch information
HydroGest committed Jan 26, 2025
commit abbaca9a89027596a54b3c63359afd01bad6797f
7 changes: 4 additions & 3 deletions packages/core/src/extensions/ext_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import { Description, Extension, Name, Param } from "./base";
@Name("execute")
@Description(`
你可以运行一些只有在IM平台才能运行的指令,下面是你可以运行的指令列表。
- ban <用户ID> <时长>: 将用户禁言。单位为秒。时长设为 0 表示解禁。
- delmsg <消息ID>: 撤回用户的消息。当你认为别人刷屏或发表不当内容时,运行这条指令
- fufu表情包
- 男娘武器库表情包
- 永雏小菲表情包
请将指令字符串添加到 cmd 参数上来执行指令。
将channel设置为你要执行指令的频道,不填默认为当前频道。
比如 \`execute("ban 1234567 600")\` 是将用户 1234567 禁言 10 分钟,
比如 \`execute("fufu表情包)\` 是发送 fufu 的表情包。
这个函数**不能**在 "status" 为 function 的时候使用。DO NOT USE THIS FUNCTION WHEN "status" IS "function".
你只能在 "status" 为 "success" 或 "skip" 的时候使用这个函数。YOU CAN ONLY USE THIS FUNCTION WHEN "status" IS "success" OR "skip".
这个函数没有返回值。
Expand Down
45 changes: 22 additions & 23 deletions packages/core/src/extensions/ext_interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,36 @@ import { Description, Extension, Name, Param } from "./base";
import { isEmpty } from "../utils/string";

@Name("reaction-create")
@Description(`
在当前频道对一个或多个消息进行表态。表态编号是数字,这里是一个简略的参考:惊讶(0),不适(1),无语(27),震惊(110),滑稽(178), 点赞(76)
`)
@Description(`在当前频道对一个或多个消息进行表态。表态编号是数字,这里是一个简略的参考:惊讶(0),不适(1),无语(27),震惊(110),滑稽(178), 点赞(76)`)
@Param("message", "消息 ID")
@Param("emoji_id", "表态编号")
export class Reaction extends Extension {
async apply(message: number, emoji_id: number) {
try {
// @ts-ignore
await this.session.onebot._request("set_msg_emoji_like", { message_id: message, emoji_id: emoji_id});
this.ctx.logger.info(`Bot[${this.session.selfId}]对消息 ${message} 进行了表态: ${emoji_id}`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]执行表态失败: ${message}, ${emoji_id} - `, e.message);
async apply(args: { message: number, emoji_id: number }) {
const { message, emoji_id } = args;
try {
// @ts-ignore
await this.session.onebot._request("set_msg_emoji_like", { message_id: message, emoji_id: emoji_id });
this.ctx.logger.info(`Bot[${this.session.selfId}]对消息 ${message} 进行了表态: ${emoji_id}`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]执行表态失败: ${message}, ${emoji_id} - `, e.message);
}
}
}
}

@Name("essence-create")
@Description(`
在当前频道将一个消息设置为精华消息。常在你认为某个消息十分重要或过于典型时使用。
`)
@Description(`在当前频道将一个消息设置为精华消息。常在你认为某个消息十分重要或过于典型时使用。`)
@Param("message", "消息 ID")
export class Essence extends Extension {
async apply(message: number) {
try {
// @ts-ignore
await this.session.onebot._request("set_essence_msg", { message_id: message})
this.ctx.logger.info(`Bot[${this.session.selfId}]将消息 ${message} 设置为精华`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]设置精华消息失败: ${message} - `, e.message);
async apply(args: { message: number }) {
const { message } = args;
try {
// @ts-ignore
await this.session.onebot._request("set_essence_msg", { message_id: message })
this.ctx.logger.info(`Bot[${this.session.selfId}]将消息 ${message} 设置为精华`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]设置精华消息失败: ${message} - `, e.message);
}
}
}
}

@Name("send-poke")
Expand All @@ -51,7 +49,8 @@ export class Essence extends Extension {
@Param("channel", "要在哪个频道运行,不填默认为当前频道")
@Param("user_id", "用户名称")
export class Poke extends Extension {
async apply(user_id: string, channel?: string) {
async apply(args: { user_id: string, channel?: string }) {
const { user_id, channel } = args;
try {
let channelId: string;
if (isEmpty(channel)) {
Expand Down
51 changes: 51 additions & 0 deletions packages/core/src/extensions/ext_qmanager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ==Extension==
// @name QQ Group Manager
// @version 1.0.0
// @description 让大模型可以管理 QQ 群
// @author HydroGest
// ==/Extension==

import { SchemaNode } from "../adapters/creators/schema";
import { isEmpty } from "../utils/string";
import { Description, Extension, Name, Param } from "./base";

@Name("delmsg")
@Description(`撤回一条消息。撤回用户/你自己的消息。当你认为别人刷屏或发表不当内容时,运行这条指令。`)
@Param("message", "要撤回的消息编号")
@Param("channel", SchemaNode.String("要在哪个频道运行,不填默认为当前频道", ""))
export class DeleteMsg extends Extension {
async apply(args: { message: string; channel?: string }) {
const { message, channel } = args;
try {
if (isEmpty(channel)) {
await this.session.bot.deleteMessage(this.session.guildId, message);
} else {
await this.session.bot.deleteMessage(channel, message);
}
this.ctx.logger.info(`Bot[${this.session.selfId}]撤回了消息: ${message}`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]撤回消息失败: ${message} - `, e.message);
}
}
}

@Name("ban")
@Description(`禁言用户`)
@Param("user_id", "要禁言的用户 ID")
@Param("duration", "禁言时长,单位为分钟。你不应该禁言他人超过 10 分钟。时长设为 0 表示解除禁言。")
@Param("channel", SchemaNode.String("要在哪个频道运行,不填默认为当前频道", ""))
export class BanUser extends Extension {
async apply(args: { user_id: string; duration: number; channel?: string }) {
const { user_id, duration, channel } = args;
try {
if (isEmpty(channel)) {
await this.session.bot.muteGuildMember(this.session.guildId, user_id, (duration ? Number(duration) * 60000 : 10 * 60000));
} else {
await this.session.bot.muteGuildMember(channel, user_id, (duration ? Number(duration) * 60000 : 10 * 60000));
}
this.ctx.logger.info(`Bot[${this.session.selfId}]在频道 ${channel} 禁言用户: ${user_id}`);
} catch (e) {
this.ctx.logger.error(`Bot[${this.session.selfId}]在频道 ${channel} 禁言用户: ${user_id} 失败 - `, e.message);
}
}
}
4 changes: 1 addition & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const inject = {
required: ["database"],
optional: [
"memory",
"qmanager",
"interactions",
"censor",
"censor"
],
}

Expand Down
Loading