forked from brentcobb/haiku-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (38 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
A Haiku bot, it makes haikus from discord chatter.
*/
if (process.env.ENVIRONMENT === 'local') {
require('dotenv').config()
}
const http = require('http')
const Discord = require('discord.js')
const client = new Discord.Client()
const syllable = require('syllable')
const writeHaiku = require('./haikuWriter.js')
const db = require('./db.js')
const token = process.env.DISCORD_TOKEN
client.on('ready', () => {
console.log('I am ready!')
})
client.on('message', message => {
console.log('--SYLLABLE COUNT--/s', syllable(message.content))
if (syllable(message.content) == '17' && message.author.bot != true) {
haiku = writeHaiku(message.content)
console.log('haiku', haiku)
message.channel.send(haiku.msg, { code: true, split: { char: '\n' } })
var haikuToSave = {
_id: message.id,
author: message.author.username,
initialMessage: message.content,
generatedArrays: haiku.arrays,
generatedHaiku: haiku.msg,
type: 'haiku',
date: Date.now()
}
db.saveHaiku(haikuToSave, message.id)
}
})
// Haiku bot enters the arean
client.login(token)
// pay attention on this port young bot
http.createServer().listen(process.env.PORT)