Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix type errors #21

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ source "https://rubygems.org"
# Specify your gem's dependencies in discorb.gemspec
gemspec

gem "rake", "~> 13.0"
gem "rake", "~> 13.0", require: false

# Rubocop
gem "rubocop", "~> 1.25"
gem "rubocop-rake", "~> 0.6.0"
gem "rubocop-rspec", "~> 2.9"
gem "rubocop", "~> 1.25", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
gem "rubocop-rspec", "~> 2.9", require: false

# RSpec
gem "async-rspec", "~> 1.17"
gem "parallel_tests", "~> 4.2"
gem "rspec", "~> 3.12"
gem "async-rspec", "~> 1.17", require: false
gem "parallel_tests", "~> 4.2", require: false
gem "rspec", "~> 3.12", require: false

# Typecheck
gem "steep", "~> 1.1"
gem "steep", "~> 1.5", require: false

# Other development tools
gem "lefthook", "~> 1.4.3"
gem "sord", "~> 3.0.1"
gem "lefthook", "~> 1.4.3", require: false
gem "sord", "~> 3.0.1", require: false

group :docs, optional: true do
gem "crowdin-api", "~> 1.0"
gem "gettext", "~> 3.4.1"
gem "redcarpet"
gem "rubyzip", "~> 2.3"
gem "yard", "~> 0.9.26"
gem "crowdin-api", "~> 1.0", require: false
gem "gettext", "~> 3.4.1", require: false
gem "redcarpet", require: false
gem "rubyzip", "~> 2.3", require: false
gem "yard", "~> 0.9.26", require: false
end

gem "syntax_tree", "~> 2.8"
gem "syntax_tree-rbs", "~> 0.5.0"
gem "syntax_tree", "~> 2.8", require: false
gem "syntax_tree-rbs", "~> 0.5.0", require: false
2 changes: 0 additions & 2 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ target :lib do

check "lib"

library "net-http", "timeout"

configure_code_diagnostics(D::Ruby.lenient)
configure_code_diagnostics do |config|
config[D::Ruby::UnsupportedSyntax] = nil
Expand Down
4 changes: 3 additions & 1 deletion lib/discorb/channel/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class CategoryChannel < GuildChannel
include Discorb::ChannelContainer

def channels
@client.channels.values.filter { |channel| channel.parent == self }
@client.channels.values.filter do |channel|
channel.parent == self && channel.is_a?(Discorb::GuildChannel)
end
end

def create_text_channel(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion lib/discorb/channel/forum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def fetch_webhooks
# @param [Integer] rate_limit_per_user The rate limit per user.
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
#
# @return [Async::Task<Discorb::PublicThread>] The created thread.
# @return [Async::Task<Discorb::ForumChannel::Post>] The created thread.
#
def create_post(
title,
Expand Down
1 change: 1 addition & 0 deletions lib/discorb/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module ClassMethods
# @param [Hash] metadata Other metadata.
#
def event(event_name, id: nil, **metadata, &block)
# @type var event_name: Symbol
unless event_name.is_a?(Symbol)
raise ArgumentError, "Event name must be a symbol"
end
Expand Down
32 changes: 25 additions & 7 deletions lib/discorb/gateway_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,41 @@ module Discorb
# Represents an activity for Gateway Command.
#
class Activity
# @return [String] The text of the activity.
attr_reader :text
# @return [:playing, :streaming, :listening, :watching, :custom, :competing] The type of the activity.
attr_reader :type
# @return [String] The URL of the activity.
attr_reader :url

# @private
# @return [{Symbol => Integer}] The mapping of activity types.
TYPES = {
playing: 0,
streaming: 1,
listening: 2,
watching: 3,
custom: 4,
competing: 5
}.freeze

#
# Initializes a new Activity.
#
# @param [String] name The name of the activity.
# @param [:playing, :streaming, :listening, :watching, :competing] type The type of activity.
# @param [String] text The text of the activity.
# @param [:playing, :streaming, :listening, :watching, :custom, :competing] type The type of activity.
# @param [String] url The URL of the activity.
#
def initialize(name, type = :playing, url = nil)
@name = name
@type = TYPES[type] or
raise ArgumentError, "Invalid activity type: #{type}"
def initialize(text, type = :playing, url: nil)
@text = text
@type =
(
if TYPES.key?(type)
TYPES[type]
else
raise(ArgumentError, "invalid activity type: #{type}")
end
)
@url = url
end

Expand All @@ -35,7 +49,11 @@ def initialize(name, type = :playing, url = nil)
# @return [Hash] A hash representation of the activity.
#
def to_hash
{ name: @name, type: @type, url: @url }
if @type == :custom
{ state: @text, type: @type, url: @url }
else
{ name: @text, type: @type, url: @url }
end
end

def inspect
Expand Down
72 changes: 7 additions & 65 deletions rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,88 +1,30 @@
---
sources:
- name: ruby/gem_rbs_collection
- type: git
name: ruby/gem_rbs_collection
revision: 8a678b2ec20e9d594055f53745399814e3a887dc
remote: https://github.com/ruby/gem_rbs_collection.git
revision: main
repo_dir: gems
path: ".gem_rbs_collection"
gems:
- name: net-http
version: '0'
source:
type: stdlib
- name: logger
version: '0'
source:
type: stdlib
- name: ast
version: '2.4'
source:
type: git
name: ruby/gem_rbs_collection
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: forwardable
version: '0'
source:
type: stdlib
- name: i18n
version: '1.10'
source:
type: git
name: ruby/gem_rbs_collection
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: listen
version: '3.2'
source:
type: git
name: ruby/gem_rbs_collection
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: minitest
version: '0'
source:
type: stdlib
- name: parallel
version: '1.20'
source:
type: git
name: ruby/gem_rbs_collection
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: prime
version: '0'
source:
type: stdlib
- name: rainbow
version: '3.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: singleton
- name: monitor
version: '0'
source:
type: stdlib
- name: uri
- name: net-http
version: '0'
source:
type: stdlib
- name: timeout
version: '0'
source:
type: stdlib
- name: monitor
version: '0'
source:
type: stdlib
- name: mutex_m
- name: uri
version: '0'
source:
type: stdlib
gemfile_lock_path: Gemfile.lock
16 changes: 13 additions & 3 deletions sig/discorb/activity.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ module Discorb
class Activity
TYPES: untyped

type types = :playing | :streaming | :listening | :watching | :custom | :competing

# @return [String] The text of the activity.
attr_reader text: String
# @return [:playing, :streaming, :listening, :watching, :competing] The type of the activity.
attr_reader type: types
# @return [String] The URL of the activity.
attr_reader url: String?

#
# Initializes a new Activity.
#
# @param [String] name The name of the activity.
# @param [:playing, :streaming, :listening, :watching, :competing] type The type of activity.
# @param [String] text The text of the activity.
# @param [:playing, :streaming, :listening, :watching, :custom, :competing] type The type of activity.
# @param [String] url The URL of the activity.
def initialize: (String name, ?Symbol `type`, ?String? url) -> void
#
def initialize: (String text, types type, ?url: String?) -> void

#
# Converts the activity to a hash.
Expand Down
6 changes: 3 additions & 3 deletions sig/discorb/channel/forum.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Discorb
String name,
Discorb::emoji emoji,
?moderated: bool
) -> Discorb::ForumChannel::Tag
) -> void

# Returns the tag as a hash.
#
Expand Down Expand Up @@ -292,7 +292,7 @@ module Discorb
# @param [Integer] rate_limit_per_user The rate limit per user.
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
#
# @return [Async::Task<Discorb::PublicThread>] The created thread.
# @return [Async::Task<Discorb::ForumChannel::Post>] The created thread.
def create_post: (
title: String,
?content: String,
Expand All @@ -306,7 +306,7 @@ module Discorb
?auto_archive_duration: :hour | :day | :three_days | :week,
?rate_limit_per_user: Integer,
?slowmode: Integer
) -> Async::Task[Discorb::PublicThread]
) -> Async::Task[Discorb::ForumChannel::Post]

alias start_thread create_post
alias create_thread start_thread
Expand Down
6 changes: 3 additions & 3 deletions sig/discorb/user.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Discorb
attr_reader verified: bool

# @return [String] The user's username. ("sevenc_nanashi" for new users, "Nanashi." for old users.)
attr_reader :username
attr_reader username: String
alias name username

# @return [Discorb::Snowflake] The user's ID.
Expand All @@ -46,10 +46,10 @@ module Discorb

# @return [String] The user's discriminator. ("0" for new users, "7740" for old users.)
# @deprecated This will be removed in the future because of discord changes.
attr_reader :discriminator
attr_reader discriminator: String

# @return [String] The user's global name. ("Nanashi." for new users, old users have no global name.)
attr_reader :global_name
attr_reader global_name: String

# @return [Discorb::Asset, Discorb::DefaultAvatar] The user's avatar.
attr_reader avatar: Discorb::Asset | Discorb::DefaultAvatar
Expand Down