Skip to content

Commit

Permalink
fix: Discord connector when a channel is not found. (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvztz authored Sep 29, 2023
1 parent 792232d commit 4e84e32
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.10.17-dev16
## 0.10.17-dev17

### Enhancements

Expand Down Expand Up @@ -29,6 +29,7 @@ should be generated, however the Formula class inherits from Element instead of
allowing the document to be loaded. Fix: Change parent class for Formula to Text. Importance: Crucial to be able to load documents that contain formulas.
* **Fixes Sphinx errors.** Fixes errors when running Sphinx `make html` and installs library to suppress warnings.
* **Fixes a metadata backwards compatibility error** Problem: When calling `partition_via_api`, the hosted api may return an element schema that's newer than the current `unstructured`. In this case, metadata fields were added which did not exist in the local `ElementMetadata` dataclass, and `__init__()` threw an error. Fix: remove nonexistent fields before instantiating in `ElementMetadata.from_json()`. Importance: Crucial to avoid breaking changes when adding fields.
* **Fixes issue with Discord connector when a channel returns `None`** Problem: Getting the `jump_url` from a nonexistent Discord `channel` fails. Fix: property `jump_url` is now retrieved within the same context as the messages from the channel. Importance: Avoids cascading issues when the connector fails to fetch information about a Discord channel.


## 0.10.16
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.17-dev16" # pragma: no cover
__version__ = "0.10.17-dev17" # pragma: no cover
5 changes: 4 additions & 1 deletion unstructured/ingest/connector/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _get_messages(self):
from discord.ext import commands

messages: t.List[discord.Message] = []
jumpurl: t.List[str] = []
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=">", intents=intents)
Expand All @@ -88,15 +89,17 @@ async def on_ready():
if self.days:
after_date = dt.datetime.utcnow() - dt.timedelta(days=self.days)
channel = bot.get_channel(int(self.channel))
jumpurl.append(channel.jump_url) # type: ignore
async for msg in channel.history(after=after_date): # type: ignore
messages.append(msg)
await bot.close()
except Exception:
logger.error("Error fetching messages")
await bot.close()
raise

bot.run(self.token)
jump_url = bot.get_channel(int(self.channel)).jump_url # type: ignore
jump_url = None if len(jumpurl) < 1 else jumpurl[0]
return messages, jump_url

def update_source_metadata(self, **kwargs):
Expand Down

0 comments on commit 4e84e32

Please sign in to comment.