Skip to content

Commit

Permalink
feat: requester run-code modules
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Feb 12, 2024
1 parent f100467 commit f75a341
Show file tree
Hide file tree
Showing 39 changed files with 817 additions and 104 deletions.
Binary file modified kotori.db
Binary file not shown.
4 changes: 1 addition & 3 deletions modules/access/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export function main(ctx: Context) {
.catch(() => {});
});

ctx.on('parse', (data) => {
// ctx.db.select('userId').from()
});
ctx.on('parse', (data) => {});
}

// const message = controlParams(`${data.group_id}\\accessList.json`
28 changes: 28 additions & 0 deletions modules/drift-bottle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# drift-bottle

throw and pick bottles

**Version:** 1.0.0
**Author:** himeno
**License:** GPL-3.0
**Front Plugin:** grouper

## List of command

- /print <...content> - send a message on privates#^^
- /echo <...message> - send a message on group\*^^

## Config

```ts
export default {
maxNum: 3,
};
```

## Lang Support

- ja_JP
- en_US
- zh_TW
- zh_CN
9 changes: 9 additions & 0 deletions modules/drift-bottle/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"drift_bottle.descr.pick": "Pick up a drift bottle",
"drift_bottle.msg.pick.none": "No drift bottles available at the moment",
"drift_bottle.msg.pick.info": "Message in bottle: {0}\nTime: {1}\nSource group: {2}",
"drift_bottle.descr.throw": "Throw a drift bottle~",
"drift_bottle.msg.throw.info": "{0} Your bottle has been thrown into the sea~",
"drift_bottle.msg.throw.fail": "{0} You have already thrown {1} bottles today, come back tomorrow~",
"drift_bottle.msg.throw.empty": "{0} Message cannot be empty"
}
9 changes: 9 additions & 0 deletions modules/drift-bottle/locales/ja_JP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"drift_bottle.descr.pick": "漂流瓶を拾う",
"drift_bottle.msg.pick.none": "現在利用可能な漂流瓶はありません",
"drift_bottle.msg.pick.info": "瓶の中身: {0}\n時間: {1}\n出所グループ番号: {2}",
"drift_bottle.descr.throw": "漂流瓶を投げる~",
"drift_bottle.msg.throw.info": "{0} あなたの瓶が海に投げられました~",
"drift_bottle.msg.throw.fail": "{0} 今日の投げる回数は{1}回超えています。明日また来てね~",
"drift_bottle.msg.throw.empty": "{0} 内容を空にすることはできません"
}
9 changes: 9 additions & 0 deletions modules/drift-bottle/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"drift_bottle.descr.pick": "捡取一个漂流瓶",
"drift_bottle.msg.pick.none": "暂时还没有一个漂流瓶",
"drift_bottle.msg.pick.info": "瓶子内容:{0}\n时间:{1}\n来源群号:{2}",
"drift_bottle.descr.throw": "投掷一个漂流瓶~",
"drift_bottle.msg.throw.info": "{0}你的瓶子已投掷大海~",
"drift_bottle.msg.throw.fail": "{0}今天的投掷次数已超过 {1} 次,明天再来吧~",
"drift_bottle.msg.throw.empty": "{0}内容不能为空"
}
9 changes: 9 additions & 0 deletions modules/drift-bottle/locales/zh_TW.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"drift_bottle.descr.pick": "撿取壹個漂流瓶",
"drift_bottle.msg.pick.none": "暫時還沒有壹個漂流瓶",
"drift_bottle.msg.pick.info": "瓶子內容:{0}\n時間:{1}\n來源群號:{2}",
"drift_bottle.descr.throw": "投擲壹個漂流瓶~",
"drift_bottle.msg.throw.info": "{0}妳的瓶子已投擲大海~",
"drift_bottle.msg.throw.fail": "{0}今天的投擲次數已超過 {1} 次,明天再來吧~",
"drift_bottle.msg.throw.empty": "{0}內容不能爲空"
}
35 changes: 35 additions & 0 deletions modules/drift-bottle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "kotori-plugin-drift-bottle",
"version": "1.0.0",
"description": "throw and pick bottles",
"main": "lib/index.js",
"scripts": {
"build": "tsc --build"
},
"keywords": [
"kotori",
"chatbot",
"kotori-plugin"
],
"license": "GPL-3.0",
"files": [
"lib",
"locales",
"LICENSE",
"README.md"
],
"author": "Himeno <[email protected]>",
"peerDependencies": {
"kotori-bot": "workspace:^"
},
"kotori": {
"meta": {
"language": [
"en_US",
"ja_JP",
"zh_TW",
"zh_CN"
]
}
}
}
56 changes: 56 additions & 0 deletions modules/drift-bottle/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Context, MessageScope, Tsu, getRandomInt } from 'kotori-bot';

export const lang = [__dirname, '../locales'];

export const inject = ['file'];

export const config = Tsu.Object({
max: Tsu.Number().default(4)
});

type Bottle = [string, number, number | string, (number | string)?];

const getZero = () => {
const today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
return today.getTime();
};

export function main(ctx: Context, conf: Tsu.infer<typeof config>) {
const getBottle = (platform: string) => ctx.file.load(`${platform}.json`, 'json', []) as Bottle[];
const setBottle = (platform: string, data: Bottle[]) => ctx.file.save(`${platform}.json`, data, 'json');

ctx
.command('throw <content> - drift_bottle.descr.throw')
.action((data, session) => {
const at = session.el.at(session.userId);
if (!data.args[1]) return ['drift_bottle.msg.throw.empty', [at]];
const bottles = getBottle(session.api.adapter.platform);
const zero = getZero();
let count = 0;
bottles.forEach((Element) => {
if (Element[3] !== session.userId) return;
if (Element[1] < zero) return;
count += 1;
});
if (count > conf.max) return ['drift_bottle.msg.throw.fail', [at, conf.max]];
bottles.push([data.args[1] as string, new Date().getTime(), session.groupId!, session.userId!]);
setBottle(session.api.adapter.platform, bottles);
return ['drift_bottle.msg.throw.info', [at]];
})
.help('')
.scope(MessageScope.GROUP);

ctx
.command('pick - drift_bottle.descr.pick')
.action((_, session) => {
const data = getBottle(session.api.adapter.platform);
if (!data || data.length < 0) return 'drift_bottle.msg.pick.none';
const bottle = data[getRandomInt(data.length - 1)];
return ['drift_bottle.msg.pick.info', [bottle[0], session.i18n.time(new Date(bottle[1])), bottle[2]]];
})
.scope(MessageScope.GROUP);
}
12 changes: 12 additions & 0 deletions modules/drift-bottle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
},
"references": [
{
"path": "../../packages/kotori"
}
]
}
24 changes: 12 additions & 12 deletions modules/i18n-command/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"corei18n.template.args_error": "参数 “%target%” 的类型错误,期望类型:%expected% 实际类型:%reality%",
"corei18n.template.args_few": "输入参数过少请增加参数,期望数量:%expected% 实际数量:%reality%",
"corei18n.template.args_many": "输入参数过多请减少参数,期望数量:%expected% 实际数量:%reality%",
"corei18n.template.option_error": "选项 “%target%” 的类型错误,期望类型:%expected% 实际类型:%reality%",
"corei18n.template.syntax": "指令语法错误,意外地在 %index% 处字符 “%char%",
"corei18n.template.unknown": "未知的指令 “%input%” ,请检查指令是否输入正确",
"corei18n.template.error": "意外的错误!\n捕获信息:%error%",
"corei18n.template.res_error": "返回数据错误!请联系管理员\n源数据:%res%",
"corei18n.template.args_error": "参数 “{0}” 的类型错误,期望类型:{1} 实际类型:{2}",
"corei18n.template.args_few": "输入参数过少请增加参数,期望数量:{0} 实际数量:{1}",
"corei18n.template.args_many": "输入参数过多请减少参数,期望数量:{0} 实际数量:{1}",
"corei18n.template.option_error": "选项 “{0}” 的类型错误,期望类型:{1} 实际类型:{2}",
"corei18n.template.syntax": "指令语法错误,意外地在 {0} 处字符 “{1}",
"corei18n.template.unknown": "未知的指令 “{0}” ,请检查指令是否输入正确",
"corei18n.template.error": "意外的错误!\n捕获信息:{0}",
"corei18n.template.res_error": "响应数据格式错误!\n错误信息:{0}",
"corei18n.template.num_error": "序号错误,请重新发送",
"corei18n.template.exists": "目标参数“%target%”已存在,请勿重复执行",
"corei18n.template.no_exists": "目标参数“%target%”不存在,请确认后,重新发送",
"corei18n.template.data_error.args": "参数 “%target%” 传入数据错误",
"corei18n.template.data_error.options": "选项 “%target%” 传入数据错误",
"corei18n.template.exists": "目标参数“{0}”已存在,请勿重复执行",
"corei18n.template.no_exists": "目标参数“{0}”不存在,请确认后,重新发送",
"corei18n.template.data_error.args": "参数 “{0}” 传入数据错误",
"corei18n.template.data_error.options": "选项 “{0}” 传入数据错误",
"corei18n.template.scope": "该指令仅群聊或私聊下可使用!",
"corei18n.template.no_access_manger": "该指令仅群管理员与群BOT管理员可使用!",
"corei18n.template.no_access_admin": "该指令仅BOT最高管理员可使用!",
Expand Down
4 changes: 2 additions & 2 deletions modules/i18n-command/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kotori-bot/kotori-plugin-i18n-command",
"version": "1.2.0",
"version": "1.2.1",
"description": "i18n for command",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -33,4 +33,4 @@
]
}
}
}
}
31 changes: 15 additions & 16 deletions modules/i18n-command/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@ export function main(ctx: Context) {
}
const { value } = data.result;
data.cancel();
ctx.logger.debug(data);
switch (value.type) {
case 'arg_error':
quick(['corei18n.template.args_error', value]);
quick(['corei18n.template.args_error', [value.index, value.expected, value.reality]]);
break;
case 'arg_few':
quick(['corei18n.template.args_few', value]);
quick(['corei18n.template.args_few', [value.expected, value.reality]]);
break;
case 'arg_many':
quick(['corei18n.template.args_many', value]);
quick(['corei18n.template.args_many', [value.expected, value.reality]]);
break;
case 'option_error':
quick(['corei18n.template.option_error', value]);
quick(['corei18n.template.option_error', [value.target, value.expected, value.reality]]);
break;
case 'syntax':
quick(['corei18n.template.syntax', value]);
quick(['corei18n.template.syntax', [value.index, value.char]]);
break;
case 'unknown':
quick(['corei18n.template.unknown', value]);
quick(['corei18n.template.unknown', [value.input]]);
break;
default:
}
Expand All @@ -52,10 +51,10 @@ export function main(ctx: Context) {
const { quick } = data.session;
switch (value.type) {
case 'res_error':
quick(['corei18n.template.res_error', { content: value.error.message }]);
quick(['corei18n.template.res_error', [value.error.message]]);
break;
case 'num_error':
quick(['corei18n.template.num_error', value]);
quick('corei18n.template.num_error');
break;
case 'no_access_manger':
quick('corei18n.template.no_access_manger');
Expand All @@ -67,31 +66,31 @@ export function main(ctx: Context) {
quick('corei18n.template.disable');
break;
case 'exists':
quick(['corei18n.template.exists', value]);
quick(['corei18n.template.exists', [value.target]]);
break;
case 'no_exists':
quick(['corei18n.template.no_exists', value]);
quick(['corei18n.template.no_exists', [value.target]]);
break;
case 'error':
ctx.logger.error(value.error);
if (value.error instanceof TsuError) {
quick(['corei18n.template.res_error', { content: value.error.message }]);
quick(['corei18n.template.res_error', [value.error.message]]);
return;
}
if (value.error instanceof Error) {
quick(['corei18n.template.error', { error: `${value.error.name} ${value.error.message}` }]);
quick(['corei18n.template.error', [`${value.error.name} ${value.error.message}`]]);
return;
}
if (typeof value.error === 'object') {
quick(['corei18n.template.error', { error: JSON.stringify(value.error) }]);
quick(['corei18n.template.error', [JSON.stringify(value.error)]]);
return;
}
quick(['corei18n.template.error', { error: value.error as string }]);
quick(['corei18n.template.error', [String(value.error)]]);
break;
case 'data_error':
quick([
`corei18n.template.data_error.${typeof value.target === 'string' ? 'options' : 'args'}`,
{ target: value.target }
[value.target]
]);
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions modules/mediawiki/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kotori-plugin-mediawiki",
"version": "1.2.0",
"version": "1.2.1",
"description": "mediawiki search tool",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -32,4 +32,4 @@
]
}
}
}
}
4 changes: 2 additions & 2 deletions modules/mediawiki/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export function main(ctx: Context) {
if (!res) return ['mediawiki.msg.wiki.fail', { input: data.args[0] }];
return [
'mediawiki.msg.wiki',
{ ...res, api: `${wiki!.api.split('api.php')[0]}index.php?curid=${res.pageid}`, name: wiki!.name }
{ ...res, url: `${wiki!.api.split('api.php')[0]}index.php?curid=${res.pageid}`, name: wiki!.name }
];
});

ctx.command('wiki query - mediawiki.descr.wikil').action((_, session) => {
ctx.command('wikio query - mediawiki.descr.wikil').action((_, session) => {
const dataList = loadWikiData();
let list = '';
let init = 1;
Expand Down
File renamed without changes.
Loading

0 comments on commit f75a341

Please sign in to comment.