lex-discord 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c2180fda409d5270527d754295a8f7a5f7f1c574c3962b93fd42a7839fd30d2
4
+ data.tar.gz: 2d0e75f99cf3fc770aa871a282775a2dbc86d315fe5c0100ce38583865cbf19a
5
+ SHA512:
6
+ metadata.gz: e73a1733989942188446ac7df873ac1b070d322f8221402fc219fe44ca696273374b4531993ae1e355f1b4360d787f7a75aadf96e7a6549f4ff8d529f1d2e8bc
7
+ data.tar.gz: c2d510ee7959651f3d427e4134532c85c3598e83754d9c41a9874d7b19ac1e60ab1052a472c9bf2dc8d917137516e7d863627c69566d81f7650b7694f8411de2
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [origin]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/origin'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 10
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-03-21
4
+
5
+ ### Added
6
+ - Initial release
7
+ - `Helpers::Client` — Faraday connection builder targeting Discord API v10 with Bot token auth
8
+ - `Runners::Messages` — send_message, edit_message, delete_message, get_messages
9
+ - `Runners::Channels` — list_guild_channels, get_channel, create_channel
10
+ - `Runners::Webhooks` — execute_webhook, edit_webhook_message
11
+ - Standalone `Client` class for use outside the Legion framework
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rspec'
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # lex-discord
2
+
3
+ LegionIO extension for Discord integration via the Discord REST API v10.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lex-discord'
11
+ ```
12
+
13
+ ## Standalone Usage
14
+
15
+ ```ruby
16
+ require 'legion/extensions/discord'
17
+
18
+ client = Legion::Extensions::Discord::Client.new(token: 'your-bot-token')
19
+
20
+ # Messages
21
+ client.send_message(channel_id: '123456789', content: 'Hello from Legion!')
22
+ client.get_messages(channel_id: '123456789', limit: 10)
23
+ client.edit_message(channel_id: '123456789', message_id: '987654321', content: 'Updated message')
24
+ client.delete_message(channel_id: '123456789', message_id: '987654321')
25
+
26
+ # Channels
27
+ client.list_guild_channels(guild_id: '111222333')
28
+ client.get_channel(channel_id: '123456789')
29
+ client.create_channel(guild_id: '111222333', name: 'announcements')
30
+
31
+ # Webhooks
32
+ client.execute_webhook(webhook_id: '444555666', webhook_token: 'webhook-token', content: 'Deployed!')
33
+ client.edit_webhook_message(webhook_id: '444555666', webhook_token: 'webhook-token', message_id: '777888999', content: 'Updated')
34
+ ```
35
+
36
+ ## Authentication
37
+
38
+ Discord bot authentication uses a Bot token in the `Authorization` header. Create a bot and obtain its token at: https://discord.com/developers/applications
39
+
40
+ ## License
41
+
42
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/discord/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-discord'
7
+ spec.version = Legion::Extensions::Discord::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX::Discord'
12
+ spec.description = 'Used to connect Legion to Discord'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-discord'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-discord'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-discord/blob/main/CHANGELOG.md'
20
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '>= 2.0'
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers/client'
4
+ require_relative 'runners/messages'
5
+ require_relative 'runners/channels'
6
+ require_relative 'runners/webhooks'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module Discord
11
+ class Client
12
+ include Helpers::Client
13
+ include Runners::Messages
14
+ include Runners::Channels
15
+ include Runners::Webhooks
16
+
17
+ attr_reader :opts
18
+
19
+ def initialize(token:, **extra)
20
+ @opts = { token: token, **extra }
21
+ end
22
+
23
+ def settings
24
+ { options: @opts }
25
+ end
26
+
27
+ def connection(**override)
28
+ super(**@opts, **override)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Discord
8
+ module Helpers
9
+ module Client
10
+ def connection(token: nil, **_opts)
11
+ Faraday.new(url: 'https://discord.com/api/v10') do |conn|
12
+ conn.request :json
13
+ conn.response :json, content_type: /\bjson$/
14
+ conn.headers['Authorization'] = "Bot #{token}" if token
15
+ conn.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Discord
6
+ module Runners
7
+ module Channels
8
+ def list_guild_channels(guild_id:, **)
9
+ resp = connection(**).get("/guilds/#{guild_id}/channels")
10
+ { channels: resp.body }
11
+ end
12
+
13
+ def get_channel(channel_id:, **)
14
+ resp = connection(**).get("/channels/#{channel_id}")
15
+ { channel: resp.body }
16
+ end
17
+
18
+ def create_channel(guild_id:, name:, channel_type: 0, topic: nil, position: nil, **)
19
+ body = { name: name, type: channel_type }
20
+ body[:topic] = topic if topic
21
+ body[:position] = position if position
22
+ resp = connection(**).post("/guilds/#{guild_id}/channels", body)
23
+ { channel: resp.body }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Discord
6
+ module Runners
7
+ module Messages
8
+ def send_message(channel_id:, content:, tts: false, embeds: nil, **)
9
+ body = { content: content, tts: tts }
10
+ body[:embeds] = embeds if embeds
11
+ resp = connection(**).post("/channels/#{channel_id}/messages", body)
12
+ { message: resp.body }
13
+ end
14
+
15
+ def edit_message(channel_id:, message_id:, content: nil, embeds: nil, **)
16
+ body = {}
17
+ body[:content] = content if content
18
+ body[:embeds] = embeds if embeds
19
+ resp = connection(**).patch("/channels/#{channel_id}/messages/#{message_id}", body)
20
+ { message: resp.body }
21
+ end
22
+
23
+ def delete_message(channel_id:, message_id:, **)
24
+ resp = connection(**).delete("/channels/#{channel_id}/messages/#{message_id}")
25
+ { deleted: resp.status == 204, message_id: message_id }
26
+ end
27
+
28
+ def get_messages(channel_id:, limit: 50, before: nil, after: nil, around: nil, **)
29
+ params = { limit: limit }
30
+ params[:before] = before if before
31
+ params[:after] = after if after
32
+ params[:around] = around if around
33
+ resp = connection(**).get("/channels/#{channel_id}/messages", params)
34
+ { messages: resp.body }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Discord
6
+ module Runners
7
+ module Webhooks
8
+ def execute_webhook(webhook_id:, webhook_token:, content: nil, username: nil, avatar_url: nil, embeds: nil, **)
9
+ body = {}
10
+ body[:content] = content if content
11
+ body[:username] = username if username
12
+ body[:avatar_url] = avatar_url if avatar_url
13
+ body[:embeds] = embeds if embeds
14
+ resp = connection(**).post("/webhooks/#{webhook_id}/#{webhook_token}", body)
15
+ { executed: [204, 200].include?(resp.status), response: resp.body }
16
+ end
17
+
18
+ def edit_webhook_message(webhook_id:, webhook_token:, message_id:, content: nil, embeds: nil, **)
19
+ body = {}
20
+ body[:content] = content if content
21
+ body[:embeds] = embeds if embeds
22
+ resp = connection(**).patch("/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}", body)
23
+ { message: resp.body }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Discord
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/discord/version'
4
+ require 'legion/extensions/discord/helpers/client'
5
+ require 'legion/extensions/discord/runners/messages'
6
+ require 'legion/extensions/discord/runners/channels'
7
+ require 'legion/extensions/discord/runners/webhooks'
8
+ require 'legion/extensions/discord/client'
9
+
10
+ module Legion
11
+ module Extensions
12
+ module Discord
13
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-discord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: Used to connect Legion to Discord
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".github/workflows/ci.yml"
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - README.md
40
+ - lex-discord.gemspec
41
+ - lib/legion/extensions/discord.rb
42
+ - lib/legion/extensions/discord/client.rb
43
+ - lib/legion/extensions/discord/helpers/client.rb
44
+ - lib/legion/extensions/discord/runners/channels.rb
45
+ - lib/legion/extensions/discord/runners/messages.rb
46
+ - lib/legion/extensions/discord/runners/webhooks.rb
47
+ - lib/legion/extensions/discord/version.rb
48
+ homepage: https://github.com/LegionIO/lex-discord
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/LegionIO/lex-discord
53
+ source_code_uri: https://github.com/LegionIO/lex-discord
54
+ changelog_uri: https://github.com/LegionIO/lex-discord/blob/main/CHANGELOG.md
55
+ rubygems_mfa_required: 'true'
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.4'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: LEX::Discord
73
+ test_files: []