Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ typings/

# dotenv environment variables file
.env
*.db
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# **Warning**

Discord self-bots will get your account **permanently** suspended! I do not condone using them and this is just an educational project.

# LittleLogger

This discord bot made in Discord JS will copy any messages and log them into sqlite db.

Format
each table will represent a text channel. All logs are dated, and usernames are inputted. Now Handles DMs!
# Database schema

Future updates: return x amount of messages from user.
## Table schema

# Installing
| Name | Type | Nullable | Description |
| :--------------: | :-----: | :------: | :---------------------------------------------------------------------------: |
| id (Primary key) | INTEGER | false | Primary table key |
| channel_id | INTEGER | false | Id for the channel a message was received in |
| message | TEXT | false | The message received |
| user_id | INTEGER | false | The id of the user that sent the message |
| timestamp | INTEGER | false | The time the message was received |
| is_dm | INTEGER | false | If the channel the message was sent in is a DM<br>(`1` if true, `0` if false) |

1. Open config.json and update with your token code
2. run on node:
>npm install --save discord.js
>npm install --save sqlite
>npm install --save moment
# Installing

3.Open node command prompt and type "node index.js" to start and it will start logging!
1. Open `.env` and update with your token code
2. run on node:
> yarn install
> yarn start
5 changes: 0 additions & 5 deletions config.json

This file was deleted.

3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREFIX=>
TOKEN=token
OWNER=id
34 changes: 0 additions & 34 deletions index.js

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "little_logger",
"version": "0.1.2",
"version": "1.1.0",
"description": "Logs all activity in the discord channel in sqlite",
"main": "index.js",
"dependencies": {
"discord.js": "^11.1.0",
"moment": "^2.18.1",
"sqlite": "^2.8.0"
"discord.js": "^12.5.3",
"dotenv": "^9.0.0",
"sqlite": "^4.0.21",
"sqlite3": "^5.0.2"
},
"devDependencies": {},
"scripts": {
"start": "node src",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "litochee",
"author": "litochee, ZachyFoxx",
"license": "ISC"
}
95 changes: 95 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const Discord = require("discord.js");
const sql = require("sqlite");
const sqlite3 = require("sqlite3");
require("dotenv").config();

// Setup our database
const db = sql.open({
filename: "./cordLogs.db",
driver: sqlite3.cached.Database,
});

// Make sure our table is setup
db.then((db) => {
db.run(
"CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY, channel_id INTEGER NOT NULL, message TEXT NOT NULL, user_id INTEGER NOT NULL, timestamp INTEGER NOT NULL, is_dm INTEGER)"
);
});

/// END DATABASE SETUP ///

// Login to Discord
const client = new Discord.Client();

client.login(process.env.TOKEN);

client.on("ready", () => {
console.log("Watching for messages...");
});

// Await messages
client.on("message", (message) => {
logMessage(message);
});

/// END DISCORD SETUP ///

/**
* Log a message sent in a channel
* @param {*} message to log
*/
async function logMessage(message) {
// If the message is an attachment, let's ignore it.
// TODO: If the attachment comes with a message, let's store that
if (message.attachments.size > 0) {
console.log(
`Attachment from ${message.author.username} (${message.author.id}) received, ignoring...`
);
return;
}

// Let's go ahead and log that we received a message from someone
switch (message.channel.type) {
case "dm":
console.log(
`Message received in DM (${message.channel.id}) from '${message.author.username}' (${message.author.id})`
);
break;
case "text":
console.log(
`Message received in channel '#${message.channel.name}' (${message.channel.id}) from '${message.author.username}' (${message.author.id})`
);
break;
}

// Insert the message into our database
insertMessage(db, message);
}

/**
* Insert a message into the sqlite database
* @param {*} db sqlite database
* @param {*} message to insert
*/
async function insertMessage(db, message) {
db.then((db) => {
db.run(
"INSERT INTO messages (channel_id, message, user_id, is_dm, timestamp) VALUES (?, ?, ?, ?, ?)",
[
message.channel.id,
message.content,
message.author.id,
message.channel.type == "dm" ? 1 : 0, // We don't want to insert a boolean into the INTEGER type, so let's convert it.
Date.now(),
]
).catch((ex) => {
// If there is some how an error with inserting, let the user know!
console.log(
"There was an issue inserting this message into the database!"
);

// Let's also log the error generated
console.log(ex);
});
});
}
Loading