群聊和频道交互成功
This commit is contained in:
parent
3fdf1be604
commit
e74af68a8d
1622
package-lock.json
generated
Normal file
1622
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,9 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "deno run -A src/index.ts",
|
||||
"test": "/root/.deno/bin/deno run -A ./src/index.ts",
|
||||
"dev:linux": "/root/.deno/bin/deno run -A ./src/index.ts",
|
||||
"nodemon": "deno run -A --watch src/index.ts",
|
||||
"nodemon:linux": "/root/.deno/bin/deno run -A --watch ./src/index.ts",
|
||||
"build:linux": "deno compile --no-check -o dist/test --target x86_64-unknown-linux-gnu -A src/index.ts",
|
||||
"build:win": "deno compile --no-check -o dist/test --target x86_64-pc-windows-msvc -A src/index.ts",
|
||||
"docker": "docker build -t qqbot-image .",
|
||||
|
||||
77
src/index.ts
77
src/index.ts
@ -15,34 +15,65 @@ const app = new QQHook<T>({
|
||||
});
|
||||
|
||||
app.on('GROUP_AT_MESSAGE_CREATE', data => { // 用户在群聊@机器人发送消息
|
||||
console.log(chalk.red('[还没打算做群聊]'));
|
||||
// console.log(chalk.red('[还没打算做群聊]'));
|
||||
// console.log(data);
|
||||
console.log(chalk.yellow('群聊:'), data.content);
|
||||
app.axios.post(`/v2/groups/${data.group_openid}/messages`, {
|
||||
content: `😅`,
|
||||
msg_id: data.id
|
||||
})
|
||||
})
|
||||
|
||||
app.on('MESSAGE_CREATE', data => { // 用户在文字子频道内发送的所有聊天消息(私域)
|
||||
console.log(chalk.yellow('文字子频道:'), data.content);
|
||||
app.axios.post(`/channels/${data.channel_id}/messages`, {
|
||||
// content: `<@${data.author.id}> 😅`,
|
||||
msg_id: data.id,
|
||||
embed: {
|
||||
"title": "标题",
|
||||
"prompt": "消息通知",
|
||||
"thumbnail": {
|
||||
"url": "xxxxxx"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "当前等级:黄金"
|
||||
},
|
||||
{
|
||||
"name": "之前等级:白银"
|
||||
},
|
||||
{
|
||||
"name": "😁继续努力"
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
const reply = (res: string) => app.axios.post(
|
||||
`/channels/${data.channel_id}/messages`, {
|
||||
content: res,
|
||||
msg_id: data.id
|
||||
});
|
||||
|
||||
if (typeof (data.content) !== 'string') {
|
||||
console.log(typeof (data.content));
|
||||
return;
|
||||
};
|
||||
|
||||
let content = data.content as string;
|
||||
|
||||
if (content.startsWith('.') || content.startsWith('/')) {
|
||||
function splitString(input: string): string {
|
||||
const noSpaceString = input.replace(/\s+/g, '');
|
||||
let arr: string[];
|
||||
if (!noSpaceString.includes('+') && !noSpaceString.includes('-')) arr = [noSpaceString];
|
||||
else arr = noSpaceString.split(/(\+|\-)/).filter(Boolean);
|
||||
let sum = 0;
|
||||
let flag = true;
|
||||
let ans_string = '';
|
||||
for (const item of arr) {
|
||||
const match = item.match(/(\d{1,3}|r)?d(\d{1,3})?/);
|
||||
if (!match) {
|
||||
if (item === '+') flag = true;
|
||||
if (item === '-') flag = false;
|
||||
ans_string += item;
|
||||
continue;
|
||||
}
|
||||
const x = match[1] === 'r' ? 1 : parseInt(match[1]);
|
||||
const y = match[2] ? parseInt(match[2]) : 100;
|
||||
const ans = Array(x).fill(0).reduce(acc => acc + Math.floor(Math.random() * y) + 1, 0);
|
||||
sum += flag ? ans : -ans;
|
||||
ans_string += ans;
|
||||
}
|
||||
return ans_string;
|
||||
}
|
||||
|
||||
content = content.slice(1);
|
||||
try {
|
||||
const ans = splitString(content);
|
||||
reply(`<@${data.author.id}> roll出的结果为 ${ans} = ${eval(ans)}`);
|
||||
} catch (error) {
|
||||
reply(`<@${data.author.id}> 未知指令`);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user