Class: Onebot::WebSocket::API
- Inherits:
-
Object
- Object
- Onebot::WebSocket::API
- Defined in:
- lib/Core/WebSocket/API.rb
Instance Attribute Summary collapse
-
#queueList ⇒ Object
Returns the value of attribute queueList.
Instance Method Summary collapse
-
#acceptFriendRequest(flag, reason = nil) ⇒ Boolean
接受好友邀请.
-
#acceptGroupRequest(flag, sub_type) ⇒ Boolean
接受加群请求.
- #get_msg(message_id, _url = @apiUrl) ⇒ Object
-
#initialize(ws, eventLogger) ⇒ API
constructor
A new instance of API.
-
#refuseFriendRequest(flag) ⇒ Boolean
拒绝好友邀请.
-
#refuseGroupRequest(flag, sub_type, reason = nil) ⇒ Boolean
拒绝加群请求.
-
#sendGroupMessage(message, group_id) ⇒ Hash
发送群聊消息.
-
#sendPrivateMessage(message, user_id) ⇒ Hash
发送私聊消息.
Constructor Details
#initialize(ws, eventLogger) ⇒ API
Returns a new instance of API.
7 8 9 10 11 |
# File 'lib/Core/WebSocket/API.rb', line 7 def initialize(ws, eventLogger) @ws = ws @eventLogger = eventLogger @queueList = {} end |
Instance Attribute Details
#queueList ⇒ Object
Returns the value of attribute queueList.
5 6 7 |
# File 'lib/Core/WebSocket/API.rb', line 5 def queueList @queueList end |
Instance Method Details
#acceptFriendRequest(flag, reason = nil) ⇒ Boolean
接受好友邀请
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/Core/WebSocket/API.rb', line 58 def acceptFriendRequest(flag, reason = nil) data = sendReq('set_friend_add_request', { flag:, approve: true, remark: reason }) if parseRet(data) @eventLogger.log '已通过好友请求' true else @eventLogger.log '请求通过失败', Logger::WARN false end end |
#acceptGroupRequest(flag, sub_type) ⇒ Boolean
接受加群请求
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/Core/WebSocket/API.rb', line 89 def acceptGroupRequest(flag, sub_type) data = sendReq('set_group_add_request', { flag:, sub_type:, approve: true }) if parseRet(data) @eventLogger.log '已通过加群请求' true else @eventLogger.log '请求通过失败', Logger::WARN false end end |
#get_msg(message_id, _url = @apiUrl) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/Core/WebSocket/API.rb', line 13 def get_msg(, _url = @apiUrl) ret = sendReq('get_msg', { message_id: }) if parseRet(ret) @eventLogger.log "获取消息成功 (#{})" else @eventLogger.log "获取消息失败,错误码: #{ret.msg}, 错误消息: #{ret.wording}", Logger::WARN end ret[:data] end |
#refuseFriendRequest(flag) ⇒ Boolean
拒绝好友邀请
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/Core/WebSocket/API.rb', line 73 def refuseFriendRequest(flag) data = sendReq('set_friend_add_request', { flag:, approve: false }) if parseRet(data) @eventLogger.log '已拒绝好友请求' true else @eventLogger.log '请求拒绝失败', Logger::WARN false end end |
#refuseGroupRequest(flag, sub_type, reason = nil) ⇒ Boolean
拒绝加群请求
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/Core/WebSocket/API.rb', line 106 def refuseGroupRequest(flag, sub_type, reason = nil) data = sendReq('set_group_add_request', { flag:, sub_type:, approve: false, reason: }) if parseRet(data) @eventLogger.log '已拒绝加群请求' true else @eventLogger.log '请求拒绝失败', Logger::WARN false end end |
#sendGroupMessage(message, group_id) ⇒ Hash
发送群聊消息
43 44 45 46 47 48 49 50 51 |
# File 'lib/Core/WebSocket/API.rb', line 43 def sendGroupMessage(, group_id) ret = sendReq('send_group_msg', { group_id:, message: }) if parseRet(ret) @eventLogger.log "发送至群 #{group_id} 的消息: #{} (#{ret.data.})" else @eventLogger.log "发送群消息失败,错误码: #{ret.msg}, 错误消息: #{ret.wording}", Logger::WARN end ret[:data] end |
#sendPrivateMessage(message, user_id) ⇒ Hash
发送私聊消息
28 29 30 31 32 33 34 35 36 |
# File 'lib/Core/WebSocket/API.rb', line 28 def sendPrivateMessage(, user_id) ret = sendReq('send_private_msg', { user_id:, message: }) if parseRet(ret) @eventLogger.log "发送至私聊 #{user_id} 的消息: #{} (#{ret.data.})" else @eventLogger.log "发送私聊消息失败,错误码: #{ret.msg}, 错误消息: #{ret.wording}", Logger::WARN end ret[:data] end |