Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ゼクロ committed Dec 21, 2017
0 parents commit ed28e8d
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\main.js"
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tutorialJSBot
5 changes: 5 additions & 0 deletions config (example).json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"token": "DISCORD BOT TOKEN",
"owner": "221905671296253953",
"prefix": "::"
}
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"token": "MzI4NTc5NjU2MzIyMjUyODAx.DQ7s9A.XxStY0q1_HWbhPfyqwI-tCqreZE",
"owner": "221905671296253953",
"prefix": "::"
}
50 changes: 50 additions & 0 deletions embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { RichEmbed } = require('discord.js')

const COLORS = {
red: 0xe74c3c,
green: 0x2ecc71
}

exports.test = "test"

module.exports = {

/**
* Send an error embed message into a channel
* @param {Discord.Channel} chan Channel where mesage is send to
* @param {string} cont
* @param {string} title
*/
error(chan, cont, title) {
var message
var emb = new RichEmbed()
.setColor(COLORS.red)
.setDescription(cont)
if (title) {
emb.setTitle(title)
}
chan.send('', emb).then((m) => {
message = m
})
return message
},

info(chan, cont, title) {
var emb = {
embed: {
color: COLORS.green,
description: cont,
title: title,
fields: [
{
name: "test",
value: "test",
inline: false
}
]
}
}
chan.send('', emb)
}

}
66 changes: 66 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const Discord = require('discord.js')
const fs = require('fs')
const Embeds = require('./embed')

const config = JSON.parse(fs.readFileSync('config.json', 'utf8'))

var client = new Discord.Client()


const AUTOROLEID = "289905364055621634"


client.on('ready', () => {
console.log(`Logged in as ${client.user.username}...`)
})


var cmdmap = {
say: cmd_say,
test: cmd_test
}

function cmd_say(msg, args) {
msg.channel.send(args.join(' '))
}

function cmd_test(msg, args) {
//Embeds.error(msg.channel, 'This is actuially not an error', 'Not an error')
Embeds.info(msg.channel, "this is a content lel")
}


client.on('message', (msg) => {

var cont = msg.content,
author = msg.member,
chan = msg.channel,
guild = msg.guild

if (author.id != client.user.id && cont.startsWith(config.prefix)) {

// ::say hello world!
var invoke = cont.split(' ')[0].substr(config.prefix.length),
args = cont.split(' ').slice(1)

if (invoke in cmdmap) {
cmdmap[invoke](msg, args)
}
}

})


client.on('guildMemberAdd', (memb) => {
var guild = memb.guild

var role = guild.roles.find(r => r.id == AUTOROLEID)
if (role) {
memb.addRole(role)
memb.send("", Discord.RichEmbed().setDescription(`Hey! YOu got automatically assigned the role <@&${AUTOROLEID}>!`))
}

})


client.login(config.token)
65 changes: 65 additions & 0 deletions package-lock.json

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

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "tutorialjsbot",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "node main.js debug",
"start": "node main.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": ""
}
}

0 comments on commit ed28e8d

Please sign in to comment.