burroughs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 41b1d09a717f6c1e14cb4ac30fcea0ae131b1cdd9303d6ee60dcaf33bcb675c9
4
+ data.tar.gz: 3092fa7fcf632ef316c472a1626f1bd025e1fab36899825b29f7c956e68f1f0a
5
+ SHA512:
6
+ metadata.gz: 6d4eb3978fe044ab3fb6f4c7c80e1040594615861d7fb48dc9d22c2be762fdc92f89d27615d15ded3b46307fe33c87e6ae2b17c9ded2312d4ced2b77ea2675b9
7
+ data.tar.gz: 591b6c8938244fe0fe39b1d46a123315f064f8101ccfc00d7cb77a93a780002a81ca827a2c9769aa3c895eecbb446cec0a9787c68add30c2c0b33748c4d18a4f
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in burroughs.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "pry-byebug", group: %i[development test]
15
+ gem "solargraph", group: %i[development test]
16
+
17
+ gem "activerecord", "~> 7.0"
18
+ gem "discordrb", github: "pinecat/discordrb", ref: "4639880" # afcf50e0
19
+ gem "httparty", "~> 0.21"
20
+
21
+ # gem "discordrb", github: "shardlab/discordrb", branch: "main" # tag: "v3.4.1" # branch: "main"
data/Gemfile.lock ADDED
@@ -0,0 +1,165 @@
1
+ GIT
2
+ remote: https://github.com/pinecat/discordrb.git
3
+ revision: 4639880cd326dcc7e39816de29294c952502dcdb
4
+ ref: 4639880
5
+ specs:
6
+ discordrb (3.4.2)
7
+ discordrb-webhooks (~> 3.4.2)
8
+ ffi (>= 1.9.24)
9
+ opus-ruby
10
+ rest-client (>= 2.0.0)
11
+ websocket-client-simple (>= 0.3.0)
12
+ discordrb-webhooks (3.4.2)
13
+ rest-client (>= 2.0.0)
14
+
15
+ PATH
16
+ remote: .
17
+ specs:
18
+ burroughs (0.1.0)
19
+
20
+ GEM
21
+ remote: https://rubygems.org/
22
+ specs:
23
+ activemodel (7.0.4.3)
24
+ activesupport (= 7.0.4.3)
25
+ activerecord (7.0.4.3)
26
+ activemodel (= 7.0.4.3)
27
+ activesupport (= 7.0.4.3)
28
+ activesupport (7.0.4.3)
29
+ concurrent-ruby (~> 1.0, >= 1.0.2)
30
+ i18n (>= 1.6, < 2)
31
+ minitest (>= 5.1)
32
+ tzinfo (~> 2.0)
33
+ ast (2.4.2)
34
+ backport (1.2.0)
35
+ benchmark (0.2.1)
36
+ byebug (11.1.3)
37
+ coderay (1.1.3)
38
+ concurrent-ruby (1.2.2)
39
+ diff-lcs (1.5.0)
40
+ domain_name (0.5.20190701)
41
+ unf (>= 0.0.5, < 1.0.0)
42
+ e2mmap (0.1.0)
43
+ event_emitter (0.2.6)
44
+ ffi (1.15.5)
45
+ http-accept (1.7.0)
46
+ http-cookie (1.0.5)
47
+ domain_name (~> 0.5)
48
+ httparty (0.21.0)
49
+ mini_mime (>= 1.0.0)
50
+ multi_xml (>= 0.5.2)
51
+ i18n (1.14.0)
52
+ concurrent-ruby (~> 1.0)
53
+ jaro_winkler (1.5.6)
54
+ json (2.6.3)
55
+ kramdown (2.4.0)
56
+ rexml
57
+ kramdown-parser-gfm (1.1.0)
58
+ kramdown (~> 2.0)
59
+ method_source (1.0.0)
60
+ mime-types (3.4.1)
61
+ mime-types-data (~> 3.2015)
62
+ mime-types-data (3.2023.0218.1)
63
+ mini_mime (1.1.2)
64
+ minitest (5.18.0)
65
+ multi_xml (0.6.0)
66
+ netrc (0.11.0)
67
+ nokogiri (1.15.2-x86_64-darwin)
68
+ racc (~> 1.4)
69
+ opus-ruby (1.0.1)
70
+ ffi
71
+ parallel (1.23.0)
72
+ parser (3.2.2.3)
73
+ ast (~> 2.4.1)
74
+ racc
75
+ pry (0.14.2)
76
+ coderay (~> 1.1)
77
+ method_source (~> 1.0)
78
+ pry-byebug (3.10.1)
79
+ byebug (~> 11.0)
80
+ pry (>= 0.13, < 0.15)
81
+ racc (1.7.1)
82
+ rainbow (3.1.1)
83
+ rake (13.0.6)
84
+ rbs (2.8.4)
85
+ regexp_parser (2.8.1)
86
+ rest-client (2.1.0)
87
+ http-accept (>= 1.7.0, < 2.0)
88
+ http-cookie (>= 1.0.2, < 2.0)
89
+ mime-types (>= 1.16, < 4.0)
90
+ netrc (~> 0.8)
91
+ reverse_markdown (2.1.1)
92
+ nokogiri
93
+ rexml (3.2.5)
94
+ rspec (3.12.0)
95
+ rspec-core (~> 3.12.0)
96
+ rspec-expectations (~> 3.12.0)
97
+ rspec-mocks (~> 3.12.0)
98
+ rspec-core (3.12.2)
99
+ rspec-support (~> 3.12.0)
100
+ rspec-expectations (3.12.3)
101
+ diff-lcs (>= 1.2.0, < 2.0)
102
+ rspec-support (~> 3.12.0)
103
+ rspec-mocks (3.12.5)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.12.0)
106
+ rspec-support (3.12.0)
107
+ rubocop (1.52.1)
108
+ json (~> 2.3)
109
+ parallel (~> 1.10)
110
+ parser (>= 3.2.2.3)
111
+ rainbow (>= 2.2.2, < 4.0)
112
+ regexp_parser (>= 1.8, < 3.0)
113
+ rexml (>= 3.2.5, < 4.0)
114
+ rubocop-ast (>= 1.28.0, < 2.0)
115
+ ruby-progressbar (~> 1.7)
116
+ unicode-display_width (>= 2.4.0, < 3.0)
117
+ rubocop-ast (1.29.0)
118
+ parser (>= 3.2.1.0)
119
+ ruby-progressbar (1.13.0)
120
+ solargraph (0.49.0)
121
+ backport (~> 1.2)
122
+ benchmark
123
+ bundler (~> 2.0)
124
+ diff-lcs (~> 1.4)
125
+ e2mmap
126
+ jaro_winkler (~> 1.5)
127
+ kramdown (~> 2.3)
128
+ kramdown-parser-gfm (~> 1.1)
129
+ parser (~> 3.0)
130
+ rbs (~> 2.0)
131
+ reverse_markdown (~> 2.0)
132
+ rubocop (~> 1.38)
133
+ thor (~> 1.0)
134
+ tilt (~> 2.0)
135
+ yard (~> 0.9, >= 0.9.24)
136
+ thor (1.2.2)
137
+ tilt (2.2.0)
138
+ tzinfo (2.0.6)
139
+ concurrent-ruby (~> 1.0)
140
+ unf (0.1.4)
141
+ unf_ext
142
+ unf_ext (0.0.8.2)
143
+ unicode-display_width (2.4.2)
144
+ websocket (1.2.9)
145
+ websocket-client-simple (0.6.1)
146
+ event_emitter
147
+ websocket
148
+ yard (0.9.34)
149
+
150
+ PLATFORMS
151
+ x86_64-darwin-22
152
+
153
+ DEPENDENCIES
154
+ activerecord (~> 7.0)
155
+ burroughs!
156
+ discordrb!
157
+ httparty (~> 0.21)
158
+ pry-byebug
159
+ rake (~> 13.0)
160
+ rspec (~> 3.0)
161
+ rubocop (~> 1.21)
162
+ solargraph
163
+
164
+ BUNDLED WITH
165
+ 2.4.7
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Burroughs
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/burroughs`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/burroughs.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/exe/burroughs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "burroughs"
4
+
5
+ Burroughs.init
data/exe/comp_reset ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "burroughs"
4
+ require "httparty"
5
+ require "json"
6
+
7
+ BASE = "https://discord.com/api"
8
+ VERS = "v9"
9
+
10
+ resp = HTTParty.get("#{BASE}/#{VERS}/applications/#{Burroughs.prefs.appid}/commands",
11
+ headers: { Authorization: "Bot #{Burroughs.prefs.token}" })
12
+ if resp.code != 200
13
+ puts "#{resp.code} #{resp.message}"
14
+ exit 1
15
+ end
16
+
17
+ commands = JSON.parse(resp.body)
18
+
19
+ if commands.size == 0
20
+ puts "No commands to remove."
21
+ exit 0
22
+ end
23
+
24
+ commands.each do |_c|
25
+ resp = HTTParty.delete("#{BASE}/#{VERS}/applications/#{Burroughs.prefs.appid}/commands/#{_c["id"]}",
26
+ headers: { Authorization: "Bot #{Burroughs.prefs.token}" })
27
+ puts "#{resp.code} #{resp.message} for command #{_c["id"]} (#{_c["name"]})" if resp.code != 204
28
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Commands
4
+ def initialize
5
+ @cmds = [
6
+ { name: :ping, desc: "Are you awake?" },
7
+ { name: :clear, desc: "Clear messages in the current channel (max 100).", params:
8
+ [
9
+ { type: "integer", name: "size", desc: "Number of messages to clear.", required: true }
10
+ ] },
11
+ { name: :invite, desc: "Generate an invite link.", params:
12
+ [
13
+ { type: "string", name: "username", desc: "Automatically PM the invite to the specified user.", required: false }
14
+ ] }
15
+ ]
16
+ end
17
+
18
+ def register
19
+ @cmds.each do |c|
20
+ if c.params.nil?
21
+ bot.register_application_command(c.name, c.desc)
22
+ else
23
+ bot.register_application_command(c.name, c.desc) do |cmd|
24
+ c.params.each do |p|
25
+ cmd.send(type, p.name, p.desc, required: p.required)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Configurable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def prefs
10
+ @prefs ||= Preferences.new
11
+ end
12
+
13
+ def configure
14
+ yield prefs
15
+ end
16
+ end
17
+
18
+ class Preferences
19
+ attr_accessor :token, :appid, :loglevel
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Environments
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def env
10
+ @env ||= Environment.new
11
+ end
12
+ end
13
+
14
+ class Environment
15
+ attr_reader :type
16
+
17
+ def initialize
18
+ env = ENV.fetch("BURROUGHS_ENV", nil)
19
+ @type = :development
20
+
21
+ @type = if env.nil? || env.empty?
22
+ :development
23
+ elsif env == "production"
24
+ :production
25
+ elsif env == "test"
26
+ :test
27
+ else
28
+ :development
29
+ end
30
+ end
31
+
32
+ def production?
33
+ return true if @type == :production
34
+
35
+ false
36
+ end
37
+
38
+ def test?
39
+ return true if @type == :test
40
+
41
+ false
42
+ end
43
+
44
+ def development?
45
+ return true if @type == :development
46
+
47
+ false
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Burroughs
4
+ VERSION = "0.1.0"
5
+ end
data/lib/burroughs.rb ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "burroughs/version"
4
+ require_relative "burroughs/util/configurable"
5
+ require_relative "burroughs/util/environments"
6
+
7
+ require "logger"
8
+ require "json"
9
+ require "discordrb"
10
+
11
+ module Burroughs
12
+ class Error < StandardError; end
13
+ include Environments
14
+ include Configurable
15
+
16
+ if env.development? || env.test?
17
+ require_relative "../preferences"
18
+ else
19
+ require_relative "preferences"
20
+ end
21
+
22
+ def self.init
23
+ Signal.trap("INT") { exit }
24
+ Signal.trap("TERM") { exit }
25
+
26
+ l = Logger.new($stdout)
27
+ l.level = prefs.loglevel
28
+ l.debug "hello"
29
+ l.debug env.type
30
+
31
+ bot = Discordrb::Bot.new(token: Burroughs.prefs.token)
32
+
33
+ bot.register_application_command(:ping, "Are you awake?")
34
+ bot.register_application_command(:clear, "Clear messages in the channel (max 100).") do |cmd|
35
+ cmd.integer("size", "Number of messages to clear.", required: true)
36
+ end
37
+
38
+ bot.application_command(:ping) do |event|
39
+ travel_time = (Time.now - event.timestamp).round
40
+ event.respond(content: "I'm awake and only `#{travel_time}ms` away.")
41
+ end
42
+
43
+ bot.application_command(:clear) do |event|
44
+ n = event.options["size"]
45
+ messages = event.channel.history(n)
46
+ # event.channel.prune(n) # TODO: For some reason, this is getting rate limited, but our workaround is fine for now
47
+
48
+ messages.each do |m|
49
+ m.delete
50
+ end
51
+
52
+ n == 1 ? event.respond(content: "Cleared #{n} message.") : event.respond(content: "Cleared #{n} messages.")
53
+
54
+ sleep 4
55
+ event.interaction.delete_response
56
+ end
57
+
58
+ bot.run
59
+ ensure
60
+ bot.stop if bot&.connected?
61
+ l.close
62
+ end
63
+ end
data/sig/burroughs.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Burroughs
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: burroughs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rory Dudley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Swiss army knife Discord bot for The Sanctuary.
14
+ email:
15
+ - rory.dudley@gmail.com
16
+ executables:
17
+ - burroughs
18
+ - comp_reset
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rubocop.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - Rakefile
27
+ - exe/burroughs
28
+ - exe/comp_reset
29
+ - lib/burroughs.rb
30
+ - lib/burroughs/commands/commands.rb
31
+ - lib/burroughs/util/configurable.rb
32
+ - lib/burroughs/util/environments.rb
33
+ - lib/burroughs/version.rb
34
+ - sig/burroughs.rbs
35
+ homepage: https://github.com/the-sanctuary/burroughs
36
+ licenses: []
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ rubygems_mfa_required: 'true'
40
+ homepage_uri: https://github.com/the-sanctuary/burroughs
41
+ source_code_uri: https://github.com/the-sanctuary/burroughs
42
+ changelog_uri: https://github.com/the-sanctuary/burroughs
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.6.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.4.7
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Burroughs Discord bot.
62
+ test_files: []