This repository has been archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.coffee
62 lines (51 loc) · 1.84 KB
/
bot.coffee
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
nesh = require 'nesh'
fs = require 'fs'
events = require 'events'
path = require 'path'
class NexerqBotClass
constructor: ->
@Config = {}
@Clients = {}
@Main = {}
@Modules = {}
@Events = new events.EventEmitter()
NexerqBot = new NexerqBotClass
# Nesh REPL Server
nesh.config.load()
nesh.loadLanguage 'coffee'
# Get welcome ver from package json
packagedata = JSON.parse fs.readFileSync './package.json', 'utf8'
nesh.start
welcome: "NexerqBot v#{packagedata.version} 2015"
prompt: 'NexerqBot » '
useGlobal: true,
(err, repl) ->
nesh.log.error err if err
repl.context.NexerqBot = NexerqBot
console.log '\n'
NexerqBot.mainModNames = []
# Load the main client modules (for files in ./main)
for mod in fs.readdirSync './main'
continue if path.extname mod isnt '.coffee'
modName = mod.replace '.coffee', ''
mod = require "./main/#{modName}"
NexerqBot[modName] = new mod NexerqBot
NexerqBot.mainModNames.push modName
NexerqBot.Logging.info 'NexerqBot', "Main client modules loaded: #{NexerqBot.mainModNames.join ', '}."
# Load modules (chat handlers, etc) [for files in ./modules]
for mod in fs.readdirSync './modules'
continue if path.extname mod isnt '.coffee'
modName = mod.replace '.coffee', ''
mod = require "./modules/#{modName}"
NexerqBot.Modules[modName] = new mod NexerqBot
NexerqBot.Logging.info 'NexerqBot', "Handler modules loaded: #{Object.keys(NexerqBot.Modules).join ', '}."
# Load config and then start clients and db
NexerqBot.ConfigIO.load ->
NexerqBot.Redis.init()
# Connect clients and init clients
NexerqBot.Twitch.connect()
NexerqBot.TwitchWhisp.connect()
NexerqBot.OsuChat.connect()
NexerqBot.OsuApi.init()
# Event? (make sure its ready for some modules that need db access)
NexerqBot.Events.emit 'bot.ready'