-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adapter-discord, slack, telegram, sandbox
- Loading branch information
Showing
126 changed files
with
6,019 additions
and
1,718 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
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 |
---|---|---|
|
@@ -10,3 +10,5 @@ data | |
*.log | ||
tsconfig.tsbuildinfo | ||
test.http | ||
|
||
kotori.dev.* |
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,19 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"name": "nodemon", | ||
"program": "${workspaceFolder}", | ||
"request": "launch", | ||
"restart": true, | ||
"runtimeExecutable": "nodemon", | ||
"skipFiles": ["<node_internals>/**"], | ||
"type": "node" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
# @kotori-bot/kotori-plugin-adapter-cmd | ||
|
||
Base on console i/o,a method for quickly testing modules,only support `private` scope. | ||
Base on console i/o, a method for quickly testing modules, only support `MessageScope.PRIVATE`. | ||
|
||
## Config | ||
|
||
```typescript | ||
interface CmdConfig extends Adapter { | ||
nickname?: string; // name of user(console) | ||
age?: string; // age of user | ||
sex?: 'male' | 'female'; // sex of user | ||
'self-nickname'?: string; // name of bot | ||
'self-id'?: string | number; // id of bot | ||
} | ||
export const config = Tsu.Object({ | ||
nickname: Tsu.String().default('Kotarou').describe('User\'s nickname'), | ||
'self-nickname': Tsu.String().default('KotoriO').describe('Bot\'s nickname'), | ||
'self-id': Tsu.String().default('720').describe('Bot\'s id'), | ||
}) | ||
``` | ||
|
||
## Supports | ||
|
||
### Events | ||
|
||
- on_message (only `MessageScope.PRIVATE`) | ||
|
||
### Api | ||
|
||
- sendPrivateMsg | ||
|
||
### Elements | ||
|
||
- text | ||
- mention | ||
- mentionAll | ||
|
||
## Reference | ||
|
||
- [Kotori Docs](https://kotori.js.org/) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,22 @@ | |
* @Blog: https://hotaru.icu | ||
* @Date: 2023-09-29 14:31:09 | ||
* @LastEditors: Hotaru [email protected] | ||
* @LastEditTime: 2024-08-01 17:44:48 | ||
* @LastEditTime: 2024-08-04 12:08:31 | ||
*/ | ||
import { Adapter, type AdapterConfig, type Context, MessageScope, Tsu } from 'kotori-bot' | ||
import CmdApi from './api' | ||
import CmdElements from './elements' | ||
|
||
export const config = Tsu.Object({ | ||
nickname: Tsu.String().default('Kotarou'), | ||
'self-nickname': Tsu.String().default('KotoriO'), | ||
'self-id': Tsu.String().default('720') | ||
nickname: Tsu.String().default('Kotarou').describe("User's nickname"), | ||
'self-nickname': Tsu.String().default('KotoriO').describe("Bot's nickname"), | ||
'self-id': Tsu.String().default('720').describe("Bot's id") | ||
}) | ||
|
||
type CmdConfig = Tsu.infer<typeof config> & AdapterConfig | ||
|
||
export class CmdAdapter extends Adapter<CmdApi, CmdConfig, CmdElements> { | ||
private messageId = '' | ||
public messageId = 0 | ||
|
||
public readonly platform = 'cmd' | ||
|
||
|
@@ -41,7 +41,7 @@ export class CmdAdapter extends Adapter<CmdApi, CmdConfig, CmdElements> { | |
message = message.replace('\r\n', '').replace('\n', '') | ||
this.session('on_message', { | ||
type: MessageScope.PRIVATE, | ||
messageId: this.messageId, | ||
messageId: String(this.messageId), | ||
message, | ||
messageAlt: message, | ||
userId: this.config.master, | ||
|
@@ -81,10 +81,6 @@ export class CmdAdapter extends Adapter<CmdApi, CmdConfig, CmdElements> { | |
if ((params as { user_id: unknown }).user_id !== this.config.master) return | ||
process.stdout.write(`${this.config['self-nickname']} > ${(params as { message: string }).message} \r\n`) | ||
this.messageId += 1 | ||
this.ctx.emit('send', { | ||
api: this.api, | ||
messageId: this.messageId | ||
}) | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -3,18 +3,27 @@ | |
* @Blog: https://hotaru.icu | ||
* @Date: 2023-09-29 14:31:13 | ||
* @LastEditors: Hotaru [email protected] | ||
* @LastEditTime: 2024-07-30 19:06:41 | ||
* @LastEditTime: 2024-08-04 12:09:25 | ||
*/ | ||
import { Api, type Message } from 'kotori-bot' | ||
import type CmdAdapter from './adapter' | ||
|
||
export class CmdApi extends Api { | ||
public readonly adapter: CmdAdapter | ||
|
||
public constructor(adapter: CmdAdapter) { | ||
super(adapter) | ||
this.adapter = adapter | ||
} | ||
|
||
public getSupportedEvents(): ReturnType<Api['getSupportedEvents']> { | ||
return ['on_message'] | ||
} | ||
|
||
public async sendPrivateMsg(message: Message, userId: string) { | ||
this.adapter.send('send_private_msg', { user_id: userId, message }) | ||
return { messageId: '', time: 0 } | ||
this.adapter.send('send_private_msg', { user_id: userId, message: this.adapter.elements.decode(message) }) | ||
this.adapter.ctx.emit('send', { api: this, messageId: String(this.adapter.messageId) }) | ||
return { messageId: String(this.adapter.messageId), time: Date.now() } | ||
} | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { CmdAdapter } from './adapter'; | ||
import { CmdAdapter } from './adapter' | ||
|
||
export { config } from './adapter'; | ||
export default CmdAdapter; | ||
export * from './adapter' | ||
export * from './api' | ||
export * from './elements' | ||
export default CmdAdapter |
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,35 @@ | ||
# @kotori-bot/adapter-discord | ||
|
||
Supports for discord. Create own bot: [Discord Developer Portal](https://discord.com/developers/applications). | ||
|
||
## Config | ||
|
||
```typescript | ||
export const config = Tsu.Object({ | ||
token: Tsu.String().describe("Bot's token") | ||
}) | ||
``` | ||
|
||
## Supports | ||
|
||
### Events | ||
|
||
- on_message (only `MessageScope.CHANNEL`) | ||
- on_message_delete (only `MessageScope.CHANNEL`) | ||
|
||
### Api | ||
|
||
- sendChannelMsg | ||
|
||
### Elements | ||
|
||
- text | ||
|
||
## Todo | ||
|
||
Support more standard api... | ||
|
||
## Reference | ||
|
||
- [Kotori Docs](https://kotori.js.org/) | ||
- [discord.js](https://discord.js.org/) |
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,26 @@ | ||
{ | ||
"name": "@kotori-bot/adapter-discord", | ||
"version": "1.0.0", | ||
"description": "Adapter For Discord", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
"kotori-plugin", | ||
"discord" | ||
], | ||
"license": "GPL-3.0", | ||
"files": [ | ||
"lib", | ||
"locales", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"author": "Arimura Sena <[email protected]>", | ||
"peerDependencies": { | ||
"kotori-bot": "workspace:^" | ||
}, | ||
"dependencies": { | ||
"discord.js": "^14.15.3" | ||
} | ||
} |
Oops, something went wrong.