discorb 0.13.4 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.github/workflows/build_version.yml +1 -1
  4. data/.github/workflows/codeql-analysis.yml +70 -0
  5. data/.github/workflows/lint-push.yml +20 -0
  6. data/.github/workflows/lint.yml +16 -0
  7. data/.rubocop.yml +74 -0
  8. data/Changelog.md +30 -0
  9. data/Gemfile +7 -3
  10. data/Rakefile +28 -22
  11. data/discorb.gemspec +1 -0
  12. data/docs/events.md +50 -0
  13. data/docs/faq.md +8 -8
  14. data/examples/commands/bookmarker.rb +2 -1
  15. data/examples/commands/hello.rb +1 -0
  16. data/examples/commands/inspect.rb +3 -2
  17. data/examples/components/authorization_button.rb +2 -1
  18. data/examples/components/select_menu.rb +2 -1
  19. data/examples/extension/main.rb +1 -0
  20. data/examples/extension/message_expander.rb +1 -0
  21. data/examples/simple/eval.rb +3 -2
  22. data/examples/simple/ping_pong.rb +1 -0
  23. data/examples/simple/rolepanel.rb +1 -0
  24. data/examples/simple/wait_for_message.rb +4 -3
  25. data/exe/discorb +8 -7
  26. data/lib/discorb/allowed_mentions.rb +71 -0
  27. data/lib/discorb/app_command/command.rb +336 -0
  28. data/lib/discorb/app_command/handler.rb +168 -0
  29. data/lib/discorb/app_command.rb +2 -426
  30. data/lib/discorb/application.rb +16 -7
  31. data/lib/discorb/asset.rb +11 -0
  32. data/lib/discorb/{file.rb → attachment.rb} +55 -33
  33. data/lib/discorb/audit_logs.rb +45 -7
  34. data/lib/discorb/channel.rb +65 -15
  35. data/lib/discorb/client.rb +34 -27
  36. data/lib/discorb/common.rb +19 -27
  37. data/lib/discorb/components/button.rb +105 -0
  38. data/lib/discorb/components/select_menu.rb +143 -0
  39. data/lib/discorb/components/text_input.rb +96 -0
  40. data/lib/discorb/components.rb +11 -276
  41. data/lib/discorb/dictionary.rb +5 -0
  42. data/lib/discorb/embed.rb +73 -40
  43. data/lib/discorb/emoji.rb +48 -5
  44. data/lib/discorb/error.rb +9 -5
  45. data/lib/discorb/event.rb +36 -24
  46. data/lib/discorb/exe/about.rb +1 -0
  47. data/lib/discorb/exe/irb.rb +4 -3
  48. data/lib/discorb/exe/new.rb +6 -7
  49. data/lib/discorb/exe/run.rb +2 -1
  50. data/lib/discorb/exe/setup.rb +8 -5
  51. data/lib/discorb/exe/show.rb +1 -0
  52. data/lib/discorb/extend.rb +19 -14
  53. data/lib/discorb/extension.rb +5 -1
  54. data/lib/discorb/gateway.rb +112 -51
  55. data/lib/discorb/gateway_requests.rb +4 -7
  56. data/lib/discorb/guild.rb +73 -41
  57. data/lib/discorb/guild_template.rb +26 -5
  58. data/lib/discorb/http.rb +38 -18
  59. data/lib/discorb/integration.rb +24 -9
  60. data/lib/discorb/intents.rb +16 -11
  61. data/lib/discorb/interaction/autocomplete.rb +6 -5
  62. data/lib/discorb/interaction/command.rb +66 -12
  63. data/lib/discorb/interaction/components.rb +19 -3
  64. data/lib/discorb/interaction/modal.rb +33 -0
  65. data/lib/discorb/interaction/response.rb +45 -4
  66. data/lib/discorb/interaction/root.rb +16 -0
  67. data/lib/discorb/interaction.rb +2 -1
  68. data/lib/discorb/invite.rb +11 -7
  69. data/lib/discorb/log.rb +5 -5
  70. data/lib/discorb/member.rb +22 -3
  71. data/lib/discorb/message.rb +39 -234
  72. data/lib/discorb/message_meta.rb +186 -0
  73. data/lib/discorb/modules.rb +39 -15
  74. data/lib/discorb/permission.rb +16 -7
  75. data/lib/discorb/presence.rb +45 -9
  76. data/lib/discorb/rate_limit.rb +7 -4
  77. data/lib/discorb/reaction.rb +6 -0
  78. data/lib/discorb/role.rb +12 -0
  79. data/lib/discorb/sticker.rb +22 -14
  80. data/lib/discorb/user.rb +12 -1
  81. data/lib/discorb/utils/colored_puts.rb +1 -0
  82. data/lib/discorb/voice_state.rb +23 -2
  83. data/lib/discorb/webhook.rb +54 -3
  84. data/lib/discorb.rb +5 -2
  85. data/sig/discorb.rbs +838 -702
  86. data/template-replace/scripts/arrow.rb +1 -0
  87. data/template-replace/scripts/favicon.rb +1 -0
  88. data/template-replace/scripts/index.rb +2 -1
  89. data/template-replace/scripts/locale_ja.rb +5 -4
  90. data/template-replace/scripts/sidebar.rb +1 -0
  91. data/template-replace/scripts/version.rb +7 -10
  92. data/template-replace/scripts/yard_replace.rb +5 -4
  93. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45868a2fa9284bc0910bdad465983c490f44b721ccc49632df681e79e78fd727
4
- data.tar.gz: 969d627479e5381da98e1775186e23f9a193244180135b8dc9396878a425ee43
3
+ metadata.gz: 4bc9c7d6433e9e093a0d58d821ed97e3f001d63224c9f65eb1693a2ee3d16f7d
4
+ data.tar.gz: daff87553c1996cbc1a68765ee3df54947f46b7660fc1a16f0a17a0e0660e2c7
5
5
  SHA512:
6
- metadata.gz: 2732b467bfc1ba6af2d6938b384026e5219bfce03ff646669870e311601ec7b0258a72ba1c4b6fd6c9a60d1c3186c3890842916bb2f387542cf1d2ee7fbafab3
7
- data.tar.gz: a825f0d8497f8f62c024fa381441d9a19da54b0aa2fe71a7b87fc6ef17bc74f7e65a1681b6dc9c7abb1a2f746e6d821abaf4ae28ae6d9661226e7276dce2f551
6
+ metadata.gz: dceaba51436368feeb9e99bc4afda5cea9ac45aa0525bb44cdd33c427fef6c6617d17bf1a56b27acac137df05b4d6f27395e22883ce574e4e48d3e7a8ca05a13
7
+ data.tar.gz: 81622ca789eee2f8c55b4fd98e7c0bdc602d164247602508c8b041757d61fcb77f659d01142db8a8c16b9dd6e6cc402ebf9f45cf881e787a77449ba4831b8376
data/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ template-replace/**/* linguist-documentation
2
+ sig/* linguist-generated
@@ -33,7 +33,7 @@ jobs:
33
33
  git clone git@github.com:discorb-lib/discorb-lib.github.io /tmp/pages
34
34
  - name: Install dependencies
35
35
  run: |
36
- bundle config --local with 'docs development'
36
+ bundle config --local with 'docs development lint'
37
37
  bundle install
38
38
  gem update uri
39
39
  - name: Generate document
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ main ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ main ]
20
+ schedule:
21
+ - cron: '20 10 * * 3'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v2
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v1
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v1
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v1
@@ -0,0 +1,20 @@
1
+ name: Lint with RuboCop
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ jobs:
7
+ rubocop:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Checkout repository
11
+ uses: actions/checkout@v2
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 3.0.0
15
+ - name: Install gems
16
+ run: |
17
+ gem install rubocop
18
+ - name: Run rubocop
19
+ run: |
20
+ rubocop lib
@@ -0,0 +1,16 @@
1
+ name: Lint with RuboCop
2
+ on:
3
+ - pull_request
4
+ jobs:
5
+ rubocop:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout repository
9
+ uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: 3.0.0
13
+ - name: rubocop
14
+ uses: reviewdog/action-rubocop@v2
15
+ with:
16
+ rubocop_version: 1.25
data/.rubocop.yml ADDED
@@ -0,0 +1,74 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.0
4
+ Exclude:
5
+ - examples/**/*.rb
6
+
7
+ Layout:
8
+ Enabled: false
9
+ Metrics:
10
+ Enabled: false
11
+
12
+ Style/TrailingCommaInHashLiteral: # Disabled for rufo
13
+ EnforcedStyleForMultiline: consistent_comma
14
+
15
+ Style/TrailingCommaInArrayLiteral: # Disabled for rufo
16
+ EnforcedStyleForMultiline: consistent_comma
17
+
18
+ Style/StringLiterals: # Disabled for rufo
19
+ Enabled: true
20
+ EnforcedStyle: double_quotes
21
+
22
+ Style/TrailingCommaInArguments: # Disabled for rufo
23
+ Enabled: false
24
+
25
+ Style/StringLiteralsInInterpolation: # Disabled for rufo
26
+ Enabled: false
27
+
28
+ Style/StringConcatenation: # + looks better
29
+ Enabled: false
30
+
31
+ Lint/MissingSuper: # For abstract classes
32
+ Enabled: false
33
+
34
+ Lint/AssignmentInCondition: # Looks bad
35
+ Enabled: false
36
+
37
+ Style/PerlBackrefs: # It will be longer
38
+ Enabled: false
39
+
40
+ Style/RedundantSelf: # Looks local variable
41
+ Enabled: false
42
+
43
+ Naming/VariableNumber: # Discord API docs naming
44
+ Enabled: false
45
+
46
+ Style/ParallelAssignment: # It will be longer
47
+ Enabled: false
48
+
49
+ Style/RedundantInterpolation: # For make it extendable
50
+ Enabled: false
51
+
52
+ Style/Next: # For make it extendable
53
+ Enabled: false
54
+
55
+ Lint/ShadowedException: # False positive
56
+ Enabled: false
57
+
58
+ Lint/AmbiguousOperatorPrecedence: # Not needed
59
+ Enabled: false
60
+
61
+ Style/GlobalVars: # For /exe
62
+ Enabled: false
63
+
64
+ Lint/Debugger: # For /exe
65
+ Enabled: false
66
+
67
+ Style/GuardClause: # For make it extendable
68
+ Enabled: false
69
+
70
+ Layout/EndOfLine: # For git
71
+ EnforcedStyle: lf
72
+
73
+ Lint/ScriptPermission: # For GitHub Actions
74
+ Enabled: false
data/Changelog.md CHANGED
@@ -4,6 +4,36 @@
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## v0.15
8
+
9
+ ### v0.15.1
10
+
11
+ - Add: Add `Member#can_manage?`
12
+ - Add: Add `Discorb::VERSION_ARRAY`
13
+ - Fix: `Snowflake#timestamp` includes milliseconds now
14
+ - Fix: `TextChannel#create_invite` will no longer return `ArgumentError`
15
+ - Fix: Connection will not closed with 4001 when `Client#update_presence`
16
+ is called
17
+
18
+ ### v0.15.0
19
+
20
+ - Add: Migrate to API v10
21
+ - Add: Add `TextChannel#threads`
22
+ - Add: Support editing attachments
23
+ - Delete!: Delete File class - Use Attachment class instead
24
+
25
+ ## v0.14
26
+
27
+ ### v0.14.0
28
+
29
+ - Add: Support Modal interaction
30
+ - Add: Support attachment option type in slash command
31
+ - Fix: Connections will no longer stacked
32
+ - Fix: Fix Client#fetch_nitro_sticker_packs returning 404
33
+ - Fix: Fix `self` reference in subcommand of extension
34
+ - Refactor: Refactored many things
35
+ - Refactor: Add Rubocop
36
+
7
37
  ## v0.13
8
38
 
9
39
  ### v0.13.4
data/Gemfile CHANGED
@@ -13,9 +13,13 @@ group :development, optional: true do
13
13
  end
14
14
 
15
15
  group :docs, optional: true do
16
- gem "redcarpet"
17
- gem "yard", "~> 0.9.26"
18
- gem "gettext", "~> 3.4.1"
19
16
  gem "crowdin-api", "~> 1.0"
17
+ gem "gettext", "~> 3.4.1"
18
+ gem "redcarpet"
20
19
  gem "rubyzip", "~> 2.3"
20
+ gem "yard", "~> 0.9.26"
21
+ end
22
+
23
+ group :lint, optional: true do
24
+ gem "rubocop", "~> 1.25"
21
25
  end
data/Rakefile CHANGED
@@ -5,15 +5,14 @@ require_relative "lib/discorb/utils/colored_puts"
5
5
  task default: %i[]
6
6
 
7
7
  # @private
8
- def get_version
8
+ def current_version
9
9
  require_relative "lib/discorb/common"
10
10
  tag = `git tag --points-at HEAD`.force_encoding("utf-8").strip
11
11
  if tag.empty?
12
- version = "main"
12
+ "main"
13
13
  else
14
- version = Discorb::VERSION
14
+ Discorb::VERSION
15
15
  end
16
- version
17
16
  end
18
17
 
19
18
  desc "Build emoji_table.rb"
@@ -63,8 +62,7 @@ end
63
62
 
64
63
  desc "Generate document and replace"
65
64
  namespace :document do
66
- version = get_version
67
-
65
+ version = current_version
68
66
  desc "Just generate document"
69
67
  task :yard do
70
68
  sh "bundle exec yardoc -o doc/#{version} --locale #{ENV["rake_locale"] or "en"}"
@@ -86,12 +84,12 @@ namespace :document do
86
84
 
87
85
  desc "Replace HTML"
88
86
  task :html do
89
- require_relative "template-replace/scripts/sidebar.rb"
90
- require_relative "template-replace/scripts/version.rb"
91
- require_relative "template-replace/scripts/index.rb"
92
- require_relative "template-replace/scripts/yard_replace.rb"
93
- require_relative "template-replace/scripts/favicon.rb"
94
- require_relative "template-replace/scripts/arrow.rb"
87
+ require_relative "template-replace/scripts/sidebar"
88
+ require_relative "template-replace/scripts/version"
89
+ require_relative "template-replace/scripts/index"
90
+ require_relative "template-replace/scripts/yard_replace"
91
+ require_relative "template-replace/scripts/favicon"
92
+ require_relative "template-replace/scripts/arrow"
95
93
  iputs "Resetting changes"
96
94
  Dir.glob("doc/#{version}/**/*.html") do |f|
97
95
  next if (m = f.match(/[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?/)) && m[0] != version
@@ -143,20 +141,18 @@ namespace :document do
143
141
  replace_locale("doc/main")
144
142
  end
145
143
  end
146
- task :replace => %i[replace:css replace:html replace:eol]
144
+ task replace: %i[replace:css replace:html replace:eol]
147
145
 
148
146
  desc "Build all versions"
149
147
  task :build_all do
150
148
  require "fileutils"
151
149
 
152
- class Bundler::Definition
153
- def validate_platforms!
154
- # noop
155
- end
156
- end
157
-
158
150
  iputs "Building all versions"
159
- FileUtils.rm_rf("doc") rescue nil
151
+ begin
152
+ FileUtils.rm_rf("doc")
153
+ rescue StandardError
154
+ nil
155
+ end
160
156
  FileUtils.cp_r("./template-replace/.", "./tmp-template-replace")
161
157
  Rake::Task["document:yard"].execute
162
158
  Rake::Task["document:replace:html"].execute
@@ -181,7 +177,7 @@ namespace :document do
181
177
  FileUtils.cp_r("./tmp-doc/.", "./doc")
182
178
  FileUtils.cp_r("./doc/#{tags.last.delete_prefix("v")}/.", "./doc")
183
179
  sputs "Successfully built all versions"
184
- rescue => e
180
+ rescue StandardError => e
185
181
  sh "git switch main -f"
186
182
  raise e
187
183
  end
@@ -322,4 +318,14 @@ task :rbs do
322
318
  File.write("sig/discorb.rbs", base)
323
319
  end
324
320
 
325
- task :document => %i[document:yard document:replace]
321
+ task document: %i[document:yard document:replace]
322
+
323
+ desc "Lint code with rubocop"
324
+ task :lint do
325
+ sh "rubocop lib"
326
+ end
327
+
328
+ desc "Autofix code with rubocop"
329
+ task "lint:fix" do
330
+ sh "rubocop lib -A"
331
+ end
data/discorb.gemspec CHANGED
@@ -46,4 +46,5 @@ Gem::Specification.new do |spec|
46
46
  spec.add_dependency "mime-types", "~> 3.3"
47
47
  # For more information and examples about making a new gem, checkout our
48
48
  # guide at: https://bundler.io/guides/creating_gem.html
49
+ spec.metadata["rubygems_mfa_required"] = "true"
49
50
  end
data/docs/events.md CHANGED
@@ -487,6 +487,46 @@ Fires when an invitation is deleted.
487
487
 
488
488
  ### Interaction events
489
489
 
490
+ #### `interaction_create(interaction)`
491
+
492
+ Fires when an interaction is created. This will fire for all interactions.
493
+
494
+ | Parameter | Type | Description |
495
+ | ---------- | ----- | ----------- |
496
+ | `interaction` | {Discorb::Interaction}| The created interaction. |
497
+
498
+ #### `application_command(interaction)`
499
+
500
+ Fires when an application command is used.
501
+
502
+ | Parameter | Type | Description |
503
+ | ---------- | ----- | ----------- |
504
+ | `interaction` | {Discorb::CommandInteraction}| The created interaction. |
505
+
506
+ #### `slash_command(interaction)`
507
+
508
+ Fires when a slash command is used.
509
+
510
+ | Parameter | Type | Description |
511
+ | ---------- | ----- | ----------- |
512
+ | `interaction` | {Discorb::CommandInteraction::SlashCommand}| The created interaction. |
513
+
514
+ #### `message_command(interaction)`
515
+
516
+ Fires when a message command is used.
517
+
518
+ | Parameter | Type | Description |
519
+ | ---------- | ----- | ----------- |
520
+ | `interaction` | {Discorb::CommandInteraction::MessageMenuCommand}| The created interaction. |
521
+
522
+ #### `user_command(interaction)`
523
+
524
+ Fires when a user command is used.
525
+
526
+ | Parameter | Type | Description |
527
+ | ---------- | ----- | ----------- |
528
+ | `interaction` | {Discorb::CommandInteraction::UserMenuCommand}| The created interaction. |
529
+
490
530
  #### `button_click(interaction)`
491
531
 
492
532
  Fires when a button is clicked.
@@ -503,6 +543,16 @@ Fires when a select menu is selected.
503
543
  | ---------- | ----- | ----------- |
504
544
  |`interaction`| {Discorb::MessageComponentInteraction::SelectMenu}| The interaction object. |
505
545
 
546
+ #### `form_submit(interaction)`
547
+
548
+ Fires when a form is submitted.
549
+
550
+ | Parameter | Type | Description |
551
+ | ---------- | ----- | ----------- |
552
+ | `interaction` | {Discorb::ModalInteraction} | The interaction object. |
553
+
554
+ #### `slash_command
555
+
506
556
  ### Voice events
507
557
 
508
558
  Because it's big, it's documented in {file:docs/voice_events.md}.
data/docs/faq.md CHANGED
@@ -62,19 +62,19 @@ client.on :ready do
62
62
  end
63
63
  ```
64
64
 
65
- ### How can I send files?
65
+ ### How can I send attachments?
66
66
 
67
- Use {Discorb::File} class.
67
+ Use {Discorb::Attachment} class.
68
68
 
69
69
  ```ruby
70
- # Send a file
71
- message.channel.post file: Discorb::File.new(File.open("./README.md"))
70
+ # Send an attachment
71
+ message.channel.post attachment: Discorb::Attachment.new(File.open("./README.md"))
72
72
 
73
- # Send some files with text
74
- message.channel.post "File!", files: [Discorb::File.new(File.open("./README.md")), Discorb::File.new(File.open("./License.txt"))]
73
+ # Send some attachment with text
74
+ message.channel.post "File!", attachments: [Discorb::Attachment.new("./README.md"), Discorb::Attachment.new(File.open("./License.txt"))]
75
75
 
76
- # Send a string as a file
77
- message.channel.post file: Discorb::File.from_string("Hello world!", "hello.txt")
76
+ # Send a string as an attachment
77
+ message.channel.post attachments: Discorb::Attachment.from_string("Hello world!", "hello.txt")
78
78
  ```
79
79
 
80
80
  ### How can I add reactions?
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
  require "json"
3
4
 
@@ -20,7 +21,7 @@ def build_embed_from_message(message)
20
21
  embed
21
22
  end
22
23
 
23
- client.message_command("Bookmark", guild_ids: [857373681096327180]) do |interaction, message|
24
+ client.message_command("Bookmark", guild_ids: [857_373_681_096_327_180]) do |interaction, message|
24
25
  unless channel = bookmark_channel(interaction.guild)
25
26
  interaction.post("Bookmark channel not found. Please create one called `bookmarks`.", ephemeral: true)
26
27
  next
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -6,7 +7,7 @@ client.once :standby do
6
7
  puts "Logged in as #{client.user}"
7
8
  end
8
9
 
9
- client.user_command("Info", guild_ids: [857373681096327180]) do |interaction|
10
+ client.user_command("Info", guild_ids: [857_373_681_096_327_180]) do |interaction|
10
11
  interaction.post(embed: Discorb::Embed.new(
11
12
  "Information of #{interaction.target.to_s_user}",
12
13
  fields: [
@@ -14,7 +15,7 @@ client.user_command("Info", guild_ids: [857373681096327180]) do |interaction|
14
15
  Discorb::Embed::Field.new("ID", interaction.target.id),
15
16
  Discorb::Embed::Field.new("Bot", interaction.target.bot? ? "Yes" : "No"),
16
17
  Discorb::Embed::Field.new("Joined at", interaction.target.joined_at.to_df("F")),
17
- Discorb::Embed::Field.new("Created at", interaction.target.created_at.to_df("F")),
18
+ Discorb::Embed::Field.new("Created at", interaction.target.created_at.to_df("F"))
18
19
  ],
19
20
  thumbnail: interaction.target.avatar&.url,
20
21
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -27,7 +28,7 @@ client.on :message do |message|
27
28
  components: [
28
29
  Discorb::Button.new(
29
30
  "Get role", custom_id: "auth:#{role.id}",
30
- ),
31
+ )
31
32
  ],
32
33
  )
33
34
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -21,7 +22,7 @@ SECTIONS = [
21
22
  > So I decided to make it.
22
23
  Matsumoto describes the design of Ruby as being like a simple Lisp language at its core, with an object system like that of Smalltalk, blocks inspired by higher-order functions, and practical utility like that of Perl.
23
24
  WIKI
24
- ["First publication", <<~WIKI],
25
+ ["First publication", <<~WIKI]
25
26
  The first public release of Ruby 0.95 was announced on Japanese domestic newsgroups on December 21, 1995.
26
27
  Subsequently, three more versions of Ruby were released in two days.
27
28
  The release coincided with the launch of the Japanese-language ruby-list mailing list, which was the first mailing list for the new language.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
  require_relative "message_expander"
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  class MessageExpander
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -24,8 +25,8 @@ client.on :message do |message|
24
25
  res = res.wait if res.is_a? Async::Task
25
26
  message.channel.post("```rb\n#{res.inspect[...1990]}\n```")
26
27
  end
27
- rescue Exception => error
28
- message.reply embed: Discorb::Embed.new("Error!", "```rb\n#{error.full_message(highlight: false)[...1990]}\n```",
28
+ rescue Exception => e
29
+ message.reply embed: Discorb::Embed.new("Error!", "```rb\n#{e.full_message(highlight: false)[...1990]}\n```",
29
30
  color: Discorb::Color[:red])
30
31
  end
31
32
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
  intents = Discorb::Intents.new
3
4
  intents.members = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "discorb"
2
3
 
3
4
  client = Discorb::Client.new
@@ -10,16 +11,16 @@ client.on :message do |message|
10
11
  next if message.author.bot?
11
12
  next unless message.content == "!quiz"
12
13
 
13
- operator = [:+, :-, :*].sample
14
+ operator = %i[+ - *].sample
14
15
  num1 = rand(1..10)
15
16
  num2 = rand(1..10)
16
17
 
17
18
  val = num1.send(operator, num2)
18
19
  message.channel.post("Quiz: `#{num1} #{operator} #{num2}`")
19
20
  begin
20
- msg = client.event_lock(:message, 30) { |m|
21
+ msg = client.event_lock(:message, 30) do |m|
21
22
  m.content == val.to_s && m.channel == message.channel
22
- }.wait
23
+ end.wait
23
24
  rescue Discorb::TimeoutError
24
25
  message.channel.post("No one answered...")
25
26
  else
data/exe/discorb CHANGED
@@ -1,24 +1,25 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  script = ARGV[0]
4
5
 
5
6
  if script.nil?
6
7
  puts "\e[94mThis is a tool for discorb. Currently these tools are available:\e[m"
7
8
 
8
- discorb_path = $:.find { |path| File.directory?(path + "/discorb") }
9
+ discorb_path = $LOAD_PATH.find { |path| File.directory?(path + "/discorb") }
9
10
  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"
11
+ Dir.glob(discorb_path + "/discorb/exe/*.rb") do |exe_script|
12
+ name = File.basename(exe_script, ".rb")
13
+ description = File.read(exe_script).match(/# description: (.+)/)&.[](1) || "No description"
13
14
  scripts[name] = description
14
15
  end
15
- max_length = scripts.keys.map { |key| key.length }.max
16
+ max_length = scripts.keys.map(&:length).max
16
17
  scripts.sort.each do |name, description|
17
18
  puts "\e[90m#{name.rjust(max_length)}\e[m - #{description}"
18
19
  end
19
20
 
20
- puts "\e[94m\nTo run a tool, type:\e[m\n" +
21
- "\e[34m discorb [script]\e[m"
21
+ puts "\e[94m\nTo run a tool, type:\e[m\n" \
22
+ "\e[34m discorb [script]\e[m"
22
23
 
23
24
  exit 1
24
25
  end