ruboty-discord 1.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 28801d31d859af52cc6cca9b7de93fb302072606
4
+ data.tar.gz: 0c44d1e9b24f2e946e9db5456a4b39a723057a44
5
+ SHA512:
6
+ metadata.gz: da4c9752efccab56f85c67e40db9c9091300179722ce00ee78a2d5747c9826f8e53e30021cf6b73debd53ddf33d6bea4a311b3f146919693b6c28a3cdc148b88
7
+ data.tar.gz: b97d247e2f4c26f054fb79b535053b772e2d58b1f40e37fcaa088e3ec7c38bd0b71bf2358c141bc5aaac88e5e2506d58978c0d7b3b733c4ecd24cfb29619631a
@@ -0,0 +1,3 @@
1
+ /.bundle/
2
+ /pkg/
3
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-slack.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Yamagishi Kazutoshi <ykzts@desire.sh>
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # Ruboty::Discord
2
+
3
+ Discord adapter for [Ruboty](https://github.com/r7kamura/ruboty)
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # Gemfile
9
+ gem "ruboty-discord"
10
+ ```
11
+
12
+ ## ENV
13
+
14
+ ```plain
15
+ DISCORD_TOKEN - Account\'s token. get one on https://discordapp.com/developers/applications/me
16
+ ```
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'discordrb'
4
+ require 'ruboty/adapters/base'
5
+
6
+ module Ruboty
7
+ module Adapters
8
+ class Discord < Base
9
+ env :DISCORD_TOKEN, 'Account\'s token. get one on https://discordapp.com/developers/applications/me'
10
+
11
+ def run
12
+ init
13
+ bind
14
+ connect
15
+ end
16
+
17
+ def say(message)
18
+ channel_id = message[:to]
19
+ content = message[:code] ? "```\n#{message[:body]}\n```" : message[:body]
20
+
21
+ bot.send_message(channel_id, content)
22
+ end
23
+
24
+ private
25
+
26
+ def bot
27
+ @bot ||= Discordrb::Bot.new(token: ENV['DISCORD_TOKEN'])
28
+ end
29
+
30
+ def init
31
+ bot.ready do
32
+ ENV['RUBOTY_NAME'] = bot.profile.username
33
+ end
34
+ end
35
+
36
+ def bind
37
+ bot.message do |event|
38
+ on_message(event.message)
39
+ end
40
+ end
41
+
42
+ def connect
43
+ bot.run
44
+ end
45
+
46
+ 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
+ robot.receive(
54
+ body: body,
55
+ from: message.channel.id,
56
+ from_name: message.author.name,
57
+ to: message.channel.id,
58
+ time: message.timestamp
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,2 @@
1
+ require 'ruboty/adapters/discord'
2
+ require 'ruboty/discord/version'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruboty
4
+ module Discord
5
+ VERSION = '1.0.0.beta1'
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'ruboty/discord/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-discord'
8
+ spec.version = Ruboty::Discord::VERSION
9
+ spec.authors = ['Yamagishi Kazutoshi']
10
+ spec.email = ['ykzts@desire.sh']
11
+ spec.summary = 'Discord adapter for Ruboty.'
12
+ spec.homepage = 'https://github.com/ykzts/ruboty-discord'
13
+ spec.license = 'MIT'
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.require_paths = ['lib']
16
+ spec.add_dependency 'ruboty', '>= 1.0.4'
17
+ spec.add_dependency 'discordrb', '~> 3.2'
18
+ spec.add_development_dependency 'rake'
19
+ spec.add_development_dependency 'bundler', '~> 1.6'
20
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-discord
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Yamagishi Kazutoshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: discordrb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description:
70
+ email:
71
+ - ykzts@desire.sh
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/adapters/discord.rb
82
+ - lib/ruboty/discord.rb
83
+ - lib/ruboty/discord/version.rb
84
+ - ruboty-discord.gemspec
85
+ homepage: https://github.com/ykzts/ruboty-discord
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.1
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.8
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Discord adapter for Ruboty.
109
+ test_files: []