-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
108 lines (55 loc) · 2.26 KB
/
bot.js
File metadata and controls
108 lines (55 loc) · 2.26 KB
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
const { Bot, session, MemorySessionStorage } = require("grammy");
const {
conversations,
createConversation,
} = require("@grammyjs/conversations");
const {menu_items } = require('./keyboard')
const commands = require('./commands')
const { chatMembers } = require("@grammyjs/chat-members");
const {config} = require('./settings/default')
const mongoose = require('mongoose')
const bot = new Bot(config.bot.api_key);
const mongoUri = `mongodb+srv://${config.bot.db.user_name}:${config.bot.db.password}@cluster0.jhy6mkq.mongodb.net/${config.bot.db.name}?authSource=admin&replicaSet=atlas-wck6hj-shard-0&w=majority&readPreference=primary&appname=MongoDB%20Compass&retryWrites=true&ssl=true`;
mongoose.connect(mongoUri).then(() => {
}).catch((err) => console.log(err))
bot.use(session({
initial() {
return { chat_to_request_id: 0, chat_token: '', chat_from_request_id: 0 };
},
}));
const adapter = new MemorySessionStorage();
bot.use(chatMembers(adapter));
bot.use(conversations());
bot.use(createConversation(commands.signup));
bot.use(createConversation(commands.searchAge));
bot.use(createConversation(commands.searchCity));
bot.use(createConversation(commands.searchProvince));
bot.command("start", commands.start)
bot.callbackQuery("searchAge", async (ctx) => {
await ctx.conversation.enter("searchAge")
})
bot.callbackQuery("searchCity", async (ctx) => {
await ctx.conversation.enter("searchCity")
})
bot.callbackQuery("searchProvince", async (ctx) => {
await ctx.conversation.enter("searchProvince")
})
bot.callbackQuery("searchNearUser", commands.searchNearUser)
//chating users
bot.on("message:text",commands.makeChat);
//accept request to chat 1 to 1
bot.callbackQuery("accept_request", commands.accept_request_chat);
//send request chat to user
bot.callbackQuery("request_chat", commands.request_chat);
//stop chatting
bot.callbackQuery("stop_chat", commands.stop_chat);
bot.callbackQuery("signup", async (ctx) => {
await ctx.conversation.enter("signup")
})
bot.on("chat_member", commands.chat_member)
// find user info by user public id
bot.hears(/user_ *(.+)?/, commands.userInfoById)
bot.hears(menu_items.searchUsers, commands.searchUsersItems)
bot.start({
allowed_updates: ["chat_member", "message", "CALLBACK_QUERY"]
});