-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
140 lines (129 loc) · 5.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require('dotenv').config();
const {Markup} = require('telegraf');
const bot = new (require("telegraf").Telegraf)(process.env.BOT_TOKEN);
const tgbot = new (require('./modules/tgbot').Tgbot);
// handle bot commands
bot.use(async (ctx, next)=>{
await tgbot.logUser(ctx.from || ctx.callbackQuery.from);
if(ctx?.message?.entities && ctx.message.entities[0].type == 'bot_command'){
return await require('./modules/commands').handleCommands(ctx.update);
}
return await next();
});
// handle stickers
bot.on('sticker', async ctx => await ctx.reply('Want to add your sticker? Talk to @threej_bot'));
// handle inline queries
bot.on('inline_query', ctx => require('./modules/inlineQueryHandler').handleInlineQueries(ctx, tgbot));
//handle callback query
bot.on('callback_query', async ctx => {
if(ctx.callbackQuery.data === 'secondaryMenu'){
await ctx.answerCbQuery('Advance search');
return await ctx.editMessageReplyMarkup(Markup.inlineKeyboard([
[
Markup.button.switchToCurrentChat('⏸ Animated sticker','A '),
Markup.button.switchToCurrentChat('🎦 Video sticker','V ')
],
[
Markup.button.switchToCurrentChat('▶️ Static sticker','S '),
Markup.button.switchToCurrentChat('🌟Premium sticker','P ')
],
[
Markup.button.callback('◀️ Back','mainMenu'),
]
]).reply_markup)
}else if(ctx.callbackQuery.data === 'mainMenu'){
await ctx.answerCbQuery('Main menu');
return await ctx.editMessageText(
`Hello ${ctx.callbackQuery.from.first_name}, nice to meet you.\n\nYou can use me anywhere in telegram to search stickers. Just type my username or click on the below button.\n\nJoin @stickers3j`,{
reply_markup: Markup.inlineKeyboard([
[
Markup.button.switchToChat('🔎 Search stickers',''),
Markup.button.callback('🕵️♂️ Advance search','secondaryMenu')
],
[
Markup.button.url('➕ Add sticker','https://t.me/threej_bot'),
Markup.button.url('😺 Contribute','https://t.me/threej_bot')
],
[
Markup.button.callback('⚙️ Preferences', 'Preferences')
]
]).reply_markup
})
}else if(ctx.callbackQuery.data === 'Preferences'){
return await ctx.editMessageText('Modify your Preferences\n\nHide Explicit contents: ' + (tgbot.user.ISNSFW ? '❌':'✅'),{
reply_markup: Markup.inlineKeyboard([
[
Markup.button.callback((tgbot.user.ISNSFW ? '🔞 Hide' : '🔞 Show') + ' NSFW stickers', tgbot.user.ISNSFW ? 'hideNSFW' : 'showNSFW')
],
[
Markup.button.callback('◀️ Back','mainMenu')
]
]).reply_markup
})
}else if(ctx.callbackQuery.data === 'hideNSFW'){
const result = await tgbot.updatePreference({ISNSFW : 0});
if(result.affectedRows == 1){
return await ctx.editMessageText('Modify your Preferences\n\nHide Explicit contents: ✅',{
reply_markup: Markup.inlineKeyboard([
[
Markup.button.callback('🔞 Show NSFW stickers', 'showNSFW')
],
[
Markup.button.callback('◀️ Back','mainMenu')
]
]).reply_markup
})
}
}else if(ctx.callbackQuery.data === 'showNSFW'){
const result = await tgbot.updatePreference({ISNSFW : 1});
if(result.affectedRows == 1){
return await ctx.editMessageText('Modify your Preferences\n\nHide Explicit contents: ❌',{
reply_markup: Markup.inlineKeyboard([
[
Markup.button.callback('🔞 Hide NSFW stickers', 'hideNSFW')
],
[
Markup.button.callback('◀️ Back','mainMenu')
]
]).reply_markup
})
}
}
})
// Default message
bot.use(async (ctx) => {
ctx.reply('Use me in inline mode, click on the button below.',{
reply_markup : Markup.inlineKeyboard([
[Markup.button.switchToChat('Search stickers','')]
]).reply_markup
})
});
// handle errors
bot.catch((err)=>{tgbot.logError(err)});
// Launch bot
bot.launch({
polling:{
allowed_updates: [
'inline_query',
'message'
]
}
});
// Production
/*
bot.launch({
webhook:{
domain: process.env.webhookDomain,
hookPath: process.env.WEBHOOKPATH,
secretToken: process.env.SECRETTOKEN,
port: 443,
allowed_updates: [
'inline_query',
'message'
]
}
})
*/
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));