discorb 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e27fc8b1d9e527f2ce007c686025f4edc9ca7ee8dda06df91ff48a02034a1dbf
4
- data.tar.gz: 7708d124bd2921941164e178c35714b3cf7d68f19b202a823bc9913688c35495
3
+ metadata.gz: 4f5c9c3f2c3e472300d1fe8462b9e667008bce0a30d11b2ce6cf866f697aedb0
4
+ data.tar.gz: d2c2fa2edd51a84a1001675d0572bfae3464f5d25b85865a95a7c7f5daebf109
5
5
  SHA512:
6
- metadata.gz: 8b4d553c7fe030956205058581ed1685a73fcdc1034c250e1c09ca29ef52637d8b85b10bb19edc93d334f0782e7b9a4d4fe4e88976d1f1174286e5f72ca866bb
7
- data.tar.gz: bc6ec15cb5c3592df82e5af2682f690a5ee6649e8a1cf957786bf0886f3b0c3ad76ab6241b606d52380d47b3ccd17f4c7cda71b62b98198ce3470180ec07c753
6
+ metadata.gz: ed4bb639464a3adc7a5982088149421d6d15f7e3c4be37bb59855a5d106ee5a1e1756b10ba401fd3d3ced9008c15e99bb3967f93eb7ff197903fb6cf95e19699
7
+ data.tar.gz: fc6809db6b8e7a7e65e70fb49ce3b25a2aa4f42145477730e234511a95f278879759d76f5ee9547fa213f34ce3c413f5ba167c7f042d7f73a954718ba22e51d4
data/.yardopts CHANGED
@@ -4,5 +4,5 @@
4
4
  --tag flags:"Flags"
5
5
  --verbose
6
6
  -
7
- docs/*.md
7
+ docs/**/*.md
8
8
  Changelog.md
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- discorb (0.2.5)
4
+ discorb (0.3.0)
5
5
  async
6
6
  async-http
7
7
  async-websocket
@@ -34,11 +34,11 @@ GEM
34
34
  fiber-local (1.0.0)
35
35
  mime-types (3.3.1)
36
36
  mime-types-data (~> 3.2015)
37
- mime-types-data (3.2021.0704)
38
- nio4r (2.5.7)
37
+ mime-types-data (3.2021.0901)
38
+ nio4r (2.5.8)
39
39
  protocol-hpack (1.4.2)
40
40
  protocol-http (0.22.5)
41
- protocol-http1 (0.14.1)
41
+ protocol-http1 (0.14.2)
42
42
  protocol-http (~> 0.22)
43
43
  protocol-http2 (0.14.2)
44
44
  protocol-hpack (~> 1.4)
data/docs/cli/init.md ADDED
@@ -0,0 +1,55 @@
1
+ # @title CLI: discorb init
2
+
3
+ # discorb init
4
+
5
+ This command will create a new project in the directory.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ discorb init [options] [dir]
11
+ ```
12
+
13
+ ## Options
14
+
15
+ ### `dir`
16
+
17
+ The directory to create the project in.
18
+ Defaults to the current directory.
19
+ If the directory exists and is not empty, an error is returned.
20
+ You can use `--force` to overwrite an existing directory.
21
+
22
+ ### `--[no-]bundle`
23
+
24
+ Whether to use bundle.
25
+ If true, the command will create Gemfile and execute `bundle install`.
26
+ Default to true.
27
+
28
+ ### `--[no-]git`
29
+
30
+ Whether to initialize git.
31
+ If true, the command will initialize git and commit the initial files with commit message `Initial commit`.
32
+ Use `git commit --amend -m "..."` to change the commit message.
33
+ Default to true.
34
+
35
+ ### `-t`, `--token`
36
+
37
+ The name of token environment variable.
38
+ Default to TOKEN.
39
+
40
+ ### `-f`, `--force`
41
+
42
+ Whether to overwrite an existing directory.
43
+ Default to false.
44
+
45
+ ## File structure
46
+
47
+ The following files will be created:
48
+
49
+ | File | Description |
50
+ | ---- | ----------- |
51
+ | `.env` | Environment variables. |
52
+ | `.gitignore` | Git ignore file. Won't be created if `--git` is false. |
53
+ | `Gemfile` | Gemfile. Won't be created if `--bundle` is false. |
54
+ | `Gemfile.lock` | Gemfile lock file. Won't be created if `--bundle` is false. |
55
+ | `main.rb` | Main script. |
@@ -1,21 +1,19 @@
1
- # @title discord-irb
1
+ # @title CLI: discorb irb
2
2
 
3
- # discord-irb
3
+ # discorb irb
4
4
 
5
- discord-irb is a command line tool for interacting with the Discord API.
5
+ discorb irb is a command line tool for interacting with the Discord API.
6
6
 
7
7
 
8
8
  ## Usage
9
9
 
10
10
  ```
11
- $ bundle exec discord-irb
11
+ discorb irb [options]
12
12
  ```
13
13
 
14
- To start.
15
-
16
14
  ### Load a token
17
15
 
18
- discord-irb will load a token from...
16
+ discorb irb will load a token from...
19
17
  1. the `DISCORD_BOT_TOKEN` environment variable
20
18
  2. the `DISCORD_TOKEN` environment variable
21
19
  3. `token` file in the current directory(customizable with `-t` option)
data/docs/cli.md ADDED
@@ -0,0 +1,20 @@
1
+ # @title CLI tools
2
+
3
+ # CLI tools
4
+
5
+ discorb has a CLI tool for developing.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ bundle exec discorb <command> ...
11
+ ```
12
+
13
+ ## Commands
14
+
15
+ Currently, discorb has the following commands:
16
+
17
+ | Command | Description |
18
+ |---------|-------------|
19
+ | {file:docs/cli/init.md `init`} | Create a new project. |
20
+ | {file:docs/cli/irb.md `irb`} | Start an interactive Ruby shell with connected client. |
data/exe/discorb ADDED
@@ -0,0 +1,28 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ script = ARGV[0]
4
+
5
+ if script.nil?
6
+ puts "\e[94mThis is a tool for discorb. Currently these tools are available:\e[m"
7
+
8
+ discorb_path = $:.find { |path| File.directory?(path + "/discorb") }
9
+ scripts = {}
10
+ Dir.glob(discorb_path + "/discorb/exe/*.rb") do |script|
11
+ name = File.basename(script, ".rb")
12
+ description = File.read(script).match(/# description: (.+)/)&.[](1) || "No description"
13
+ scripts[name] = description
14
+ end
15
+ max_length = scripts.keys.map { |key| key.length }.max
16
+ scripts.sort.each do |name, description|
17
+ puts "\e[90m#{name.rjust(max_length)}\e[m - #{description}"
18
+ end
19
+
20
+ exit 1
21
+ end
22
+
23
+ begin
24
+ require "discorb/exe/#{script}"
25
+ rescue LoadError
26
+ puts "\e[91mThis tool is not available: \e[90m#{script}\e[m"
27
+ exit 1
28
+ end
@@ -279,6 +279,9 @@ module Discorb
279
279
  @new_value = data[:new_value].then(&method)
280
280
  end
281
281
 
282
+ #
283
+ # Send a message to the new value.
284
+ #
282
285
  def method_missing(method, ...)
283
286
  @new_value.__send__(method, ...)
284
287
  end
@@ -4,7 +4,7 @@ module Discorb
4
4
  # @return [String] The API base URL.
5
5
  API_BASE_URL = "https://discord.com/api/v9"
6
6
  # @return [String] The version of discorb.
7
- VERSION = "0.2.5"
7
+ VERSION = "0.3.0"
8
8
  # @return [String] The user agent for the bot.
9
9
  USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
10
10
 
@@ -93,6 +93,9 @@ module Discorb
93
93
  !self[id].nil?
94
94
  end
95
95
 
96
+ #
97
+ # Send a message to the array of values.
98
+ #
96
99
  def method_missing(name, ...)
97
100
  if values.respond_to?(name)
98
101
  values.send(name, ...)
@@ -0,0 +1,185 @@
1
+ # description: Make files for the discorb project.
2
+
3
+ require "optparse"
4
+ require_relative "../utils/colored_puts"
5
+
6
+ $path = Dir.pwd
7
+
8
+ FILES = {
9
+ "main.rb" => <<~'RUBY',
10
+ require "discorb"
11
+ require "dotenv"
12
+
13
+ Dotenv.load
14
+
15
+ client = Discorb::Client.new
16
+
17
+ client.once :ready do
18
+ puts "Logged in as #{client.user}"
19
+ end
20
+
21
+ client.run ENV["%<token>s"]
22
+ RUBY
23
+ ".env" => <<~BASH,
24
+ %<token>s=Y0urB0tT0k3nHer3.Th1sT0ken.W0ntWorkB3c4useItH4sM34n1ng
25
+ BASH
26
+ ".gitignore" => <<~GITIGNORE,
27
+ *.gem
28
+ *.rbc
29
+ /.config
30
+ /coverage/
31
+ /InstalledFiles
32
+ /pkg/
33
+ /spec/reports/
34
+ /spec/examples.txt
35
+ /test/tmp/
36
+ /test/version_tmp/
37
+ /tmp/
38
+
39
+ # Used by dotenv library to load environment variables.
40
+ .env
41
+
42
+ # Ignore Byebug command history file.
43
+ .byebug_history
44
+
45
+ ## Specific to RubyMotion:
46
+ .dat*
47
+ .repl_history
48
+ build/
49
+ *.bridgesupport
50
+ build-iPhoneOS/
51
+ build-iPhoneSimulator/
52
+
53
+ ## Specific to RubyMotion (use of CocoaPods):
54
+ #
55
+ # We recommend against adding the Pods directory to your .gitignore. However
56
+ # you should judge for yourself, the pros and cons are mentioned at:
57
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
58
+ #
59
+ # vendor/Pods/
60
+
61
+ ## Documentation cache and generated files:
62
+ /.yardoc/
63
+ /_yardoc/
64
+ /doc/
65
+ /rdoc/
66
+
67
+ ## Environment normalization:
68
+ /.bundle/
69
+ /vendor/bundle
70
+ /lib/bundler/man/
71
+
72
+ # for a library or gem, you might want to ignore these files since the code is
73
+ # intended to run in multiple environments; otherwise, check them in:
74
+ # Gemfile.lock
75
+ # .ruby-version
76
+ # .ruby-gemset
77
+
78
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
79
+ .rvmrc
80
+
81
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
82
+ # .rubocop-https?--*
83
+
84
+ # This gitignore is from github/gitignore.
85
+ # https://github.com/github/gitignore/blob/master/Ruby.gitignore
86
+ GITIGNORE
87
+ }
88
+
89
+ def make_files
90
+ iputs "Making files..."
91
+ FILES.each do |file, content|
92
+ File.write($path + "/#{file}", format(content, token: $values[:token]), mode: "wb")
93
+ end
94
+ sputs "Made files.\n"
95
+ end
96
+
97
+ def bundle_init
98
+ iputs "Initializing bundle..."
99
+ File.write($path + "/Gemfile", <<~'RUBY', mode: "wb")
100
+ # frozen_string_literal: true
101
+
102
+ source "https://rubygems.org"
103
+
104
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
105
+
106
+ gem "discorb", "~> 0.2.5"
107
+ gem "dotenv", "~> 2.7"
108
+ RUBY
109
+ iputs "Installing gems..."
110
+ system "bundle install"
111
+ sputs "Installed gems.\n"
112
+ end
113
+
114
+ def git_init
115
+ iputs "Initializing git repository..."
116
+ system "git init"
117
+ system "git add ."
118
+ system "git commit -m \"Initial commit\""
119
+ sputs "Initialized repository, use " +
120
+ "\e[32mgit commit --amend -m '...'\e[92m" +
121
+ " to change commit message of initial commit.\n"
122
+ end
123
+
124
+ opt = OptionParser.new <<~BANNER
125
+ A tool to make a new project.
126
+
127
+ Usage: discorb init [options] [dir]
128
+
129
+ dir The directory to make the files in.
130
+ BANNER
131
+
132
+ $values = {
133
+ bundle: true,
134
+ git: true,
135
+ force: false,
136
+ token: "TOKEN",
137
+ }
138
+
139
+ opt.on("--[no-]bundle", "Whether to use bundle. Default to true.") do |v|
140
+ $values[:bundle] = v
141
+ end
142
+
143
+ opt.on("--[no-]git", "Whether to initialize git. Default to true.") do |v|
144
+ $values[:git] = v
145
+ end
146
+
147
+ opt.on("-t NAME", "--token NAME", "The name of token environment variable. Default to TOKEN.") do |v|
148
+ $values[:token] = v
149
+ end
150
+
151
+ opt.on("-f", "--force", "Whether to force use directory. Default to false.") do |v|
152
+ $values[:force] = v
153
+ end
154
+
155
+ ARGV.delete_at(0)
156
+
157
+ opt.parse!(ARGV)
158
+
159
+ if (dir = ARGV[0])
160
+ $path += "/#{dir}"
161
+ if Dir.exist?($path)
162
+ if Dir.empty?($path)
163
+ gputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
164
+ else
165
+ if $values[:force]
166
+ gputs "Found \e[30m#{dir}\e[90m and not empty, but force is on, using this directory."
167
+ else
168
+ eputs "Directory \e[31m#{dir}\e[91m already exists and not empty. Use \e[31m-f\e[91m to force."
169
+ exit
170
+ end
171
+ end
172
+ else
173
+ Dir.mkdir($path)
174
+ gputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
175
+ end
176
+ Dir.chdir($path)
177
+ end
178
+
179
+ bundle_init if $values[:bundle]
180
+
181
+ make_files
182
+
183
+ git_init if $values[:git]
184
+
185
+ sputs "\nSuccessfully made a new project at \e[32m#{$path}\e[92m."
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # description: Connect to discord and start IRB.
4
+
3
5
  require "io/console"
4
6
  require "discorb"
5
7
  require "optparse"
data/lib/discorb/flag.rb CHANGED
@@ -25,6 +25,9 @@ module Discorb
25
25
  end
26
26
  end
27
27
 
28
+ #
29
+ # Returns the value of the flag.
30
+ #
28
31
  def method_missing(name, args = nil)
29
32
  if @values.key?(name.to_s.delete_suffix("?").to_sym)
30
33
  @values[name.to_s.delete_suffix("?").to_sym]
@@ -75,6 +75,9 @@ module Discorb
75
75
  }
76
76
  end
77
77
 
78
+ #
79
+ # (see Flag#method_missing)
80
+ #
78
81
  def method_missing(name, args = nil)
79
82
  if @raw_value.key?(name)
80
83
  @raw_value[name]
@@ -229,6 +229,9 @@ module Discorb
229
229
  end
230
230
  end
231
231
 
232
+ #
233
+ # (see Flag#method_missing)
234
+ #
232
235
  def method_missing(method, bool = nil)
233
236
  if self.class.bits.key?(method)
234
237
  self[method]
@@ -0,0 +1,11 @@
1
+ def sputs(text)
2
+ puts "\e[92m#{text}\e[m"
3
+ end
4
+
5
+ def eputs(text)
6
+ puts "\e[91m#{text}\e[m"
7
+ end
8
+
9
+ def iputs(text)
10
+ puts "\e[90m#{text}\e[m"
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi
@@ -70,7 +70,7 @@ description:
70
70
  email:
71
71
  - sevenc-nanashi@sevenbot.jp
72
72
  executables:
73
- - discord-irb
73
+ - discorb
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
@@ -88,7 +88,9 @@ files:
88
88
  - discorb.gemspec
89
89
  - docs/Examples.md
90
90
  - docs/application_command.md
91
- - docs/discord_irb.md
91
+ - docs/cli.md
92
+ - docs/cli/init.md
93
+ - docs/cli/irb.md
92
94
  - docs/events.md
93
95
  - docs/extension.md
94
96
  - docs/voice_events.md
@@ -103,7 +105,7 @@ files:
103
105
  - examples/simple/ping_pong.rb
104
106
  - examples/simple/rolepanel.rb
105
107
  - examples/simple/wait_for_message.rb
106
- - exe/discord-irb
108
+ - exe/discorb
107
109
  - lib/discorb.rb
108
110
  - lib/discorb/application.rb
109
111
  - lib/discorb/asset.rb
@@ -120,6 +122,8 @@ files:
120
122
  - lib/discorb/emoji_table.rb
121
123
  - lib/discorb/error.rb
122
124
  - lib/discorb/event.rb
125
+ - lib/discorb/exe/init.rb
126
+ - lib/discorb/exe/irb.rb
123
127
  - lib/discorb/extend.rb
124
128
  - lib/discorb/extension.rb
125
129
  - lib/discorb/file.rb
@@ -145,6 +149,7 @@ files:
145
149
  - lib/discorb/sticker.rb
146
150
  - lib/discorb/user.rb
147
151
  - lib/discorb/utils.rb
152
+ - lib/discorb/utils/colored_puts.rb
148
153
  - lib/discorb/voice_state.rb
149
154
  - lib/discorb/webhook.rb
150
155
  - po/yard.pot