@satorijs/core
Advanced tools
Comparing version 4.1.1 to 4.1.2
@@ -1,2 +0,2 @@ | ||
import { Context, Logger, z, Service } from 'cordis'; | ||
import { Context, Service, Logger, z } from 'cordis'; | ||
import { Message, SendOptions, Event, GuildMember, User, Login, Methods, Response, Status, Upload, WebSocket } from '@satorijs/protocol'; | ||
@@ -44,2 +44,6 @@ import h from '@satorijs/element'; | ||
static counter: number; | ||
[Service.tracker]: { | ||
associate: string; | ||
property: string; | ||
}; | ||
id: number; | ||
@@ -80,3 +84,6 @@ bot: Bot<C>; | ||
static MessageEncoder?: new (bot: Bot, channelId: string, guildId?: string, options?: SendOptions) => MessageEncoder; | ||
self: this; | ||
[Service.tracker]: { | ||
associate: string; | ||
property: string; | ||
}; | ||
user: User; | ||
@@ -92,3 +99,2 @@ isBot: boolean; | ||
logger: Logger; | ||
[Context.current]: C; | ||
protected context: Context; | ||
@@ -95,0 +101,0 @@ protected _status: Status; |
{ | ||
"name": "@satorijs/core", | ||
"description": "Core components of Satorijs", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"type": "module", | ||
@@ -59,11 +59,11 @@ "main": "lib/index.cjs", | ||
"peerDependencies": { | ||
"cordis": "^3.16.1" | ||
"cordis": "^3.17.1" | ||
}, | ||
"dependencies": { | ||
"@cordisjs/plugin-http": "^0.5.2", | ||
"@cordisjs/plugin-http": "^0.5.3", | ||
"@satorijs/element": "^3.1.7", | ||
"@satorijs/protocol": "^1.4.0", | ||
"cordis": "^3.16.1", | ||
"@satorijs/protocol": "^1.4.1", | ||
"cordis": "^3.17.1", | ||
"cosmokit": "^1.6.2" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
import { clone, Dict, pick, remove } from 'cosmokit' | ||
import { Context, Logger } from 'cordis' | ||
import { clone, Dict, pick } from 'cosmokit' | ||
import { Context, Logger, Service } from 'cordis' | ||
import h from '@satorijs/element' | ||
@@ -25,3 +25,7 @@ import { Adapter } from './adapter' | ||
public self = this | ||
public [Service.tracker] = { | ||
associate: 'bot', | ||
property: 'ctx', | ||
} | ||
public user = {} as User | ||
@@ -37,3 +41,2 @@ public isBot = true | ||
public logger: Logger | ||
public [Context.current]: C | ||
@@ -47,9 +50,7 @@ // Same as `this.ctx`, but with a more specific type. | ||
this.context = ctx | ||
this[Context.current] = ctx | ||
const self = Context.associate(this, 'bot') | ||
ctx.bots.push(self) | ||
self.context.emit('bot-added', self) | ||
ctx.bots.push(this) | ||
this.context.emit('bot-added', this) | ||
if (platform) { | ||
self.logger = ctx.logger(platform) | ||
self.platform = platform | ||
this.logger = ctx.logger(platform) | ||
this.platform = platform | ||
} | ||
@@ -64,7 +65,7 @@ | ||
await Promise.resolve() | ||
self.dispatchLoginEvent('login-added') | ||
return self.start() | ||
this.dispatchLoginEvent('login-added') | ||
return this.start() | ||
}) | ||
ctx.on('dispose', () => self.dispose()) | ||
ctx.on('dispose', () => this.dispose()) | ||
@@ -75,4 +76,2 @@ ctx.on('interaction/button', (session) => { | ||
}) | ||
return self | ||
} | ||
@@ -93,5 +92,8 @@ | ||
dispose() { | ||
remove(this.ctx.bots, this) | ||
this.context.emit('bot-removed', this) | ||
this.dispatchLoginEvent('login-removed') | ||
const index = this.ctx.bots.findIndex(bot => bot.sid === this.sid) | ||
if (index >= 0) { | ||
this.ctx.bots.splice(index, 1) | ||
this.context.emit('bot-removed', this) | ||
this.dispatchLoginEvent('login-removed') | ||
} | ||
return this.stop() | ||
@@ -114,3 +116,3 @@ } | ||
this._status = value | ||
if (this.ctx.bots?.includes(this)) { | ||
if (this.ctx.bots?.some(bot => bot.sid === this.sid)) { | ||
this.context.emit('bot-status-updated', this) | ||
@@ -153,3 +155,3 @@ this.dispatchLoginEvent('login-updated') | ||
} catch (error) { | ||
this.context.emit('internal/error', error) | ||
this.context.emit(this.ctx, 'internal/error', error) | ||
} finally { | ||
@@ -227,3 +229,3 @@ this.offline() | ||
} | ||
const _dispose = this[Context.current].on('dispose', dispose) | ||
const _dispose = this.ctx.on('dispose', dispose) | ||
return ids.map(id => `upload://temp/${this.ctx.satori.uid}/${id}`) | ||
@@ -230,0 +232,0 @@ } |
import { Context, Logger, Service, z } from 'cordis' | ||
import { Awaitable, Dict, makeArray, remove } from 'cosmokit' | ||
import { Awaitable, defineProperty, Dict, makeArray, remove } from 'cosmokit' | ||
import { Bot } from './bot' | ||
@@ -138,2 +138,4 @@ import { Session } from './session' | ||
defineProperty(this.bots, Service.tracker, {}) | ||
const self = this | ||
@@ -184,3 +186,3 @@ ;(ctx as Context).on('http/file', async function (url, options) { | ||
upload(path: UploadRoute['path'], callback: UploadRoute['callback'], proxyUrls: UploadRoute['path'][] = []) { | ||
return this[Context.current].effect(() => { | ||
return this.ctx.effect(() => { | ||
const route: UploadRoute = { path, callback } | ||
@@ -187,0 +189,0 @@ this._uploadRoutes.push(route) |
import { Channel, Event, GuildMember, Message, User } from '@satorijs/protocol' | ||
import { defineProperty, isNullable } from 'cosmokit' | ||
import { Context } from 'cordis' | ||
import { Context, Service } from 'cordis' | ||
import { Bot } from './bot' | ||
@@ -33,2 +33,7 @@ import h from '@satorijs/element' | ||
public [Service.tracker] = { | ||
associate: 'session', | ||
property: 'ctx', | ||
} | ||
public id: number | ||
@@ -35,0 +40,0 @@ public bot: Bot<C> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
114861
2412
Updated@cordisjs/plugin-http@^0.5.3
Updated@satorijs/protocol@^1.4.1
Updatedcordis@^3.17.1