Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treehouses message discord [servers|channels|read|send] new subcommands (fixes #2152) #2151

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

rjpadilla
Copy link
Member

@rjpadilla rjpadilla commented Mar 27, 2021

New treehouses message discord features

Four new subcommands for treehouse message discord:

  • servers - list all servers the user is in
  • channels - list all channels in the chosen server by the user
  • read - read all messages in the chosen server and channel
  • send - send a message in the chosen server and channel

How to use

In the Discord Web Client, type ctrl+shift+i to pull up the browser's Developer Tools.
Head to the Network tab and filter the url with /api (you may need to reload the page).
Click on any of the requests and in the headers windows on the right, copy the Authorization's value.
This value will be your API token.

grabapitoken

Add your apitoken with the command treehouses message discord authorize <apitoken>

@JLKwong
Copy link
Member

JLKwong commented Mar 29, 2021

  • servers - list all servers owned by the user

./cli.sh message discord servers lists all Discord servers I'm in, not just the ones I own.

@JLKwong
Copy link
Member

JLKwong commented Mar 29, 2021

  • channels - list all channels in the chosen server by the user

./cli.sh message discord channels will return a jq error:

image

./cli.sh message discord channels <server> will include the categories for the channels, not just the channels:

image
image

@JLKwong
Copy link
Member

JLKwong commented Mar 29, 2021

  • read - read all messages in the chosen server and channel

./cli.sh message discord read <server> <channel> reads a limited number of messages, not all of them, and will fail to mark channel as read:

image
image

image

In particular, it fails to read the first new message in a channel:

image

@JLKwong
Copy link
Member

JLKwong commented Mar 29, 2021

  • send - send a message in the chosen server and channel

./cli.sh message discord send <server <channel> <message> sends a message on Discord, but the bash echoes JSON values instead of a success message:

image
image

Copy link
Member

@JLKwong JLKwong left a comment

Choose a reason for hiding this comment

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

All new features work. I left comments on possible improvements.

Copy link
Member

@JLKwong JLKwong left a comment

Choose a reason for hiding this comment

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

Need to add new subcommands to:

_treehouses
README.md
help.sh
message.sh (message_help)

@rjpadilla
Copy link
Member Author

  • servers - list all servers owned by the user

./cli.sh message discord servers lists all Discord servers I'm in, not just the ones I own.
My bad, I meant the servers the user is joined in, not server ownership 🤦. I'll correct that step.

@rjpadilla
Copy link
Member Author

  • channels - list all channels in the chosen server by the user

./cli.sh message discord channels will return a jq error:

image

./cli.sh message discord channels <server> will include the categories for the channels, not just the channels:

image
image

  1. An argument is required after channels. I will update it to be more specific and produce an error handler.
  2. Yes that'll be something that I'll try to fix on the next integration.

@rjpadilla
Copy link
Member Author

  • read - read all messages in the chosen server and channel

./cli.sh message discord read <server> <channel> reads a limited number of messages, not all of them, and will fail to mark channel as read:

image
image

image

In particular, it fails to read the first new message in a channel:

image

I will need to check up on the documentation to see the limitations on how far back the message history goes.

@rjpadilla
Copy link
Member Author

  • send - send a message in the chosen server and channel

./cli.sh message discord send <server <channel> <message> sends a message on Discord, but the bash echoes JSON values instead of a success message:

image
image

You're right. I'll put in a success message in the output if the command is executed correctly.

@rjpadilla
Copy link
Member Author

Need to add new subcommands to:

_treehouses
README.md
help.sh
message.sh (message_help)

I'm holding off on this until @dogi decides if he wants to use the user token(this implementation) or use the Oauth/Bot for the API token.

Copy link
Member

@JLKwong JLKwong left a comment

Choose a reason for hiding this comment

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

All features work when tested. I made some optional suggestions. Waiting on @dogi to decide whether to use the user token (this implementation) or use the Oauth/Bot for the API token.

@rjpadilla rjpadilla changed the title treehouses message discord [servers|channels|read|send] new subcommands treehouses message discord [servers|channels|read|send] new subcommands (fixes ##2152) Mar 29, 2021
@rjpadilla rjpadilla changed the title treehouses message discord [servers|channels|read|send] new subcommands (fixes ##2152) treehouses message discord [servers|channels|read|send] new subcommands (fixes #2152) Mar 29, 2021
@rjpadilla
Copy link
Member Author

  • read - read all messages in the chosen server and channel

./cli.sh message discord read <server> <channel> reads a limited number of messages, not all of them, and will fail to mark channel as read:

@JLKwong looked at the documentation and I believe it defaults to 50 messages.
Reference -> https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

./cli.sh message discord send "OLE Test" "general" "Hello World!" will fail if there is more than one channel with the same name.

image

Success case: general and General channels (different case)
image

Failure case: general and general` channels (exact names)
image

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

  • channels - list all channels in the chosen server by the user

./cli.sh message discord channels will return a jq error:
image
./cli.sh message discord channels <server> will include the categories for the channels, not just the channels:
image
image

  1. An argument is required after channels. I will update it to be more specific and produce an error handler.
  2. Yes that'll be something that I'll try to fix on the next integration.

./cli.sh message discord channels "OLE Test" will only return 1 general when there is more than one channel with the exact name.
image
image

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

./cli.sh message discord channels "RJPadilla's Super Secret Server" will return a JQ error (attempted to display channels for non-existent server that I'm not in):

jq: error (at <stdin>:1): Cannot index string with string "type"

image

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

./cli.sh message discord channels "OLE Test" lists only text channels in an arbitrary order and omits voice channels instead of (1) including voice channels, (2) order channels by category, (3) grouping text channels together, and (4) grouping voice channels together:

image

Test with only text channels:
image

Test with both text & voice channels:
image

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

  • read - read all messages in the chosen server and channel

./cli.sh message discord read <server> <channel> reads a limited number of messages, not all of them, and will fail to mark channel as read:
image
image
image
In particular, it fails to read the first new message in a channel:
image

I will need to check up on the documentation to see the limitations on how far back the message history goes.

./cli.sh message discord read <server> <channel> could have an optional sub-sub-subcommand to specify number of channels to display (documentation says it can be from 1 to 100).

Copy link
Member

@JLKwong JLKwong left a comment

Choose a reason for hiding this comment

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

I left recommendations based on testing.

@rjpadilla
Copy link
Member Author

I left recommendations based on testing.

cursedwojak

@JLKwong
Copy link
Member

JLKwong commented Mar 31, 2021

I left recommendations based on testing.

cursedwojak

28-286335_view-samegoogleiqdbsaucenao-yvkevqi-blob-sweat-emoji-discord

Copy link
Member

@JLKwong JLKwong left a comment

Choose a reason for hiding this comment

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

I will create PR's for my suggestions after @dogi merges this PR.

@JLKwong
Copy link
Member

JLKwong commented Apr 3, 2021

@rjpadilla It seems that the Discord authorization token expires after a while. I've been running while true; do ./cli.sh message discord send "Ace Fam!" "bots" 'p!fish'; sleep 60; done for about 5 hours:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants