forked from xhan/qqbot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.coffee
executable file
·54 lines (44 loc) · 1.46 KB
/
main.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
#!/usr/bin/env coffee
###
QQBot 独立运行入口
启动命令:./main.coffee (nologin)
@params nologin - 跳过登录模块,方便调试和测试
###
log = new (require 'log')('debug')
auth = require "./src/qqauth"
api = require "./src/qqapi"
QQBot = require "./src/qqbot"
defaults = require './src/defaults'
config = require './config'
KEY_COOKIES = 'qq-cookies'
KEY_AUTH = 'qq-auth'
# 获取接口需要的cookie和token
# @param isneedlogin : 是否需要登录,or本地获取
# @param options : 配置文件涉及的内容
# @callback (cookies,auth_info)
get_tokens = (isneedlogin, options,callback)->
if isneedlogin
auth.login options , (cookies,auth_info)->
defaults.data KEY_COOKIES, cookies
defaults.data KEY_AUTH , auth_info
defaults.save()
callback(cookies,auth_info)
else
cookies = defaults.data KEY_COOKIES
auth_info = defaults.data KEY_AUTH
log.info "skip login"
callback(cookies , auth_info )
# 启动bot
# 获取好友,群,群成员信息,然后进入守护模式
# TODO: 获取信息 + 守护模式 同步状态
run = ->
isneedlogin = process.argv.pop().trim() isnt 'nologin'
get_tokens isneedlogin , config , (cookies,auth_info)->
bot = new QQBot(cookies,auth_info,config)
bot.update_all_members (ret)->
unless ret
log.error "获取信息失败"
process.exit(1)
log.info "Entering runloop, Enjoy!"
bot.runloop()
run()