Skip to content

Instantly share code, notes, and snippets.

@ScienJus ScienJus/demo.rb
Last active Apr 19, 2017

Embed
What would you like to do?
qqbot 的 demo:通过 Tuling123 的 API 自动回复消息
require 'qqbot'
require 'net/http'
require 'json'
def tuling(msg)
key = 'your tuling123 key'
uri = URI('http://www.tuling123.com/openapi/api')
uri.query =
URI.encode_www_form(
key: key,
info: msg
)
Net::HTTP.start(uri.host, uri.port) do |http|
req = Net::HTTP::Get.new(uri)
res = http.request(req)
JSON.parse(res.body)['text']
end
end
qqbot = QQBot.new
qqbot.poll do |message|
msg = message.content
if msg.kind_of?(String) && msg.start_with?('AI')
reply = tuling(msg[2...msg.length])
if message.type == 0
qqbot.send_to_friend(message.from_id, reply)
elsif message.type == 1
qqbot.send_to_group(message.from_id, reply)
elsif message.type == 2
qqbot.send_to_discuss(message.from_id, reply)
end
end
end
@depctg

This comment has been minimized.

Copy link

commented Feb 11, 2016

line24:
kind_of => kind_of?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.