Skip to content

Commit

Permalink
Fix issue with Message.lua causing bot to crash (#290)
Browse files Browse the repository at this point in the history
* Fix issue with Message.lua causing bot to crash

This fixes an issue with my friend's bot where `reaction` is nil and causes the bot to crash. The check should be before the definition of `reaction` to fix the issue.

* Apply fix for issue properly

I originally messed up and put the if statement higher when `reactions` was nil, and `reactions` was attempted to be indexed when nil, not `reaction` being nil.

* Apply requested changes

Makes the check for reactions an if statement rather than in-line with the variable.
  • Loading branch information
mrparkerlol authored May 12, 2021
1 parent b371b03 commit 3aa8da4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libs/containers/Message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ end
function Message:_removeReaction(d)

local reactions = self._reactions

if not reactions then return nil end

local emoji = d.emoji
local k = emoji.id ~= null and emoji.id or emoji.name
local reaction = reactions:get(k)

local reaction = reactions:get(k) or nil
if not reaction then return nil end -- uncached reaction?

reaction._count = reaction._count - 1
Expand Down

3 comments on commit 3aa8da4

@IsLilyYaGirl
Copy link

Choose a reason for hiding this comment

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

are you 100% sure that "or nil" is necessary? (i could be entirely wrong here because i'm mostly sure that it's not necessary in standard lua/luajit but idk if luvit uses a different type of lua that does need that)

@SinisterRectus
Copy link
Owner

Choose a reason for hiding this comment

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

It's not necessary, but it's fine to use.

@seyja
Copy link
Contributor

@seyja seyja commented on 3aa8da4 May 16, 2021

Choose a reason for hiding this comment

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

it's not rlly necessary unless if you don't want reaction to be false

Please sign in to comment.