MartinHowarth / lyrebot

A discord bot that speaks what you type in your own voice.
MIT License
24 stars 3 forks source link

Avoid copy-pasting URL by hosting local server #4

Open MysteryPancake opened 5 years ago

MysteryPancake commented 5 years ago

I noticed this bot relies on the user copy-pasting the authentication URL to Discord.

This is a great method to avoid the agony of hosting a server, so ignore this issue if you are happy with the current implementation.

I am working on a bot inspired by this one, written in JavaScript. I was initially using the same method. However, it felt quite hacky and prone to errors.

I wanted to recommend the option of hosting a local server, then reading the parameters req.query.code and req.query.state. This allows the user to immediately authenticate without copy-pasting.

Sorry if I'm being a nuisance. I've just been playing around with the API and I feel this is quite a clean and secure method.

(Note that this method requires OAuth 2.0 Authorization code Flow, so it does not work with #1)

MartinHowarth commented 5 years ago

Firstly, you're definitely not being a nuisance - it's great to have other people interested in collaborating on projects :)

I did consider adding a local web server because, as you say, it's cleaner, more secure and less prone to errors. However, I decided that the barrier of getting a static IP or buying a hostname (which would be required to configure the redirect on the lyrebird API) would make it a bit too difficult for others to get started with this bot.

Maybe I could add local web server as an optional thing? Then users can choose to switch over to web based authentication when they want to tackle the associated problems.

Maybe a heroku-hosted version that I make trivial to clone would work well (as you'd get a hostname for free).

What do you think?

MysteryPancake commented 5 years ago

It may be a good idea to have an option for server hosting, but it becomes complicated on Heroku. My cheap knockoff bot can currently be hosted locally or on Heroku, but I came across a number of difficulties in the process:

I first tried hosting the bot and the website through a single web dyno, which makes it easy to communicate between them. I soon discovered Heroku disables web dynos after 30 minutes of inactivity, meaning the bot will be offline unless the authorization website is constantly active.

For the bot to be online for more than 30 minutes, the website must be hosted through a web dyno, and the bot through a worker dyno. The main difficulty is communicating between them. I am trying to get around this by using a MongoDB database, but it quickly becomes complicated.

At the moment this bot would work fine using a single worker dyno, so it may not be worth going through this hassle.

MartinHowarth commented 5 years ago

Yep, I host mine locally (raspberry pi). There are options out there to keep your free heroku dyno alive (e.g. https://www.veerayaaa.com/posts/free-and-easy-ways-to-prevent-heroku-free-dyno-from-sleeping/). But then you only get 20 days a month free, so the free tier doesn't work out anyway.

I think I'll add the web server option for those who do want to do the extra setup though.

HussainMasthan commented 5 years ago

hi how to test this application. where i should send text and get the output.