-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
44 changed files
with
681 additions
and
445 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
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
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "koishi-adapter-tomon", | ||
"description": "Tomon adapter for Koishi", | ||
"version": "0.1.0", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"author": "Shigma <1700011071@pku.edu.cn>", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint src --ext .ts", | ||
"precommit": "yarn lint", | ||
"prepack": "tsc -b" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/koishijs/koishi.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/koishijs/koishi/issues" | ||
}, | ||
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/koishi-core#readme", | ||
"keywords": [ | ||
"bot", | ||
"tomon", | ||
"chatbot", | ||
"koishi" | ||
], | ||
"peerDependencies": { | ||
"koishi-core": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"koishi-test-utils": "^5.0.1" | ||
}, | ||
"dependencies": { | ||
"koishi-utils": "^3.1.5", | ||
"tomon-sdk": "^0.2.0" | ||
} | ||
} |
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,13 @@ | ||
import { Bot, Session } from 'koishi-core' | ||
|
||
Bot.prototype.sendGroupMsg = Bot.prototype.sendPrivateMsg = async function (this: Bot, channelId, content) { | ||
if (!content) return | ||
const data = await this.tomon.api.route(`/channels/${channelId}/messages`).post({ data: { content } }) | ||
console.log(data) | ||
return 0 | ||
} | ||
|
||
Session.prototype.$send = async function $send(this: Session, message: string) { | ||
if (!message) return | ||
await this.$bot.sendPrivateMsg(this.channelId, message) | ||
} |
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,49 @@ | ||
import Tomon from 'tomon-sdk' | ||
import { Bot, Server } from 'koishi-core' | ||
|
||
export * from './api' | ||
|
||
declare module 'koishi-core/dist/server' { | ||
interface BotOptions { | ||
token?: string | ||
} | ||
|
||
interface Bot { | ||
tomon?: Tomon | ||
} | ||
} | ||
|
||
declare module 'koishi-core/dist/session' { | ||
interface Session { | ||
channelId?: number | ||
} | ||
} | ||
|
||
Server.types.tomon = class TomonServer extends Server { | ||
async __listen(bot: Bot) { | ||
const tomon = bot.tomon = new Tomon() | ||
await tomon.start(bot.token) | ||
bot.ready = true | ||
const selfId = bot.selfId = +tomon.discriminator | ||
tomon.on('MESSAGE_CREATE', async ({ d }) => { | ||
const userId = +d.author.discriminator | ||
if (userId === selfId) return | ||
const session = this.prepare({ | ||
...d, | ||
selfId, | ||
userId, | ||
message: d.content, | ||
postType: 'message', | ||
messageType: d['guild_id'] ? 'group' : 'private', | ||
groupId: d['guild_id'], | ||
}) | ||
this.dispatch(session) | ||
}) | ||
} | ||
|
||
async _listen() { | ||
await Promise.all(this.bots.map(bot => this.__listen(bot))) | ||
} | ||
|
||
_close() {} | ||
} |
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,10 @@ | ||
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
}, | ||
"include": [ | ||
"src", | ||
], | ||
} |
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
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
Oops, something went wrong.