wechat-bot2 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +13 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/Rakefile +41 -0
- data/lib/wechat/bot/cached_list.rb +15 -0
- data/lib/wechat/bot/callback.rb +15 -0
- data/lib/wechat/bot/client.rb +574 -0
- data/lib/wechat/bot/configuration.rb +70 -0
- data/lib/wechat/bot/contact.rb +214 -0
- data/lib/wechat/bot/contact_list.rb +56 -0
- data/lib/wechat/bot/core.rb +138 -0
- data/lib/wechat/bot/exception.rb +4 -0
- data/lib/wechat/bot/ext/wechat_emoji_string.rb +16 -0
- data/lib/wechat/bot/handler.rb +92 -0
- data/lib/wechat/bot/handler_list.rb +92 -0
- data/lib/wechat/bot/helper.rb +2 -0
- data/lib/wechat/bot/http/adapter/js.rb +33 -0
- data/lib/wechat/bot/http/adapter/xml.rb +29 -0
- data/lib/wechat/bot/http/session.rb +117 -0
- data/lib/wechat/bot/logger.rb +102 -0
- data/lib/wechat/bot/message.rb +282 -0
- data/lib/wechat/bot/message_data/share_card.rb +46 -0
- data/lib/wechat/bot/pattern.rb +63 -0
- data/lib/wechat/bot/version.rb +5 -0
- data/lib/wechat/bot.rb +12 -0
- data/lib/wechat-bot.rb +3 -0
- data/lib/wechat_bot.rb +3 -0
- data/wechat-bot.gemspec +40 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76b246c63b536774556c5fafa531bebc278f0f549842f05ced1653093e72f762
|
4
|
+
data.tar.gz: a4a77da6a1aad60695c87ddd315e4653ba10128a7beffbb6563e12dd67c2dd7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb7625ff7fba4b614ff551c92bc45471a259085408234020ef617c33e3d118c363067f4cdb8d6a8021d93270cea6e0fe4521cadb1dab7ad47f591075ea1b5970
|
7
|
+
data.tar.gz: ecf78ee7d7a1c80f33337336c57d07e1fa66e25194f76f905dffa4f8acadbf8f6f687f54e1a911ae759eed0784d8c6f8fdc983bea778b5fda7f5286a133f247f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 120
|
3
|
+
|
4
|
+
Metrics/MethodLength:
|
5
|
+
Max: 20
|
6
|
+
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Max: 150
|
9
|
+
|
10
|
+
Style/AsciiComments:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/SpecialGlobalVars:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Lint/AssignmentInCondition:
|
17
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
wechat-bot
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.yardopts
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at icyleaf.cn@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 icyleaf
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# wechat-bot
|
2
|
+
|
3
|
+
[![Build Status](https://img.shields.io/circleci/project/github/icyleaf/wechat-bot.svg?style=flat)](https://circleci.com/gh/icyleaf/wechat-bot)
|
4
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/icyleaf/wechat-bot.svg?style=flat)](https://codeclimate.com/github/icyleaf/wechat-bot)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/icyleaf/wechat-bot.svg?style=flat)](https://inch-ci.org/github/icyleaf/wechat-bot)
|
6
|
+
[![Gem version](https://img.shields.io/gem/v/wechat-bot.svg?style=flat)](https://rubygems.org/gems/wechat-bot)
|
7
|
+
[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat)](LICENSE.txt)
|
8
|
+
|
9
|
+
微信机器人 Ruby 版本。
|
10
|
+
|
11
|
+
## 快速上手
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'wechat-bot'
|
15
|
+
|
16
|
+
bot = Wechat::Bot.new do
|
17
|
+
on :message, "ping" do |message|
|
18
|
+
message.reply "PONG"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
bot.start
|
23
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'wechat_bot'
|
3
|
+
require 'awesome_print'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task :default => [:rubocop, :spec]
|
12
|
+
|
13
|
+
desc 'Run a sample wechat bot'
|
14
|
+
task :bot do
|
15
|
+
bot = WeChat::Bot.new do
|
16
|
+
configure do |c|
|
17
|
+
c.verbose = true
|
18
|
+
end
|
19
|
+
|
20
|
+
on :message do |m|
|
21
|
+
case m.kind
|
22
|
+
when WeChat::Bot::Message::Kind::Text
|
23
|
+
m.reply m.message
|
24
|
+
when WeChat::Bot::Message::Kind::Emoticon
|
25
|
+
if m.media_id.to_s.empty?
|
26
|
+
m.reply "微信商店的表情哪有私藏的好用!"
|
27
|
+
else
|
28
|
+
m.reply m.media_id, type: :emoticon
|
29
|
+
end
|
30
|
+
when WeChat::Bot::Message::Kind::ShareCard
|
31
|
+
m.reply "标题:#{m.meta_data.title}\n描述:#{m.meta_data.description}\n#{m.meta_data.link}"
|
32
|
+
when WeChat::Bot::Message::Kind::System
|
33
|
+
m.reply "系统消息:#{m.message}"
|
34
|
+
else
|
35
|
+
m.reply "[#{m.kind}]消息:#{m.message}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
bot.start
|
41
|
+
end
|