discorb 0.8.1 → 0.8.2
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.
- checksums.yaml +4 -4
 - data/Changelog.md +4 -0
 - data/lib/discorb/client.rb +3 -4
 - data/lib/discorb/common.rb +1 -1
 - data/lib/discorb/message.rb +49 -0
 - metadata +1 -3
 - data/.github/workflows/changelog.rb +0 -12
 - data/.github/workflows/release_from_changelog.yml +0 -39
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c3274a015f4e303bb978379e4eb01a039088ce3139507bccf6e32dbcf19dfe29
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4f8b8ca01fcbd9e362ff90bdee7880d11769e0c984687be1e7d5774a9da6a8b5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7eb065d83e4fa92ac82bfd70426e48e04aaca4832dcea9890603e04a349998b48f0d39aac1169a047b73014b88517eae05ab9679c1e55e27286e7b411f6454b2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 77bb4471337fbf056af8a3d3493b84218cb6811745ce28e3a33e4684e72f6806c74045af1a58bf8d7e80532d46cf9fb8caa51587e94c8f96660e5ad9ce10bd6b
         
     | 
    
        data/Changelog.md
    CHANGED
    
    
    
        data/lib/discorb/client.rb
    CHANGED
    
    | 
         @@ -65,13 +65,12 @@ module Discorb 
     | 
|
| 
       65 
65 
     | 
    
         
             
                # @param [Boolean] colorize_log Whether to colorize the log.
         
     | 
| 
       66 
66 
     | 
    
         
             
                # @param [:debug, :info, :warn, :error, :critical] log_level The log level.
         
     | 
| 
       67 
67 
     | 
    
         
             
                # @param [Boolean] wait_until_ready Whether to delay event dispatch until ready.
         
     | 
| 
       68 
     | 
    
         
            -
                # @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client.
         
     | 
| 
       69 
     | 
    
         
            -
                #   Defaultly, it's `false` if {Discorb::Intents#members} is false. Otherwise, it's `true`.
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client. Default to `false`.
         
     | 
| 
       70 
69 
     | 
    
         
             
                #
         
     | 
| 
       71 
70 
     | 
    
         
             
                def initialize(
         
     | 
| 
       72 
71 
     | 
    
         
             
                  allowed_mentions: nil, intents: nil, message_caches: 1000,
         
     | 
| 
       73 
72 
     | 
    
         
             
                  log: nil, colorize_log: false, log_level: :info,
         
     | 
| 
       74 
     | 
    
         
            -
                  wait_until_ready: true, fetch_member:  
     | 
| 
      
 73 
     | 
    
         
            +
                  wait_until_ready: true, fetch_member: false
         
     | 
| 
       75 
74 
     | 
    
         
             
                )
         
     | 
| 
       76 
75 
     | 
    
         
             
                  @allowed_mentions = allowed_mentions || AllowedMentions.new(everyone: true, roles: true, users: true)
         
     | 
| 
       77 
76 
     | 
    
         
             
                  @intents = (intents or Intents.default)
         
     | 
| 
         @@ -94,7 +93,7 @@ module Discorb 
     | 
|
| 
       94 
93 
     | 
    
         
             
                  @commands = []
         
     | 
| 
       95 
94 
     | 
    
         
             
                  @bottom_commands = []
         
     | 
| 
       96 
95 
     | 
    
         
             
                  @status = :initialized
         
     | 
| 
       97 
     | 
    
         
            -
                  @fetch_member = fetch_member 
     | 
| 
      
 96 
     | 
    
         
            +
                  @fetch_member = fetch_member
         
     | 
| 
       98 
97 
     | 
    
         
             
                  set_default_events
         
     | 
| 
       99 
98 
     | 
    
         
             
                end
         
     | 
| 
       100 
99 
     | 
    
         | 
    
        data/lib/discorb/common.rb
    CHANGED
    
    | 
         @@ -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.8. 
     | 
| 
      
 7 
     | 
    
         
            +
              VERSION = "0.8.2"
         
     | 
| 
       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 
     | 
    
         | 
    
        data/lib/discorb/message.rb
    CHANGED
    
    | 
         @@ -213,6 +213,55 @@ module Discorb 
     | 
|
| 
       213 
213 
     | 
    
         
             
                  !@updated_at.nil?
         
     | 
| 
       214 
214 
     | 
    
         
             
                end
         
     | 
| 
       215 
215 
     | 
    
         | 
| 
      
 216 
     | 
    
         
            +
                #
         
     | 
| 
      
 217 
     | 
    
         
            +
                # Removes the mentions from the message.
         
     | 
| 
      
 218 
     | 
    
         
            +
                #
         
     | 
| 
      
 219 
     | 
    
         
            +
                # @param [Boolean] user Whether to clean user mentions.
         
     | 
| 
      
 220 
     | 
    
         
            +
                # @param [Boolean] channel Whether to clean channel mentions.
         
     | 
| 
      
 221 
     | 
    
         
            +
                # @param [Boolean] role Whether to clean role mentions.
         
     | 
| 
      
 222 
     | 
    
         
            +
                # @param [Boolean] emoji Whether to clean emoji.
         
     | 
| 
      
 223 
     | 
    
         
            +
                # @param [Boolean] everyone Whether to clean `@everyone` and `@here`.
         
     | 
| 
      
 224 
     | 
    
         
            +
                # @param [Boolean] codeblock Whether to clean codeblocks.
         
     | 
| 
      
 225 
     | 
    
         
            +
                #
         
     | 
| 
      
 226 
     | 
    
         
            +
                # @return [String] The cleaned content of the message.
         
     | 
| 
      
 227 
     | 
    
         
            +
                #
         
     | 
| 
      
 228 
     | 
    
         
            +
                def clean_content(user: true, channel: true, role: true, emoji: true, everyone: true, codeblock: false)
         
     | 
| 
      
 229 
     | 
    
         
            +
                  ret = @content.dup
         
     | 
| 
      
 230 
     | 
    
         
            +
                  ret.gsub!(/<@!?(\d+)>/) do |match|
         
     | 
| 
      
 231 
     | 
    
         
            +
                    member = guild&.members&.[]($1)
         
     | 
| 
      
 232 
     | 
    
         
            +
                    member ||= @client.users[$1]
         
     | 
| 
      
 233 
     | 
    
         
            +
                    member ? "@#{member.name}" : "@Unknown User"
         
     | 
| 
      
 234 
     | 
    
         
            +
                  end if user
         
     | 
| 
      
 235 
     | 
    
         
            +
                  ret.gsub!(/<#(\d+)>/) do |match|
         
     | 
| 
      
 236 
     | 
    
         
            +
                    channel = @client.channels[$1]
         
     | 
| 
      
 237 
     | 
    
         
            +
                    channel ? "<##{channel.id}>" : "#Unknown Channel"
         
     | 
| 
      
 238 
     | 
    
         
            +
                  end
         
     | 
| 
      
 239 
     | 
    
         
            +
                  ret.gsub!(/<@&(\d+)>/) do |match|
         
     | 
| 
      
 240 
     | 
    
         
            +
                    role = guild&.roles&.[]($1)
         
     | 
| 
      
 241 
     | 
    
         
            +
                    role ? "@#{role.name}" : "@Unknown Role"
         
     | 
| 
      
 242 
     | 
    
         
            +
                  end if role
         
     | 
| 
      
 243 
     | 
    
         
            +
                  ret.gsub!(/<a?:([a-zA-Z0-9_]+):\d+>/) do |match|
         
     | 
| 
      
 244 
     | 
    
         
            +
                    $1
         
     | 
| 
      
 245 
     | 
    
         
            +
                  end if emoji
         
     | 
| 
      
 246 
     | 
    
         
            +
                  ret.gsub!(/@(everyone|here)/, "@\u200b\\1") if everyone
         
     | 
| 
      
 247 
     | 
    
         
            +
                  unless codeblock
         
     | 
| 
      
 248 
     | 
    
         
            +
                    codeblocks = ret.split("```", -1)
         
     | 
| 
      
 249 
     | 
    
         
            +
                    original_codeblocks = @content.scan(/```(.+?)```/m)
         
     | 
| 
      
 250 
     | 
    
         
            +
                    res = []
         
     | 
| 
      
 251 
     | 
    
         
            +
                    max = codeblocks.length
         
     | 
| 
      
 252 
     | 
    
         
            +
                    codeblocks.each_with_index do |codeblock, i|
         
     | 
| 
      
 253 
     | 
    
         
            +
                      if max % 2 == 0 && i == max - 1 or i.even?
         
     | 
| 
      
 254 
     | 
    
         
            +
                        res << codeblock
         
     | 
| 
      
 255 
     | 
    
         
            +
                      else
         
     | 
| 
      
 256 
     | 
    
         
            +
                        res << original_codeblocks[i / 2]
         
     | 
| 
      
 257 
     | 
    
         
            +
                      end
         
     | 
| 
      
 258 
     | 
    
         
            +
                    end
         
     | 
| 
      
 259 
     | 
    
         
            +
                    res.join("```")
         
     | 
| 
      
 260 
     | 
    
         
            +
                  else
         
     | 
| 
      
 261 
     | 
    
         
            +
                    ret
         
     | 
| 
      
 262 
     | 
    
         
            +
                  end
         
     | 
| 
      
 263 
     | 
    
         
            +
                end
         
     | 
| 
      
 264 
     | 
    
         
            +
             
     | 
| 
       216 
265 
     | 
    
         
             
                #
         
     | 
| 
       217 
266 
     | 
    
         
             
                # Edit the message.
         
     | 
| 
       218 
267 
     | 
    
         
             
                #
         
     | 
    
        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.8. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.8.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - sevenc-nanashi
         
     | 
| 
         @@ -79,8 +79,6 @@ files: 
     | 
|
| 
       79 
79 
     | 
    
         
             
            - ".github/ISSUE_TEMPLATE/feature_request.md"
         
     | 
| 
       80 
80 
     | 
    
         
             
            - ".github/workflows/build_main.yml"
         
     | 
| 
       81 
81 
     | 
    
         
             
            - ".github/workflows/build_version.yml"
         
     | 
| 
       82 
     | 
    
         
            -
            - ".github/workflows/changelog.rb"
         
     | 
| 
       83 
     | 
    
         
            -
            - ".github/workflows/release_from_changelog.yml"
         
     | 
| 
       84 
82 
     | 
    
         
             
            - ".gitignore"
         
     | 
| 
       85 
83 
     | 
    
         
             
            - ".yardopts"
         
     | 
| 
       86 
84 
     | 
    
         
             
            - Changelog.md
         
     | 
| 
         @@ -1,12 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            changelog = File.read("./Changelog.md")
         
     | 
| 
       2 
     | 
    
         
            -
            releases = changelog.split("## ")
         
     | 
| 
       3 
     | 
    
         
            -
            releases_hash = releases.map do |release|
         
     | 
| 
       4 
     | 
    
         
            -
              release_name = "v" + release.split("\n")[0]
         
     | 
| 
       5 
     | 
    
         
            -
              release_body = release.split("\n")[1..-1].join("\n").strip
         
     | 
| 
       6 
     | 
    
         
            -
              [release_name, release_body]
         
     | 
| 
       7 
     | 
    
         
            -
            end.to_h
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            release_version = ENV["GITHUB_REF"].split("/")[-1]
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            release_body = releases_hash[release_version] || "No release notes for this version"
         
     | 
| 
       12 
     | 
    
         
            -
            puts "::set-output name=release_body::#{release_body.gsub("\n", "\\n")}"
         
     | 
| 
         @@ -1,39 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            name: Release from changelog
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            on:
         
     | 
| 
       4 
     | 
    
         
            -
              workflow_dispatch:
         
     | 
| 
       5 
     | 
    
         
            -
              push:
         
     | 
| 
       6 
     | 
    
         
            -
                tags: 
         
     | 
| 
       7 
     | 
    
         
            -
                  - "v*"
         
     | 
| 
       8 
     | 
    
         
            -
            jobs:
         
     | 
| 
       9 
     | 
    
         
            -
              main:
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                runs-on: ubuntu-latest
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                steps:
         
     | 
| 
       14 
     | 
    
         
            -
                  - uses: actions/checkout@v2
         
     | 
| 
       15 
     | 
    
         
            -
                    with:
         
     | 
| 
       16 
     | 
    
         
            -
                      fetch-depth: 0
         
     | 
| 
       17 
     | 
    
         
            -
                  - name: Set up Ruby
         
     | 
| 
       18 
     | 
    
         
            -
                    uses: ruby/setup-ruby@v1
         
     | 
| 
       19 
     | 
    
         
            -
                    with:
         
     | 
| 
       20 
     | 
    
         
            -
                      ruby-version: 3.0.2
         
     | 
| 
       21 
     | 
    
         
            -
                      bundler-cache: true
         
     | 
| 
       22 
     | 
    
         
            -
                  - name: Install dependencies
         
     | 
| 
       23 
     | 
    
         
            -
                    run: |
         
     | 
| 
       24 
     | 
    
         
            -
                      bundle install
         
     | 
| 
       25 
     | 
    
         
            -
                  - name: Get changelog
         
     | 
| 
       26 
     | 
    
         
            -
                    run: |
         
     | 
| 
       27 
     | 
    
         
            -
                      bundle exec ruby .github/workflows/changelog.rb
         
     | 
| 
       28 
     | 
    
         
            -
                    id: get-changelog
         
     | 
| 
       29 
     | 
    
         
            -
                  - name: Build gem
         
     | 
| 
       30 
     | 
    
         
            -
                    run: |
         
     | 
| 
       31 
     | 
    
         
            -
                      bundle exec rake build
         
     | 
| 
       32 
     | 
    
         
            -
                  - name: Release
         
     | 
| 
       33 
     | 
    
         
            -
                    uses: softprops/action-gh-release@v1
         
     | 
| 
       34 
     | 
    
         
            -
                    with:
         
     | 
| 
       35 
     | 
    
         
            -
                      files: |
         
     | 
| 
       36 
     | 
    
         
            -
                        $(ls -1 pkg/*.gem)
         
     | 
| 
       37 
     | 
    
         
            -
                      body: ${{ steps.get-changelog.outputs.release_body }}
         
     | 
| 
       38 
     | 
    
         
            -
                    env:
         
     | 
| 
       39 
     | 
    
         
            -
                      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         
     |