GithubHelp home page GithubHelp logo

audiosutras / feed_bot Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 675 KB

A discord bot for emulating an rss feed reader within your guild channels

Home Page: https://docs.chrisdixononcode.dev/feed_bot.html

License: MIT License

Dockerfile 1.13% Python 98.87%
discord-bot docker python rss-feed self-hosted

feed_bot's People

Contributors

audiosutras avatar

Watchers

 avatar  avatar

feed_bot's Issues

Not Well Formed URL

feed_bot-bot-prod-1  | 2024-02-10 05:15:50 ERROR    discord.ext.tasks Unhandled exception in internal background task 'subreddit_task'.
feed_bot-bot-prod-1  | Traceback (most recent call last):
feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
feed_bot-bot-prod-1  |     await self.coro(*args, **kwargs)
feed_bot-bot-prod-1  |   File "/code/feed_bot/bot.py", line 98, in subreddit_task
feed_bot-bot-prod-1  |     await self.post_subreddit(*args, **kwargs)
feed_bot-bot-prod-1  |   File "/code/feed_bot/bot.py", line 146, in post_subreddit
feed_bot-bot-prod-1  |     await channel.send(embeds=[embed])
feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/abc.py", line 1561, in send
feed_bot-bot-prod-1  |     data = await state.http.send_message(channel.id, params=params)
feed_bot-bot-prod-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 745, in request
feed_bot-bot-prod-1  |     raise HTTPException(response, data)
feed_bot-bot-prod-1  | discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
feed_bot-bot-prod-1  | In embeds.0.url: Not a well formed URL.



Resolves #61: ValueError RSS Feeds

This PR remediates a ValueError bug that is thrown when more than 10 embeds are tried to be sent to a channel. Now sending embeds in batches.

Consolidate reddit api calls

In asyncpraw you can fetch multiple subreddits at once. Let's retrieve a channel's subreddits and fetch new listings at one in order to cut down on api requests.

Website Feeds

This ticket is to start consuming and posting website rss feeds to discord.

DONT NOT USE 0.2.6

A couple of bugs need to be worked out of 0.2.6 docker image. Use 0.2.5 but limit the amount of rss feeds you are following.

Also looking to retire this project in favor another that utilizes webhooks and its own self-hostable server. More on that in the future.

Support The Work task loop

Let end users know where they can support the project.

  • Include a url and qr code to kofi
  • amazon affiliate link

Make sure duplicate entries are not stored in db

Need to make sure only unique entries are stored in database.

See corbett report 'February Open Thread' for an example of a duplicated entry. inserted_entries are being sent to channels after being inserted into the db. inserted_entries should be unique.

To access database:

$  docker compose exec mongo mongosh mongodb://root:feed_bot@mongo:27017/
$ use feed_bot_db
$ db.rss.find({feed_url: 'https://corbettreport.com/feed', title: 'February Open Thread'})



Unique Discord Colour for RSS Feed source

Assign a unique rss feed colour for the source.

  • Reddit stays orange
  • website stays blue
  • substack set to green

Create a dictionary for rss feed source colors, check domains against dictionary for assigning colours. Update dictionary when a new source is found

ValueError RSS Feeds - Embeds has a maximum of 10 elements

feed_bot-bot-1  | 2024-04-01 10:23:56 ERROR    discord.ext.tasks Unhandled exception in internal background task 'rss_feeds_task'.
feed_bot-bot-1  | Traceback (most recent call last):
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
feed_bot-bot-1  |     await self.coro(*args, **kwargs)
feed_bot-bot-1  |   File "/code/feed_bot/bot.py", line 208, in rss_feeds_task
feed_bot-bot-1  |     await self.update_all_rss_feeds(*args, **kwargs)
feed_bot-bot-1  |   File "/code/feed_bot/bot.py", line 259, in update_all_rss_feeds
feed_bot-bot-1  |     await self.channel_send(
feed_bot-bot-1  |   File "/code/feed_bot/bot.py", line 119, in channel_send
feed_bot-bot-1  |     await channel.send(*args, **kwargs)
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/abc.py", line 1545, in send
feed_bot-bot-1  |     with handle_message_parameters(
feed_bot-bot-1  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 171, in handle_message_parameters
feed_bot-bot-1  |     raise ValueError('embeds has a maximum of 10 elements.')

Code Cleanup: Add Comprehensive Typing

Do more to add strong typing for a better understanding of the code for yourself and others. Add typing across all files where possible.

If strapped for time focus rss workflow.

Add Unit Test Suite

Add unit testings of REDDITRSS and any logic that is not directly tied to discord.py.


400 Bad Request: embeds.0.title: Must be 256 or fewer in length

feed_bot-bot-1  | 2024-02-12 16:55:50 ERROR    discord.ext.tasks Unhandled exception in internal background task 'subreddit_task'.
feed_bot-bot-1  | Traceback (most recent call last):
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
feed_bot-bot-1  |     await self.coro(*args, **kwargs)
feed_bot-bot-1  |   File "/code/feed_bot/bot.py", line 98, in subreddit_task
feed_bot-bot-1  |     await self.post_subreddit(*args, **kwargs)
feed_bot-bot-1  |   File "/code/feed_bot/bot.py", line 146, in post_subreddit
feed_bot-bot-1  |     await channel.send(embeds=[embed])
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/abc.py", line 1561, in send
feed_bot-bot-1  |     data = await state.http.send_message(channel.id, params=params)
feed_bot-bot-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
feed_bot-bot-1  |   File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 745, in request
feed_bot-bot-1  |     raise HTTPException(response, data)
feed_bot-bot-1  | discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
feed_bot-bot-1  | In embeds.0.title: Must be 256 or fewer in length.
```

Generate PDF of Entry Content

For an entry when a user adds an emoji (like a paper emoji) dm that user with the full content if an article. TBD"


Remove Subreddit command

Need to add a remove subreddit from channel feed command. Doing so removes any unsent posts for that subreddit in the particular channel as well.

Subreddit list

List the subreddits that are available within a particular channel

URL Not Well Formed Error

Same error we thought we resolved in Issue #20

feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
feed_bot-bot-prod-1  |     await self.coro(*args, **kwargs)
feed_bot-bot-prod-1  |   File "/code/feed_bot/bot.py", line 98, in subreddit_task
feed_bot-bot-prod-1  |     await self.post_subreddit(*args, **kwargs)
feed_bot-bot-prod-1  |   File "/code/feed_bot/bot.py", line 146, in post_subreddit
feed_bot-bot-prod-1  |     await channel.send(embeds=[embed])
feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/abc.py", line 1561, in send
feed_bot-bot-prod-1  |     data = await state.http.send_message(channel.id, params=params)
feed_bot-bot-prod-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
feed_bot-bot-prod-1  |   File "/usr/local/lib/python3.12/site-packages/discord/http.py", line 745, in request
feed_bot-bot-prod-1  |     raise HTTPException(response, data)
feed_bot-bot-prod-1  | discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
feed_bot-bot-prod-1  | In embeds.0.url: Scheme "/r/trading212/comments/1amu4an/i_made_a_trading_212_dashboard_free_to_use/" is not supported. Scheme must be one of ('http', 'https'). Not a well formed URL.

Create task to poll subreddit for new posts

  • We need to get unique together channel_id and subreddit columns out of the database.
  • Then run get_channel_subreddit_dicts
  • Then check if a document already exists in the database. If not insert this document

For this task see:

  • reddit.py get_channel_subreddit_dicts
  • cogs.py update_or_insert_documents definition within subreddit group

Need to fix update_or_insert_documents.

  • move it to bot class
  • break into two parts, find_one and insert_one

Better logging for rss feeds

We need better logging for rss feeds. There seems to be an issue where an error is occurring and our loop is stopping.

Handle Errors Generated During Coroutine task

For example if you delete a channel while a background task is sending embeds to said channel an error is generated and the task stops. Make sure we handle exceptions and restart the task.

Order Feed Updates by Date

Have earliest published added first to Feed Updates and send to channel the latest published embed last

Env Var for Looping Interval

Create a couple environment variables for task.loop intervals and update documentation.

  • LOOP_SECONDS
  • LOOP_MINUTES
  • LOOP_HOURS
    

Validating Input & Error Handling Reddit API

  • Except r/<subreddit> and <subreddit> for add definiton in cog
  • Handle errors generated by API calls to reddit
  • Handle space seperated input and comma seperated input for add method in cog.py

Refactor how Channel Updates for Subreddits Are Sent

Eventually would like to copy the rss workflow for reddit. Only associate a subreddit name with a channel. Get the channels that subscribed to that subreddit. Send new listings to channels and store the new listing in the db.
See workflow for rss for more information. 

Add Export Feature

Allow users to get a csv file for their subscriptions.

  • .rss export
  • .subreddit export

Exporting feed_urls as a comma seperated list will make importing again very easy



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.