Fixed myInfos and added help command

main
Killian 4 years ago
parent 00cdd5bebf
commit 0f6b6042c7

@ -1,2 +1,3 @@
BOTUSERNAME=Your bot account username
PASSWORD=Your bot account password
PASSWORD=Your bot account password
DATABASEURL=The url of your mongoDB database (can be local or cluster and need to be URL friendly)

@ -0,0 +1,19 @@
const Command = require("../../Structure/Command.js");
module.exports = class extends Command {
constructor(client) {
super(client, {
name: "help",
description: "Return the commands list.",
category: "Bot",
enabled: true,
aliases: ["?"],
cooldown: 3,
dmOnly: false,
});
}
async run(message, args) {
message.chat.sendMessage("Here are the commands you can use ! https://github.com/Mr-KayJayDee/instagram-bot#available-commands")
}
}

@ -14,8 +14,9 @@ module.exports = class extends Command {
}
async run(message, args) {
message.chat.sendMessage(
`FUll Name: ${message.author.fullName}
message.author.fetch().then(e => {
message.chat.sendMessage(
`Full Name: ${message.author.fullName}
Username: ${message.author.username}
ID: ${message.author.id}
Biography:\n${message.author.biography}
@ -27,5 +28,6 @@ Private: ${message.author.isPrivate}
Number Of Posts: ${message.author.mediaCount}
Number Of IGTV posts: ${message.author.totalIgtvVideos}
`)
})
}
}

@ -5,10 +5,10 @@ module.exports = class {
async emit() {
this.client.logger.log(`Logged in as ${this.client.user.fullName} (${this.client.user.username}).`, "ready");
this.client.logger.log(`Followers: ${this.client.user.followerCount}`, "ready")
this.client.logger.log(`Following: ${this.client.user.followingCount}`, "ready")
this.client.logger.log(`Business : ${this.client.user.isBusiness}`, "ready")
this.client.logger.log(`Verified: ${this.client.user.isVerified}`, "ready")
this.client.logger.log(`Private: ${this.client.user.isPrivate}`, "ready")
this.client.logger.log(`Followers: ${this.client.user.followerCount}`, "ready");
this.client.logger.log(`Following: ${this.client.user.followingCount}`, "ready");
this.client.logger.log(`Business : ${this.client.user.isBusiness}`, "ready");
this.client.logger.log(`Verified: ${this.client.user.isVerified}`, "ready");
this.client.logger.log(`Private: ${this.client.user.isPrivate}`, "ready");
}
}

@ -6,8 +6,21 @@ module.exports = class {
}
async emit(message) {
const data = {};
data.config = this.client.config;
if (message.authorID === this.client.user.id) return;
message.markSeen();
if (message.chat.isGroup) {
const groupMembersData = await this.client.findOrCreateGroupMember({ id: message.author.id, groupID: message.chat.id });
data.groupMembers = groupMembersData;
console.log(groupMembersData)
const groupsData = await this.client.findOrCreateGroup({ groupID: message.chat.id });
data.groups = groupsData;
} else {
const usersData = await this.client.findOrCreateUser({ id: message.author.id });
data.users = usersData;
}
let prefixes = this.client.config.defaultPrefix;
if (message.content.indexOf(prefixes) !== 0) return;
@ -46,6 +59,6 @@ module.exports = class {
tStamps.set(message.authorID, timeNow);
setTimeout(() => tStamps.delete(message.authorID), cdAmount);
cmd.run(message, args);
cmd.run(message, args, data);
}
}

@ -0,0 +1,7 @@
const mongoose = require("mongoose"),
Schema = mongoose.Schema;
module.exports = mongoose.model("GroupMembers", new Schema({
id: String,
groupID: String,
}));

@ -0,0 +1,10 @@
const mongoose = require("mongoose"),
Schema = mongoose.Schema;
module.exports = mongoose.model("Groups", new Schema({
groupID: String,
reminds: {
type: Array,
default: []
},
}));

@ -0,0 +1,10 @@
const mongoose = require("mongoose"),
Schema = mongoose.Schema;
module.exports = mongoose.model("Users", new Schema({
id: String,
reminds: {
type: Array,
default: []
},
}));

@ -85,13 +85,13 @@ it means that the bot is ready to be used. 🎉
# Known bugs
- A story answer return an error (TypeError: Cannot read property 'indexOf' of undefined)
- A story answer return an error (TypeError: Cannot read property 'indexOf' of undefined, same for all system messages)
# Future updates
- Ability to change the prefix on a chat
- Ability to change the lang
- Ability to make reminders
- Ability to make reminders (working on it)
- Ability to get the informations about an user
Feel free to make a pull request if you have any edit to do in the code or just open an issue if you don't know how to fix it.

@ -1,20 +1,27 @@
const { Client } = require("@androz2091/insta.js"),
Collection = require("@discordjs/collection")
Collection = require("@discordjs/collection")
path = require("path");
class InstaBot extends Client {
constructor(options) {
super(options);
["commands", "aliases", "cooldowns"].forEach(x => this[x] = new Collection());
["commands", "aliases", "cooldowns"].forEach(x => this[x] = new Collection());
this.config = require("../config");
this.logger = require("../Helpers/logger");
this.usersData = require("../Models/Users");
this.groupsData = require("../Models/Groups")
this.groupMembersData = require("../Models/GroupMembers")
this.databaseCache = {};
this.databaseCache.users = new Collection();
this.databaseCache.groups = new Collection();
this.databaseCache.groupMembers = new Collection();
}
loadCommand(commandPath, commandName) {
try {
const props = new (require(`.${commandPath}${path.sep}${commandName}`))(this);
props.conf.location = commandPath;
if (props.init){
if (props.init) {
props.init(this);
}
this.commands.set(props.help.name, props);
@ -27,22 +34,73 @@ class InstaBot extends Client {
}
}
async unloadCommand (commandPath, commandName) {
async unloadCommand(commandPath, commandName) {
let command;
if(this.commands.has(commandName)) {
if (this.commands.has(commandName)) {
command = this.commands.get(commandName);
} else if(this.aliases.has(commandName)){
} else if (this.aliases.has(commandName)) {
command = this.commands.get(this.aliases.get(commandName));
}
if(!command){
if (!command) {
return `The command \`${commandName}\` doesn't seem to exist, nor is it an alias. Try again!`;
}
if(command.shutdown){
if (command.shutdown) {
await command.shutdown(this);
}
delete require.cache[require.resolve(`.${commandPath}${path.sep}${commandName}.js`)];
return false;
}
async findOrCreateUser({ id: userID }, isLean) {
if (this.databaseCache.users.get(userID)) {
return isLean ? this.databaseCache.users.get(userID).toJSON() : this.databaseCache.users.get(userID);
} else {
let userData = (isLean ? await this.usersData.findOne({ id: userID }).populate("members").lean() : await this.usersData.findOne({ id: userID }).populate("members"));
if (userData) {
if (!isLean) this.databaseCache.users.set(userID, userData);
return userData;
} else {
userData = new this.usersData({ id: userID });
await userData.save();
this.databaseCache.users.set(userID, userData);
return isLean ? userData.toJSON() : userData;
}
}
}
async findOrCreateGroupMember({ id: userID, groupID: groupID }, isLean) {
if (this.databaseCache.groupMembers.get(`${userID}-${groupID}`)) {
return isLean ? this.databaseCache.groupMembers.get(`${userID}-${groupID}`).toJSON() : this.databaseCache.groupMembers.get(`${userID}-${groupID}`);
} else {
let groupMemberData = (isLean ? await this.groupMembersData.findOne({ id: userID, groupID: groupID }).populate("members").lean() : await this.groupMembersData.findOne({ id: userID, groupID: groupID }).populate("members"));
if (groupMemberData) {
if (!isLean) this.databaseCache.groupMembers.set(`${userID}-${groupID}`, groupMemberData);
return groupMemberData;
} else {
groupMemberData = new this.groupMembersData({ id: userID, groupID: groupID });
await groupMemberData.save();
this.databaseCache.groupMembers.set(`${userID}-${groupID}`, groupMemberData);
return isLean ? groupMemberData.toJSON() : groupMemberData;
}
}
}
async findOrCreateGroup({ groupID: groupID }, isLean) {
if (this.databaseCache.groups.get(groupID)) {
return isLean ? this.databaseCache.groupMembers.get(groupID).toJSON() : this.databaseCache.groupMembers.get(groupID);
} else {
let groupData = (isLean ? await this.groupMembersData.findOne({ groupID: groupID }).populate("members").lean() : await this.groupMembersData.findOne({ groupID: groupID }).populate("members"));
if (groupData) {
if (!isLean) this.databaseCache.groupMembers.set(groupID, groupData);
return groupData;
} else {
groupData = new this.groupMembersData({ groupID: groupID });
await groupData.save();
this.databaseCache.groupMembers.set(groupID, groupData);
return isLean ? groupData.toJSON() : groupData;
}
}
}
}
module.exports = InstaBot;

@ -3,7 +3,8 @@ const InstaBot = require("./Structure/Client"),
const util = require("util"),
fs = require("fs"),
readdir = util.promisify(fs.readdir);
readdir = util.promisify(fs.readdir),
mongoose = require("mongoose");
require("dotenv").config();
const initialize = async () => {
@ -26,5 +27,11 @@ const initialize = async () => {
delete require.cache[require.resolve(`./Events/${file}`)];
});
client.login(process.env.BOTUSERNAME, process.env.PASSWORD);
mongoose.connect(process.env.DATABASEURL, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
client.logger.log("Connected to the Mongodb database.", "ready");
}).catch((err) => {
client.logger.log("Unable to connect to the Mongodb database. Error:"+err, "error");
});
};
initialize();

@ -1,6 +1,6 @@
{
"name": "instabot",
"version": "1.1.2",
"version": "1.1.5",
"description": "A fully working instagram bot using Insta.js by androz2091",
"main": "index.js",
"scripts": {
@ -14,6 +14,9 @@
"@discordjs/collection": "^0.1.6",
"chalk": "^4.1.0",
"discord-image-generation": "^1.3.7",
"dotenv": "^8.2.0"
"dotenv": "^8.2.0",
"mongoose": "^5.10.1",
"ms": "^2.1.2",
"node-fetch": "^2.6.0"
}
}

Loading…
Cancel
Save