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 filtering of playing events by game or type #303

Merged
merged 1 commit into from
Jan 12, 2017

Conversation

sven-strothoff
Copy link
Contributor

There are two small issues in the PlayingEventHandler that result in crashes if a filter for game or type is used.

During the initialisation of PlayingEvent the game object received from the server is flattened to its only attribute name (presence.rb:75). In line 100 event.game.name is accessed, but at this point event.game is only a string.

For filtering by event type the type attribute is accessed twice (i.e. event.type.type) in lines 105 and 107.

@@ -97,14 +97,14 @@ def matches?(event)
end,
matches_all(@attributes[:game], event.game) do |a, e|
a == if a.is_a? String
e.name
e
else
e
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call all just be written as a == e

else
e
end
end,
matches_all(@attributes[:type], event.type) do |a, e|
a == if a.is_a? Integer
e.type
e
else
e
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@sven-strothoff sven-strothoff force-pushed the fix-playing-event-handler branch from 64d76c8 to 516c612 Compare January 12, 2017 21:48
@meew0 meew0 added this to the 3.2.0 milestone Jan 12, 2017
@meew0
Copy link
Collaborator

meew0 commented Jan 12, 2017

Nice catch!

@meew0 meew0 merged commit 6c22c7d into discordrb:master Jan 12, 2017
@sven-strothoff
Copy link
Contributor Author

Yeah, I had a strange feeling about the e in the if and else branches. I thought it mattered that a is a String/Integer respectively. But you are right @Daniel-Worrall, it's just e in every case. I amended my commit. Thank you!

@sven-strothoff sven-strothoff deleted the fix-playing-event-handler branch January 12, 2017 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants