Skip to content

Commit

Permalink
feat(feedback): add loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 6, 2024
1 parent 854684f commit 62eeaa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/feedback/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-plugin-feedback",
"version": "2.1.0",
"version": "2.1.2",
"description": "Feedback plugin for Koishi",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
10 changes: 9 additions & 1 deletion packages/feedback/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const name = 'feedback'
export function apply(ctx: Context, config: Config) {
ctx.i18n.define('zh-CN', require('./locales/zh-CN'))

const logger = ctx.logger('feedback')

type FeedbackData = [sid: string, channelId: string, guildId: string]
const feedbacks: Dict<FeedbackData> = {}

Expand All @@ -47,9 +49,11 @@ export function apply(ctx: Context, config: Config) {
if (options.receive) {
if (index >= 0) return session.text('.not-modified')
config.receivers.push(pick(session, ['platform', 'selfId', 'channelId', 'guildId']))
logger.info(`add receiver ${session.platform}:${session.selfId}:${session.channelId}:${session.guildId}`)
} else {
if (index < 0) return session.text('.not-modified')
config.receivers.splice(index, 1)
logger.info(`remove receiver ${session.platform}:${session.selfId}:${session.channelId}:${session.guildId}`)
}
ctx.scope.update(config, false)
return session.text('.updated')
Expand All @@ -65,13 +69,17 @@ export function apply(ctx: Context, config: Config) {
if (index && delay) await sleep(delay)
const { platform, selfId, channelId, guildId } = config.receivers[index]
const bot = ctx.bots.find(bot => bot.platform === platform && bot.selfId === selfId)
if (!bot) {
logger.warn(`cannot find bot (${platform}:${selfId})`)
continue
}
await bot.sendMessage(channelId, message, guildId).then((ids) => {
for (const id of ids) {
feedbacks[id] = data
ctx.setTimeout(() => delete feedbacks[id], config.replyTimeout)
}
}, (error) => {
ctx.logger('bot').warn(error)
logger.warn(error)
})
}
return session.text('.success')
Expand Down

0 comments on commit 62eeaa7

Please sign in to comment.