Skip to content

Commit

Permalink
v2.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ejnshtein committed Feb 6, 2019
1 parent a501291 commit 9aeec1f
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 159 deletions.
11 changes: 10 additions & 1 deletion actions/chapter-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ composer.action([
const copy = ctx.match[3] === 'true'
const offset = ctx.match[4]
const history = ctx.match[5]
if (getFiles.getCacheBlockingValue()) {
return ctx.answerCbQuery(
`Sorry, caching isn't available right now.\nThis can be because of bot update or malfunction.`,
true,
{ cache_time: 10 }
)
}
let chapter = await getChapter(chapterId)
const manga = await getManga(chapter.manga_id, false)
chapter = await getFiles(chapter, manga, ctx, offset, history)
if (!chapter) { return ctx.answerCbQuery('') }
if (!chapter) {
return ctx.answerCbQuery('')
}
const keyboard = [
[
{
Expand Down
10 changes: 10 additions & 0 deletions actions/choosen-inline-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { Composer } = require('telegraf').default
const composer = new Composer()

// composer.on('chosen_inline_result', async ctx => {
// console.log(ctx.update.chosen_inline_result)
// })

module.exports = app => {
app.use(composer.middleware())
}
1 change: 1 addition & 0 deletions actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = app => {
require('./chapter-list')(app)
require('./delete')(app)
require('./mark-as-read')(app)
require('./choosen-inline-query')(app)
}
21 changes: 17 additions & 4 deletions actions/inline-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,18 @@ composer.on('inline_query', async ctx => {
},
reply_markup: {
inline_keyboard: [
[{
text: 'Read manga',
url: `https://t.me/${ctx.me}?start=${buffer.encode(`manga:${title.id}`)}`
}]
[
{
text: 'Read manga',
url: `https://t.me/${ctx.me}?start=${buffer.encode(`manga:${title.id}`)}`
}
]
// ,[
// {
// text: 'Want to read',
// callback_data: `test:1`
// }
// ]
]
},
thumb_url: title.image_url
Expand All @@ -143,6 +151,11 @@ composer.on('inline_query', async ctx => {
}
})

// composer.action(/test:(\S+)/i, async ctx => {
// console.log(ctx.update)
// ctx.answerCbQuery('Hello there!')
// })

module.exports = app => {
app.use(composer.middleware())
}
Expand Down
3 changes: 3 additions & 0 deletions actions/user-reading-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Composer = require('telegraf/composer')
const composer = new Composer()
const getFiles = require('../lib/get-files')
76 changes: 76 additions & 0 deletions commands/get-cache-pool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const Composer = require('telegraf/composer')
const composer = new Composer()
const getFiles = require('../lib/get-files')

composer.command('pool', async ctx => {
if (ctx.from.id === Number.parseInt(process.env.ADMIN_ID)) {
ctx.reply(`Here's ${Object.keys(getFiles.cachePool()).length} chapters waiting to be cached.`, {
reply_markup: {
inline_keyboard: cacheKeyboard(
getFiles.getCacheBlockingValue(),
getFiles.getUpdateCachingBlockingValue()
)
}
})
}
})
composer.action(/^cachepool=(\S+)$/i, async ctx => {
if (ctx.from.id === Number.parseInt(process.env.ADMIN_ID)) {
switch (ctx.match[1]) {
case 'on':
getFiles.setCachingBlocking(true)
break
case 'off':
getFiles.setCachingBlocking(false)
break
}
ctx.editMessageReplyMarkup({
inline_keyboard: cacheKeyboard(
getFiles.getCacheBlockingValue(),
getFiles.getUpdateCachingBlockingValue()
)
})
} else {
return ctx.editMessageReplyMarkup({ inline_keyboard: [] })
}
})

composer.action(/^updatecache=(\S+)$/i, async ctx => {
if (ctx.from.id === Number.parseInt(process.env.ADMIN_ID)) {
switch (ctx.match[1]) {
case 'on':
getFiles.setUpdateCachingBlocking(true)
break
case 'off':
getFiles.setUpdateCachingBlocking(false)
break
}
ctx.editMessageReplyMarkup({
inline_keyboard: cacheKeyboard(
getFiles.getCacheBlockingValue(),
getFiles.getUpdateCachingBlockingValue()
)
})
} else {
return ctx.editMessageReplyMarkup({ inline_keyboard: [] })
}
})

module.exports = app => {
app.use(composer.middleware())
}

function cacheKeyboard (cacheBlock, updateBlock) {
return [
[
{
text: `${cacheBlock ? 'Enable' : 'Disable'} caching`,
callback_data: `cachepool=${cacheBlock ? 'off' : 'on'}`
},
{
text: `${updateBlock ? 'Enable' : 'Disable'} updating`,
callback_data: `updatecache=${updateBlock ? 'off' : 'on'}`
}
]
]
}
1 change: 1 addition & 0 deletions commands/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = app => {
require('./start')(app)
require('./search')(app)
require('./get-cache-pool')(app)
}
2 changes: 1 addition & 1 deletion core/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ module.exports = collectionName => {
} else {
throw new Error('Collection not found')
}
}
}
60 changes: 0 additions & 60 deletions lib/cache-file.js

This file was deleted.

Loading

0 comments on commit 9aeec1f

Please sign in to comment.