Skip to content

Commit

Permalink
feat(rss): add rss --list
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 16, 2020
1 parent 759c3d7 commit a7373b4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/plugin-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function apply(ctx: Context, config: Config = {}) {

ctx.on('connect', async () => {
feeder.on('error', (err: Error) => {
logger.warn(err)
logger.warn(err.message)
})

const groups = await ctx.database.getAllGroups(['id', 'rss'])
Expand Down Expand Up @@ -97,24 +97,30 @@ export function apply(ctx: Context, config: Config = {}) {

ctx.group().command('rss <url...>', '订阅 RSS 链接')
.groupFields(['rss', 'id'])
.option('remove', '-r, --remove 取消订阅')
.option('list', '-l 查看订阅列表')
.option('remove', '-r 取消订阅')
.action(async ({ session, options }, url) => {
const { rss, id } = session.$group
if (options.list) {
if (!rss.length) return '未订阅任何链接。'
return rss.join('\n')
}

url = url.toLowerCase()
const { $group } = session
const index = $group.rss.indexOf(url)
const index = rss.indexOf(url)

if (options.remove) {
if (index < 0) return '未订阅此链接。'
$group.rss.splice(index, 1)
unsubscribe(url, $group.id)
rss.splice(index, 1)
unsubscribe(url, id)
return '取消订阅成功!'
}

if (index >= 0) return '已订阅此链接。'
return validate(url, session).then(() => {
subscribe(url, $group.id)
if (!$group.rss.includes(url)) {
$group.rss.push(url)
subscribe(url, id)
if (!rss.includes(url)) {
rss.push(url)
return '添加订阅成功!'
}
}, (error) => {
Expand Down

0 comments on commit a7373b4

Please sign in to comment.