Skip to content

Commit

Permalink
Added Initial Files
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbert Duggan committed Nov 3, 2018
1 parent 85ee084 commit 42af56e
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
149 changes: 149 additions & 0 deletions Delta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//*/Main Setup
const fs = require('fs');
const Discord = require('discord.js');
const Sequelize = require('sequelize');
require('C:/Archives/Code Libs/LBlazeLib.js')();
var config = require('./config.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const cooldowns = new Discord.Collection();
var commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
//*/

//*/ TODO PLEASE MOVE

const responseObject = {
"Delta, Help": "Please gain voice command list by saying \"Delta, Command List\" and say a command with \"Delta,\" Followed by the command to use, or `d!help` for my terminal commands",
"Delta, Command List": "Command List: \"Who made you?\",\"Who are you?\"",
"Delta, Who made you?": "I was created by <@!95645688938893312>",
"Delta, Who are you?": "I am an Extremely Basic AI System"
};

//*/

/*/Setup for SQLite Storage
const sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
operatorsAliases: false,
storage: 'database.sqlite',
});
const Tags = sequelize.define('tags', {
UserID: {
type: Sequelize.STRING,
unique: true,
},
Comments: Sequelize.TEXT,
});
//*/

//*/On client ready up
client.on('ready', () => {
console.log('\033c')
console.log('Loading Delta Systems...');
console.log(' Loading Commands...');
for (const file of commandFiles) {
var command = require(`./commands/${file}`);
client.commands.set(command.name, command);
console.log(' Loading ' + file);
}
console.log(' All Commands Loaded!');
console.log('');
console.log('Delta Systems Ready');
});
//*/


/*/Dynamic User Data Systems
//*/


//*/On Client Get Message
client.on('message', message => {
if(responseObject[message.content]) {
message.channel.send(responseObject[message.content]);
}
else if (message.content.startsWith(config.prefix + "reload"))
{
commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
console.log('');
console.log("New Commands Loaded");
}
else if (message.content.startsWith(config.prefix))
{
const args = message.content.slice(config.prefix.length).split(/ +/);
const commandName = args.shift();

const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

if (!command) return;

if (command.guildOnly && message.channel.type !== 'text') {
return message.reply('I can\'t execute that command inside DMs!');
}

if (command.args && !args.length) {
let reply = `You didn't provide any arguments, ${message.author}!`;

if (command.usage) {
reply += `\nThe proper usage would be: \`${config.prefix}${command.name} ${command.usage}\``;
}

return message.channel.send(reply);
}

if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}

const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000;

if (!timestamps.has(message.author.id)) {
timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
}
else {
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
}

timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
}

try {
command.execute(message, args);
}
catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
}
var x = 0;
while(x < config.toDelete.length)
{
if(message.content.startsWith(config.toDelete[x]))
{
sleep(10)
message.delete()
}
x++;
}
});
//*/

//*/Actually Run Bot
client.login(config.token);
//*/
7 changes: 6 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# delta
## File Layout ##
Delta.js - Main Bot Core
config.js - Config for Bot Core

## Required npm Packages ##

42 changes: 42 additions & 0 deletions commands/getChannelStat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require('C:/Archives/Code Libs/LBlazeLib.js')();
var config = require('../config.js');
var fs = require('fs');

module.exports = {
name: 'getChannelStat',
aliases: ['getChanStat'],
description: 'Get your own (or another users) channel stats',
execute(message, args) {
//*/Make User Data Folder if Needed
var userID = message.member.user.id;
var ChannelID = message.channel.id;
if (args.length==2)
{
userID = message.mentions.members.first().id;
}
var channelFolder = config.dataLocation + '/CHNL-' + ChannelID
var userFolder = channelFolder + '/' + userID;
var statFolder = userFolder + '/stats'
mkFolderIfNeeded(config.dataLocation);
mkFolderIfNeeded(channelFolder);
mkFolderIfNeeded(userFolder);
mkFolderIfNeeded(statFolder);
//*/

//*/Get User Data if it exists
var dataFile = statFolder + '/' + args[0];
if (fs.existsSync(dataFile)){
fs.readFile(dataFile, 'utf8', function (err,data) {
if (err) {
console.log(err);
}
message.reply('Current channel ' + args[0] + ' of <@!' + userID + '> is ' + data);
});
}
else
{
message.reply('ERROR, Defaults do not yet exist');
}
//*/
},
};
38 changes: 38 additions & 0 deletions commands/getStat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require('C:/Archives/Code Libs/LBlazeLib.js')();
var config = require('../config.js');
var fs = require('fs');

module.exports = {
name: 'getStat',
description: 'Get your own stat',
execute(message, args) {
//*/Make User Data Folder if Needed
var userID = message.member.user.id;
if (args.length==2)
{
userID = message.mentions.members.first().id;
}
var userFolder = config.dataLocation + '/' + userID;
var statFolder = userFolder + '/stats'
mkFolderIfNeeded(config.dataLocation);
mkFolderIfNeeded(userFolder);
mkFolderIfNeeded(statFolder);
//*/

//*/Get User Data if it exists
var dataFile = statFolder + '/' + args[0];
if (fs.existsSync(dataFile)){
fs.readFile(dataFile, 'utf8', function (err,data) {
if (err) {
console.log(err);
}
message.reply('Current ' + args[0] + ' of <@!' + userID + '> is ' + data);
});
}
else
{
message.reply('ERROR, Defaults do not yet exist');
}
//*/
},
};
46 changes: 46 additions & 0 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var config = require('../config.js');

module.exports = {
name: 'help',
description: 'List all available commands, or info about a speciifc command',
aliases: ['commands'],
usage: '[command name]',
cooldown: 5,
execute(message, args) {
const data = [];
const { commands } = message.client;

if (!args.length) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${config.prefix}help [command name]\` to get info on a specific command!`);

return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like I can\'t DM you!');
});
}

const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));

if (!command) {
return message.reply('that\'s not a valid command!');
}

data.push(`**Name:** ${command.name}`);

if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
if (command.description) data.push(`**Description:** ${command.description}`);
if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);

data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);

message.channel.send(data, { split: true });
},
};
7 changes: 7 additions & 0 deletions commands/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
description: 'Basic ping command, responds with `Pong.`',
execute(message, args) {
message.channel.send('Pong.');
},
};
41 changes: 41 additions & 0 deletions commands/setChannelStat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require('C:/Archives/Code Libs/LBlazeLib.js')();
var config = require('../config.js');
var fs = require('fs');

module.exports = {
name: 'setChannelStat',
aliases: ['setChanStat'],
description: 'Set your own channel stats',
execute(message, args) {
//*/Make User Data Folder if Needed
var userID = message.member.user.id;
var ChannelID = message.channel.id;
var channelFolder = config.dataLocation + '/' + ChannelID
var userFolder = channelFolder + '/' + userID;
var statFolder = userFolder + '/stats'
mkFolderIfNeeded(config.dataLocation);
mkFolderIfNeeded(channelFolder);
mkFolderIfNeeded(userFolder);
mkFolderIfNeeded(statFolder);
//*/

//*/Get User Data if it exists
var dataSet = args[1];
var i = 2
while(i<args.length)
{
dataSet = dataSet + " " + args[i];
i++
}
var dataFile = statFolder + '/' + args[0];
if (fs.existsSync(dataFile)){
fs.writeFileSync(dataFile,dataSet)
message.reply("Set " + args[0] + " to " + dataSet)
}
else
{
message.reply('ERROR, Defaults do not yet exist');
}
//*/
},
};
37 changes: 37 additions & 0 deletions commands/setStat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require('C:/Archives/Code Libs/LBlazeLib.js')();
var config = require('../config.js');
var fs = require('fs');

module.exports = {
name: 'setStat',
description: 'Set your own stat',
execute(message, args) {
//*/Make User Data Folder if Needed
var userID = message.member.user.id;
var userFolder = config.dataLocation + '/' + userID;
var statFolder = userFolder + '/stats'
mkFolderIfNeeded(config.dataLocation);
mkFolderIfNeeded(userFolder);
mkFolderIfNeeded(statFolder);
//*/

//*/Get User Data if it exists
var dataSet = args[1];
var i = 2
while(i<args.length)
{
dataSet = dataSet + " " + args[i];
i++
}
var dataFile = statFolder + '/' + args[0];
if (fs.existsSync(dataFile)){
fs.writeFileSync(dataFile,dataSet)
message.reply("Set " + args[0] + " to " + dataSet)
}
else
{
message.reply('ERROR, Defaults do not yet exist');
}
//*/
},
};
6 changes: 6 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
"prefix": "d!",
"token": "NDA3MDc3MjE4MTI5MjgxMDI0.DjNFhA.pXapMXPJKB-TXAfEZc07t4xxXSM",
"toDelete": ["f.","d!"],
"dataLocation": "./Data",
}

0 comments on commit 42af56e

Please sign in to comment.