const id = 5;
const users = [
{
"id" : 5,
"name" : "Jalla",
"lastName" : "Koo",
"age" : 22
},
{
"id" : 6,
"name" : "Jalla",
"lastName" : "Koo",
"age" : 22
},
{
"id" : 7,
"name" : "Lella",
"lastName" : "Moo",
"age" : 33
}
];
const index = users.map(x => x.id).indexOf(id);
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
message = event.obj['message']
text = message['text']
if text.lower() == "привет":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": text,
"random_id": 0})
elif event.object.peer_id == event.object.from_id:
if text.lower() == "привет":
vk.method("messages.send", {"user_id": event.object.from_id, "message": text,
"random_id": 0})
import os
import requests
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
TOKEN = ''
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start', 'help'])
async def start(message: types.Message):
await bot.send_message(message.chat.id, text='привет')
@dp.message_handler(content_types=['text'])
async def downloader(message: types.Message):
instagram_post = message.text
if "instagram.com" in instagram_post:
changing_url = instagram_post.split("/")
url_code = changing_url[4]
url = f"https://instagram.com/p/{url_code}?__a=1"
global checking_video
try:
visit = requests.get(url).json()
checking_video = visit['graphql']['shortcode_media']['is_video']
except:
await bot.send_message(message.chat.id, text="Send Me Only Public Instagram Posts")
if checking_video==True:
try:
video_url = visit['graphql']['shortcode_media']['video_url']
await bot.send_video(message.chat.id, video=video_url)
except:
pass
elif checking_video==False:
try:
post_url = visit['graphql']['shortcode_media']['display_url']
await bot.send_photo(message.chat.id, photo=post_url)
except:
pass
else:
await bot.send_message(message.chat.id, text="I Cant Send You Private Posts")
else:
await bot.send_message(message.chat.id, text="Kindly Send Me Public Instagram Video/Photo Url")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
let obj = {
"productRows": [
{
"id": 26046,
"ownerId": 20708,
"ownerType": "D",
"productId": 0,
"productName": "Товар не из каталога",
"price": 11,
"quantity": 1
},
{
"id": 25844,
"ownerId": 20708,
"ownerType": "D",
"productId": 2,
"productName": "Товар 2",
"price": 900,
"quantity": 5
}
]
};
obj = obj["productRows"].map(x => x = { productId: x.productId, productName: x.productName, price: x.price, quantity: x.quantity });
console.log(obj);
const { VK, uploadErrors, Keyboard, Context } = require('vk-io');
const vk = new VK();
const commands = [];
const users = require('./users.json');
const chats = require('./chats.json');
const fs = require('fs');
const { NONAME } = require('dns');
setInterval(async () => {
await saveUsers();
}, 1000);
async function saveUsers()
{
require('fs').writeFileSync('./users.json', JSON.stringify(users, null, '\t'));
require('fs').writeFileSync('./chats.json', JSON.stringify(chats, null, '\t'));
return true;
}
vk.setOptions({ token: '', pollingGroupId: });
/* const { updates, snippets } = vk; */
vk.updates.on('message', async (message, next) => {
if(Number(message.senderId) <= 0) return;
if(/\[club209536507\|(.*)\]/i.test(message.text)) message.text = message.text.replace(/\[clubсудаайдигруппы\|(.*)\]/ig, '').trim();
if(!chats.find(x=>x.id===message.chatId))
{
const chat = await vk.api.messages.getConversationsById({ peer_ids: message.peerId, extended: 1, fields: 'chat_settings', group_id: 209536507 }); // это обязательно
const [peer] = chat.items;
const chat_info = peer.chat_settings;
message.send(`Ваша беседа успешно активирована.`)
chats.push({
id: message.chatId,
cid: chats.length,
name: `${chat_info.title}`,
owner: chat_info.owner_id,
greeting: null,
members: []
})
}
const peer = chats.filter(x => x.id === message.chatId)[0];
const user = peer.members.filter(x => x.id === message.senderId)[0];
if(!peer.members.find(x=>x.id===message.senderId))
{
const [user_info] = await vk.api.users.get({ user_id: message.senderId });
peer.members.push({
id: message.senderId,
ban: false,
points: 0,
warn: 0,
mute: 0,
role: 0
})
}
if(peer.owner==message.senderId) return user.role=4
if(!users.find(x=>x.id===message.senderId))
{
const [user_info] = await vk.api.users.get({ user_id: message.senderId });
users.push({
id: message.senderId,
gban: false,
tag: `${user_info.first_name}`
})
}
message.user = users.find(x=> x.id === message.senderId);
const bot = (text, params) => {
return message.send(` ${message.user.mention ? `@id${message.user.id} (${message.user.nick})` : `${message.user.nick}`}, ${text}`, params);
}
const command = commands.find(x=> x[0].test(message.text));
if(!command) return;
message.args = message.text.match(command[0]);
await command[1](message, bot);
let date = new Date;
message.user.last_sms = date;
message.user.message_sms += 1;
console.log();
return next();
});
vk.updates.on(['chat_kick_user'], (next, context) => {
const peer = chats.filter(x => x.id === next.chatId)[0];
const user = peer.members.filter(x => x.id === next.eventMemberId)[0];
vk.api.messages.removeChatUser({ chat_id: next.chatId, user_id: user.id });
});
vk.updates.hear(/^(?:greeting)$/i, async (message, bot) => {
console.log(message)
return message.send(`Команда заработала.`)
});
var user = { lastScroll: 0 };
// представим, что произошло событие скролла
if(user.lastScroll > Date.now()) return;
user.lastScroll = Date.now() + 300;
const fs = require('fs');
const json = require('./file.json'); // в этом файле []
let object = await /*здесь вводишь этот АПИ метод с нужными параметрами*/
json.push(object); // добавляем в массив (из файла file.json) объект, только что полученный запросом.
fs.writeFileSync("./file.json", JSON.stringify(file, null, "\t")); // перезаписываем данные из переменной file в file.json
// vk - переменная Вашего колбека в коде, msg объект сообщения
vk.api.messages.getConversationsById({ peer_ids: msg.peerId, extended: 1, fields: 'chat_settings', group_id: /*положительное айди вашей группы*/ }).then((res) => { console.log(res[0].items.chat_settings.title) });