Discord bot parser python

Discord Markdown AST Parser

This package provides a parser that can be used to translate a Discord message into an abstract syntax tree (AST) that represents how the message should be rendered according to Discord’s markdown rules.

Example

Check the following example on how this parser will translate a Discord message:

You can install this package from PyPI:
pip install discord-markdown-ast-parser 

Usage

Pass the message’s content to parse_to_dict to get the AST represented as a dict . Alternatively, use parse to get the AST using this package’s internal Node type instead of a string-based dict :

These are the types of nodes the parser will output:

TEXT - fields: "text_content" - Just standard text, no additional formatting - No child nodes ITALIC, BOLD, UNDERLINE, STRIKETHROUGH, SPOILER, CODE_INLINE - fields: "children" - self-explanatory QUOTE_BLOCK - fields: "children" - represents a single, uninterrupted code block (no gaps in Discord's client) - can not contain another quote block (Discord has no nested quotes) CODE_BLOCK - fields: "children", "code_lang" - can only contain a single TEXT node, all other markdown syntax inside the code block is ignored - may or may not have a language specifier - first newline is stripped according to the same rules that the Discord client uses USER, ROLE, CHANNEL - fields: "discord_id" - user, role, or channel mention - there is no way to retrieve the user/role/channel name, color or channel type (text/voice/stage) from just the message, so you'll have to use the API (or discord.py) to query that URL_WITH_PREVIEW, URL_WITHOUT_PREVIEW - fields: "url" - a HTTP URL - this is only recognized if the link actually contains "http". this is the same for the Discord client, with the exception that the Discord client also scan for invite links that don't start with http, e.g., "discord.gg/pxa" - the WITHOUT_PREVIEW variant appears when the message contains the URL in the form, which causes the Discord client to suppress the preview EMOJI_CUSTOM - fields: "emoji_name", "emoji_id" - you can get the custom emoji's image by querying to https://cdn.discordapp.com/emojis/EMOJI_ID.png EMOJI_UNICODE_ENCODED - fields: "emoji_name" - this will appear very rarely. unicode emojis are usually just posted as unicode characters and thus end up in a TEXT node it is, however, possible to send a message from a bot that uses, e.g., :red_car: instead of the actual red_car unicode emoji. the Discord client will properly translate that to the correct unicode emoji. this package does not do that because Discord has not published the list of names they use for the emojis. so this package will simply relay the emoji's name 

Known Issues

While this parser should work in pretty much every realistic scenario, there are some very specific edge cases in which this parser will produce an output that doesn’t align with how it’s rendered in the Discord client:

  • ***bold and italic*** will be detected as bold-only with extra stars. This only happens when the italic and bold stars are right next to each other. This does not happen when mixing bold stars with italic underscores.
  • *italic with whitespace before star closer * will be detected as italic even though the Discord client won’t. Note that Discord doesn’t have this weird requirement for _underscore italic_ .
||spoilers around ``` code blocks ``` || 

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Simple Discord bot that does two things: works as RSS and can parse page specified by a link right into discord.

KtyJIxy/Discord-Parser-RSS-Public

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Discord Parser RSS is a simple Discord bot built on Python that does two things:

  • Bring your RSS subscriptions for last 24 hours on command;
  • Parse web-sites and prints text directly into channel.
  1. Clone this repository and keep it private.
  2. At Discord Developer Portal create new application. Remember Client ID .
  3. At application page on Discord Developer Portal create a bot and save token (KEEP IT SECRET.)
  4. Create a Discord Server or be sure to have bot-inviting rights on existing one.
  5. Invite your bot to server by link: https://discord.com/oauth2/authorize?client_id=[Client ID numbers]&scope=bot .
  6. Get back to GitHub and save your token in code, 11th line. Alternatively, there are ways to load your token into file. Discussed below.
  7. Create a Heroku account.
  8. Create a new App with unique name. On Settings page in Buildpack choose Python.
  9. On Deploy page link your Heroku account to Github account, choose your Discord Parser RSS Bot repository and deploy it.
  10. On Resources page activate worker.
  11. Test your bot. It should work now, except ?rss_daily command.
  12. In FEED_URL (line 32) add all your XML RSS subscriptions, push and re-deploy. All set.

You either can set up an .env at Heroku (check manual) or load it locally, through a JSON-mapping , for example. Latter will require installing of Heroku CLI and, of course addition of according .gitignore line. You will stage your bot directly from your local repository, so you won’t need a GitHub linking to Heroku anymore.

Things to consider while using:

  • Parse function prints all the text on page, despite how page long is. If you’re using it for same sites, you may want to make it parse through specific block-codes on page. Of course, every site has different HTML structure, so you will have to write code for every situation.
  • If you’re setting bot not only for yourself, but for a community, you may want to add user commands to add to FEED_URL.
  • RSS function is set to bring links of content. If your subscription is, for example, photos, you’ll have to change parsed XML-structure accordingly.

About

Simple Discord bot that does two things: works as RSS and can parse page specified by a link right into discord.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

parsing info from discord, wallet addresses etc.

1-0-1-Labs/discord_parser

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A python script for scraping solana wallet addresses in a discord server.

A Discord bot client is initialized. This client works with the specified discord bot token. When an event is received, all messages in the channel are retrieved with the specified channel id. The received messages are checked one by one with regexp within the for loop. If it matches with the regexp, the discord id of the author of the message and the message are stored as a dictionary which is used to store key:value pairs and this dict is appended to a list. After all messages are checked, this list is written to the json file.

git clone https://github.com/1-0-1-Labs/discord_parser cd discord_parser pip3 install -r requirements.txt 
user@pc:~$ python3 scrape_dc.py [INFO] Logged in as my_lovely_bot#3886 [INFO] JSON data is written to wallet_addresses.json 

Creating a Discord Bot & Fetching Bot’s Token

After entering here, create a new application. Enter the bot settings of the application you created and click «Add Bot». After adding a bot, click «Click to Reveal Token» to see the bot’s token below. Detailed info here

Adding the Bot to a Discord Server

To add your bot to a discord server, you should know its client id. You can find it from the OAuth2 settings of the application that you created before. Detailed info here. After finding the client id, just replace with YOUR_CLIENT_ID in the following URL. https://discordapp.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot&permissions=0

Finding the ID of a Discord Channel

Go to your discord settings > advanced settings and enable «Developer Mode». After enabling the developer mode, right click to the channel that you want to find its id and click «Copy ID». Detailed info here

Firstly create a discord bot and add it to your discord server. After adding it to your discord server get ID of the channel that you want to scrape. Clone this repo to your device and change enviroment variables (channel id and bot token) which are in «.env» file. Execute the python script and thats all!

About

parsing info from discord, wallet addresses etc.

Источник

Читайте также:  Read file into bytes python
Оцените статью