ruboty-discord 1.0.0.beta1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +13 -0
- data/.github/ISSUE_TEMPLATE.md +30 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/CONTRIBUTING.md +13 -0
- data/README.md +11 -5
- data/Rakefile +4 -0
- data/lib/ruboty/adapters/discord.rb +13 -10
- data/lib/ruboty/discord/version.rb +1 -1
- data/ruboty-discord.gemspec +4 -2
- data/spec/ruboty/adapters/discord_spec.rb +61 -0
- data/spec/spec_helper.rb +2 -0
- metadata +47 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e48c29baaca622d2bafb994194cf7642344a672f
|
4
|
+
data.tar.gz: 8134ad7b258cc5854fedbc5fb33bcb436e5ff8d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79047156beaf021ae1b2adb5427d299379ab63e9d1b1f2c22d24dfe152374023fc88cdfe9c8a4181a5148260d2d4139432563023157e216955e1db884af9a0e
|
7
|
+
data.tar.gz: ad4f9bdc2522f85906457ee21c15c917df3d033681f11031b58c0211b0850cf13f35ed8a81edd18a780ff3301558e3f47b391ca6d61761988fc7dba29c9339aa
|
data/.editorconfig
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
<!-- Choose Issue type -->
|
2
|
+
|
3
|
+
This issue is a **Feature request** or **Bug Report**.
|
4
|
+
|
5
|
+
### Summary
|
6
|
+
|
7
|
+
<!-- Please edit -->
|
8
|
+
|
9
|
+
<!-- only bug report -->
|
10
|
+
<!--
|
11
|
+
### Check list
|
12
|
+
|
13
|
+
- [ ] Do you reproduce the bug on the [master](https://github.com/ykzts/ruboty-discord/tree/master) branch?
|
14
|
+
- [ ] Did you check whether the bug is duplicated? ([Issues](https://github.com/ykzts/ruboty-discord/issues))
|
15
|
+
|
16
|
+
### Step to reproduce
|
17
|
+
|
18
|
+
1. ...
|
19
|
+
2. ...
|
20
|
+
3. ...
|
21
|
+
|
22
|
+
### Your Environment
|
23
|
+
|
24
|
+
| sofware | version |
|
25
|
+
|-----------------|----------------------------|
|
26
|
+
| Ruby | 2.4.2? |
|
27
|
+
| Ruboty | 1.3.0? |
|
28
|
+
| Ruboty::Discord | 1.0.0? |
|
29
|
+
| OS | GNU/Linux? macOS? Windows? |
|
30
|
+
-->
|
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ykzts@desire.sh. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
data/README.md
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
-
# Ruboty::Discord
|
1
|
+
# Ruboty::Discord [![build status](https://travis-ci.org/ykzts/ruboty-discord.svg?branch=master)](https://travis-ci.org/ykzts/ruboty-discord)
|
2
2
|
|
3
|
-
Discord adapter for [Ruboty](https://github.com/r7kamura/ruboty)
|
3
|
+
Discord adapter for [Ruboty](https://github.com/r7kamura/ruboty).
|
4
4
|
|
5
|
-
##
|
5
|
+
## Install
|
6
6
|
|
7
7
|
```ruby
|
8
8
|
# Gemfile
|
9
|
-
gem
|
9
|
+
gem 'ruboty-discord'
|
10
10
|
```
|
11
11
|
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
1. Create new App ([https://discordapp.com/developers/applications/me/create](https://discordapp.com/developers/applications/me/create))
|
15
|
+
2. Get Client ID & bot user token
|
16
|
+
3. Open `https://discordapp.com/oauth2/authorize?scope=bot&client_id=xxxxxxxxx` (Replace `xxxxxxxxx` with client ID)
|
17
|
+
|
12
18
|
## ENV
|
13
19
|
|
14
20
|
```plain
|
15
|
-
DISCORD_TOKEN - Account
|
21
|
+
DISCORD_TOKEN - Account's token
|
16
22
|
```
|
data/Rakefile
CHANGED
@@ -4,8 +4,8 @@ require 'discordrb'
|
|
4
4
|
require 'ruboty/adapters/base'
|
5
5
|
|
6
6
|
module Ruboty
|
7
|
-
module Adapters
|
8
|
-
class Discord < Base
|
7
|
+
module Adapters # :nodoc:
|
8
|
+
class Discord < Base # :nodoc:
|
9
9
|
env :DISCORD_TOKEN, 'Account\'s token. get one on https://discordapp.com/developers/applications/me'
|
10
10
|
|
11
11
|
def run
|
@@ -16,7 +16,8 @@ module Ruboty
|
|
16
16
|
|
17
17
|
def say(message)
|
18
18
|
channel_id = message[:to]
|
19
|
-
|
19
|
+
body = message[:body]
|
20
|
+
content = message[:code] ? "```\n#{body}\n```" : body
|
20
21
|
|
21
22
|
bot.send_message(channel_id, content)
|
22
23
|
end
|
@@ -44,20 +45,22 @@ module Ruboty
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def on_message(message)
|
47
|
-
body = message.content.gsub(/<@([^>]+?)>/) do |matched|
|
48
|
-
user_id = $1.to_i
|
49
|
-
user = message.mentions.find { |user| user.id == user_id }
|
50
|
-
user.nil? ? matched : "@#{user.username}"
|
51
|
-
end
|
52
|
-
|
53
48
|
robot.receive(
|
54
|
-
body:
|
49
|
+
body: parse_content(message),
|
55
50
|
from: message.channel.id,
|
56
51
|
from_name: message.author.name,
|
57
52
|
to: message.channel.id,
|
58
53
|
time: message.timestamp
|
59
54
|
)
|
60
55
|
end
|
56
|
+
|
57
|
+
def parse_content(message)
|
58
|
+
message.content.gsub(/<@([^>]+?)>/) do |matched|
|
59
|
+
user_id = Regexp.last_match[1].to_i
|
60
|
+
user = message.mentions.find { |mention| mention.id == user_id }
|
61
|
+
user.nil? ? matched : "@#{user.username}"
|
62
|
+
end
|
63
|
+
end
|
61
64
|
end
|
62
65
|
end
|
63
66
|
end
|
data/ruboty-discord.gemspec
CHANGED
@@ -13,8 +13,10 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.files = `git ls-files -z`.split("\x0")
|
15
15
|
spec.require_paths = ['lib']
|
16
|
-
spec.add_dependency 'ruboty', '>= 1.0.4'
|
17
16
|
spec.add_dependency 'discordrb', '~> 3.2'
|
18
|
-
spec.
|
17
|
+
spec.add_dependency 'ruboty', '>= 1.0.4'
|
19
18
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
21
|
+
spec.add_development_dependency 'rubocop', '~> 0.51'
|
20
22
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'discordrb'
|
4
|
+
require 'ruboty'
|
5
|
+
require 'ruboty/adapters/discord'
|
6
|
+
|
7
|
+
RSpec.describe Ruboty::Adapters::Discord do
|
8
|
+
around do |example|
|
9
|
+
original_discord_token = ENV['DISCORD_TOKEN']
|
10
|
+
ENV['DISCORD_TOKEN'] = 'xxxxxxxxxxxxxxxxxxxx'
|
11
|
+
example.run
|
12
|
+
ENV['DISCORD_TOKEN'] = original_discord_token
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:robot) do
|
16
|
+
Ruboty::Robot.new
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:adapter) do
|
20
|
+
described_class.new(robot)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#run' do
|
24
|
+
# todo
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#say' do
|
28
|
+
before do
|
29
|
+
allow_any_instance_of(Discordrb::Bot).to receive(:send_message) do |_, channel_id, content|
|
30
|
+
channel = OpenStruct.new(id: channel_id)
|
31
|
+
OpenStruct.new(content: content, channel: channel)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:body) { 'content body' }
|
36
|
+
|
37
|
+
let(:code) { false }
|
38
|
+
|
39
|
+
let(:message) do
|
40
|
+
{ body: body, to: 0, code: code }
|
41
|
+
end
|
42
|
+
|
43
|
+
subject do
|
44
|
+
adapter.say(message)
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when code false' do
|
48
|
+
it do
|
49
|
+
expect(subject.content).to eq('content body')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when code true' do
|
54
|
+
let(:code) { true }
|
55
|
+
|
56
|
+
it do
|
57
|
+
expect(subject.content).to eq("```\ncontent body\n```")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-discord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamagishi Kazutoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: discordrb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: ruboty
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,19 +39,19 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: 1.0.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '1.6'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,33 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '3.7'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.51'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.51'
|
69
97
|
description:
|
70
98
|
email:
|
71
99
|
- ykzts@desire.sh
|
@@ -73,7 +101,13 @@ executables: []
|
|
73
101
|
extensions: []
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
104
|
+
- ".editorconfig"
|
105
|
+
- ".github/ISSUE_TEMPLATE.md"
|
76
106
|
- ".gitignore"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- CONTRIBUTING.md
|
77
111
|
- Gemfile
|
78
112
|
- LICENSE
|
79
113
|
- README.md
|
@@ -82,6 +116,8 @@ files:
|
|
82
116
|
- lib/ruboty/discord.rb
|
83
117
|
- lib/ruboty/discord/version.rb
|
84
118
|
- ruboty-discord.gemspec
|
119
|
+
- spec/ruboty/adapters/discord_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
85
121
|
homepage: https://github.com/ykzts/ruboty-discord
|
86
122
|
licenses:
|
87
123
|
- MIT
|
@@ -97,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
133
|
version: '0'
|
98
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
135
|
requirements:
|
100
|
-
- - "
|
136
|
+
- - ">="
|
101
137
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
138
|
+
version: '0'
|
103
139
|
requirements: []
|
104
140
|
rubyforge_project:
|
105
141
|
rubygems_version: 2.6.8
|