Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Whit3XLightning authored Jul 21, 2019
1 parent 9be62a6 commit e077785
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 0 deletions.
267 changes: 267 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "snot",
"version": "1.0.0",
"description": "Discord bot used to log and copy all text messages sent within the bot(s) eyes.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rat",
"copy",
"discord",
"bot"
],
"author": "Whit3Xlightning",
"license": "ISC",
"dependencies": {
"@types/node": "^12.6.8",
"discord.js": "^11.5.1",
"node.js": "0.0.0"
}
}
46 changes: 46 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as d from "discord.js";
import * as fs from "fs";
import * as p from "path";

const b: d.Client = new d.Client();

b.on("ready", () => {
console.log("Connected to discord with token: " + process.argv[2].toString() + ".");
b.user.setStatus('invisible');
fs.access(p.join(__dirname, "Guilds"), fs.constants.F_OK, (err) => {
if (err) {
console.log('Failed to find \"Guilds\" folder. Attemping to create.');
fs.mkdir(p.join(__dirname, "Guilds"), (err) => {
if (err) throw err;
})
console.log('\"Guilds\" folder created.');
}
});
});

b.login(process.argv[2].toString())

b.on("message", async message => {
fs.mkdir(p.join(__dirname, "Guilds", message.guild.name), (err) => {
if (err && err.code != 'EEXIST') throw err;
})
fs.mkdir(p.join(__dirname, "Guilds", message.guild.name, message.channel.parent.name), (err) => {
if (err && err.code != 'EEXIST') throw err;
});
fs.open(p.join(__dirname, "Guilds", message.guild.name, message.channel.parent.name, message.channel.name + ".txt"), 'a', (err, fd) => {
if (err && err.code != "ENOENT") throw err;
var am = "[ " + message.createdAt + " ] " + message.author.username + ": " + message.content
if (message.attachments) {
message.attachments.forEach(attachment => {
am = am + " " + attachment.filename + "(" + attachment.url + ")"
});
}
fs.appendFile(fd, am + "\r\n", 'utf8', (err) => {
fs.close(fd, (err) => {
if (err) throw err;
});
if (err) throw err;
});
console.log("logged 1 message in "+p.join(__dirname, "Guilds", message.guild.name, message.channel.parent.name, message.channel.name + ".txt"))
});
});
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "dist",
"removeComments": true,
"strict": false,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitThis": true,
},
"include": [
"src"
],
"exclude": [

]
}

0 comments on commit e077785

Please sign in to comment.