Skip to content

Commit

Permalink
Previous non-cached implementation broke due to sudden API limit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
norrisng committed Nov 4, 2019
1 parent 44d119b commit 206812e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Discord API bot token
bot_token.txt
discord_credentials.py

# Current client version
/curr_client_version.txt
Expand Down
14 changes: 13 additions & 1 deletion dbmanager/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dbmodels.fsd_message import FsdMessage
from discord import DMChannel, Client
from typing import List
import discord_credentials

# MariaDB
DB_URI = 'localhost'
Expand Down Expand Up @@ -392,7 +393,18 @@ async def get_channel(client: Client, discord_id: int) -> DMChannel:
try:
channel = pm_channels[discord_id]
except KeyError:
user = await client.get_user_info(discord_id)
# (0.10.1 and earlier) Old implementation:
# This makes an API call.
# get_user_info() would fail silently, returning None instead of an exception.
#
# This may have been due to this:
# https://www.reddit.com/r/discordapp/comments/couffh/is_discord_going_to_undo_the_recent_api_change/
# -----
# user = await client.get_user_info(discord_id)
# ch = user.dm_channel

# (0.10.2+) New implementation: this is a cache lookup
user = client.get_guild(discord_credentials.FCOM_DISCORD_SERVER_ID).get_member(discord_id)
ch = user.dm_channel

if ch is None:
Expand Down

0 comments on commit 206812e

Please sign in to comment.