Skip to content

Commit

Permalink
整合逻辑至bot
Browse files Browse the repository at this point in the history
  • Loading branch information
xhan committed Dec 31, 2013
1 parent fbfa18a commit 7a315b1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 51 deletions.
2 changes: 1 addition & 1 deletion plugins/help.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (content ,send, robot, message)->
send VERSION_INFO

if content.match /^plugins$/i
send "插件列表:\n" + robot.plugin_control.plugins.join('\r\n')
send "插件列表:\n" + robot.dispatcher.plugins.join('\r\n')

if content.match /^time$/i
send "冥王星引力精准校时:" + new Date()
Expand Down
6 changes: 3 additions & 3 deletions src/qqbot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class QQBot

api.cookies @cookies
@api = api
@dispatcher = new Dispatcher(config.plugins)
@dispatcher = new Dispatcher(@config.plugins)

# @format PROTOCOL `用户分组信息格式`
save_buddy_info: (@buddy_info)->
Expand Down Expand Up @@ -160,10 +160,10 @@ class QQBot

log.info "fetching groupmember #{name}"
@update_group_member {name:name} ,(ret,error)=>

groupinfo = @get_group {name:name}
group = new Group(@, groupinfo.gid)
@dispatcher.add_listener group.dispatch
@dispatcher.add_listener [group,"dispatch"]
callback group


Expand Down
11 changes: 6 additions & 5 deletions tests/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ auth_opts ={
###

test_api = ->
# log "长轮训"
api.long_poll auth_opts , (ret)->
log ret


###
api.get_buddy_list auth_opts , (ret,e)->
log 'friend',jsons ret
log ''
api.get_group_list auth_opts, (ret , e)->
log 'group',ret
log ''

###

# api.get_group_member 86784314, vfwebqq , (ret,e)->
# log 'group_member' , ret
Expand All @@ -48,8 +51,6 @@ test_api = ->
# api.send_msg_2group 2559225925, "系统提示:hahha" , auth_opts, (ret,e)->
# log "group send ret:",ret

# log "长轮训"
# api.long_poll auth_opts , (ret)->
# log ret


test_api()
64 changes: 22 additions & 42 deletions tests/bot.coffee
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
#!/usr/bin/env coffee

# qqbot相关的测试代码
int = (v) -> parseInt v
log = console.log

log = new (require 'log')('debug')
jsons = JSON.stringify

auth = require "../src/qqauth"

api = require "../src/qqapi"
QQBot = require "../src/qqbot"
defaults = require '../src/defaults'

config = require '../config'
qq = config.account
pass = config.password


# 设置登录信息
api.cookies defaults.data 'cookie'
auth_opts = defaults.data 'auth'
###
auth_opts ={
psessionid
clientid
ptwebqq
uin
vfwebqq
}
###


bot = new QQBot( api.cookies(), auth_opts ,config )


api.get_buddy_list auth_opts, (ret,e)->
log e if e
log 'friend',jsons ret
log ''
bot.save_buddy_info ret.result if ret.retcode == 0


api.get_group_list auth_opts, (ret , e)->
log e if e
log 'group',jsons ret
log ''
if ret.retcode == 0
bot.save_group_info ret.result
bot.update_group_member({name:"qqbot群"})


api.long_poll auth_opts, (ret,e)->
log e if e
log jsons ret
bot.handle_poll_responce(ret)
cookies = defaults.data 'cookie'
auth_info = defaults.data 'auth'


bot = new QQBot(cookies,auth_info,config)
group = null


bot.listen_group "qqbot群" , (_group,error)->

log.info "enter long poll mode, have fun"
bot.runloop()

group = _group
group.on_message (content ,send, robot, message)->
log.info 'received',content
if content.match /^wow/
send 'mom'

0 comments on commit 7a315b1

Please sign in to comment.