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

help: choose pastebin service for .help output #1451

Merged
merged 12 commits into from
Apr 19, 2019
Merged

help: choose pastebin service for .help output #1451

merged 12 commits into from
Apr 19, 2019

Conversation

uint
Copy link

@uint uint commented Jan 15, 2019

Description

I've created a new config section help with the output setting. output can currently be set to:

  • "ptpb"
  • "0x0"
  • "hastebin"
  • "termbin"

This resolves #1416.

Example

19:42 <uint> .set help.output termbin
19:42 <uint> .help
19:43 <uint-bot> Hang on, I'm creating a list.
19:43 <uint-bot> I've posted a list of my commands at https://termbin.com/3tyx2 - You can see more
                 info about any of these commands by doing .help <command> (e.g. .help time)

Potential problems

It seems that if I use .help, the bot will cache the url. If I then change the output option to something else, the bot won't let me use the new service since it still has the old link cached. This could lead to problems if the old link is erroneous and the user can't get a new one until they restart the bot.

@dgw Is it possible to make it so that changing the config option also triggers the cached data to be cleared? I think that would be the simplest solution.

Next steps?

  • We probably really should add an option for the bot to simply "say" the command list, either in the channel or a private message. Should I work on that too?

Version

19:51 <uint> .version
19:51 <uint-bot> uint: Sopel v. 6.5.3

@HumorBaby
Copy link
Contributor

In regards to the caching issue: Sopel won't re-read a config file after editing manually (that I know of). The main way to change the config on the fly is to use things like .set and .save from the admin.py module. This will update the configuration object used by the bot and allow you to save said changes to the config. Ideally this is how .help paste provides will be changed by the user also.

One solution could be to store the current pastebin provider right next to the cached URL, and check if the current config.help.output matches the cached value you have stored before sending. This alternative would make it so the config load/update logic would not need to be changed, as this could be implemented purely in help.py.

@uint
Copy link
Author

uint commented Jan 16, 2019

@HumorBaby What I could do is change help.py so that it caches both the url and the string denoting the pastebin provider. Then I can very easily make sure the cache is only used if the cached provider matches the one currently configured. Does that sound sane?

@HumorBaby
Copy link
Contributor

@uint, yep 😄

@uint
Copy link
Author

uint commented Jan 16, 2019

On rereading your post, that's exactly what you suggested ;) There goes my reading comprehension. But yeah. I'll add a commit soon.

@kwaaak
Copy link
Contributor

kwaaak commented Jan 24, 2019

hastebin.com had an interruption a few days ago, posting was returning a 503 error.

I wonder if it would be a good idea to - if there is no service configured - randomly pick a service, and try another one if there is an error.

sopel/modules/help.py Outdated Show resolved Hide resolved
@dgw dgw added the Feature label Jan 29, 2019
@dgw dgw added this to the 7.0.0 milestone Jan 29, 2019
@dgw
Copy link
Member

dgw commented Mar 9, 2019

After 6.6.4 is released and its changes merged to master, this should be rebased (it probably will gain a merge conflict or three because of #1495).

Also, ptpb is shut down (semi-?)permanently (ptpb/pb#246), so it would be good to remove that option. Maybe replace it with clbin?

@dgw
Copy link
Member

dgw commented Mar 27, 2019

@uint *poke*

@dgw
Copy link
Member

dgw commented Apr 19, 2019

Rebased and "squashed" the whitespace-fix commits (not actually squashed, since both batches of fixed applied to multiple commits each).

Next will be removing ptpb and adding… something else. Like clbin.

(Edited/rebased to switch default from ptpb -> clbin, and whitespace
fixed, by dgw)

Co-Authored-By: dgw <dgw@technobabbl.es>
@dgw
Copy link
Member

dgw commented Apr 19, 2019

And ptpb->clbin default change: done

@dgw dgw requested a review from a team April 19, 2019 00:36
Tomasz Kurcz and others added 4 commits April 18, 2019 19:40
(Rebased, default changed from ptpb->clbin, 0x0 switched to HTTPS, and
whitespace fixed by dgw)

Co-Authored-By: dgw <dgw@technobabbl.es>
(Rebased, default changed from ptpb->clbin, 0x0 switched to HTTPS, and
whitespace fixed by dgw)

Co-Authored-By: dgw <dgw@technobabbl.es>
(Rebased and whitespace fixed by dgw)

Co-Authored-By: dgw <dgw@technobabbl.es>
(Rebased and whitespace fixed by dgw)

Co-Authored-By: dgw <dgw@technobabbl.es>
Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

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

One (optional) change requested for consistency and two (I would like to say required, at least in one form or another) changes requested for proper error handling of the low-level socket for termbin.

The overarching theme of this review is.... 🎰 error handling!

sopel/modules/help.py Outdated Show resolved Hide resolved
sopel/modules/help.py Outdated Show resolved Hide resolved
sopel/modules/help.py Outdated Show resolved Hide resolved
Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

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

Imagine this was a part of the previous review... 🍄

sopel/modules/help.py Outdated Show resolved Hide resolved
dgw added 5 commits April 19, 2019 01:27
All `requests.post()` calls moved to a wrapper that catches all the
appropriate exception types and re-raises them as `PostingException` to
simplify the error handling across callers.

Termbin socket operations wrapped in a try/except, which will re-raise
any error as a `PostingException` just like any other supported service.
Tomasz Kurcz definitely contributed enough code to be included here.
Also took the liberty of including myself, since I'm rewriting a fair
chunk of the new pastebin code.
Sometimes it depends on whether you called the API over HTTP or HTTPS.
Sometimes the site just wants to save on HTTPS overhead by returning a
URL with `http://`, hoping nobody will notice/care and correct it.

We always call over HTTPS, but we'll make sure any valid response is
acceptable (with or without the `s`) and enforce HTTPS before output.
`_pastebin_providers` -> `PASTEBIN_PROVIDERS`

`s` (for socket object) -> `sock`
@dgw
Copy link
Member

dgw commented Apr 19, 2019

@HumorBaby Did a pretty big overhaul of error handling, and a few other little things while I was at it. 🚀

Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Just some nitpicks. But I approve otherwise.

sopel/modules/help.py Outdated Show resolved Hide resolved
sopel/modules/help.py Show resolved Hide resolved
sopel/modules/help.py Outdated Show resolved Hide resolved
This is just "by convention" stuff, nothing substantive.
Copy link
Contributor

@HumorBaby HumorBaby left a comment

Choose a reason for hiding this comment

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

🏆 :shipit:

Misc. notes: At first, I was worried that @dgw improperly capitalized Hastebin 😱, but alas, since it seems to be a descendant of Haste, I have now come around to accepting the current capitalization.

@uint
Copy link
Author

uint commented Apr 19, 2019

Hey. Sorry for not having been responsive! Pretty busy and I... probably should configure e-mail notifications. Ahem.

@Exirel
Copy link
Contributor

Exirel commented Apr 19, 2019

@uint no worry! Our dear maintainer @dgw took it from where you left, co-authored the first commits and added some more. Also thank you for these first commits! 👍

@dgw
Copy link
Member

dgw commented Apr 19, 2019

@uint You got us 90% of the way there! Most of what I did was just sanding off rough edges. 🙌 Without your initial set of commits, this feature would still be "Patches Welcome", but it's done!

As for non-pastebin help output, we are tracking that in #1212. I think @RustyBower is working on something for that, unless he changed his mind. Feel free to join us in the #sopel IRC channel on freenode if you want to avoid duplicating effort on any future contributions. And thank you again for this PR!

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

Successfully merging this pull request may close these issues.

help: pastebin provider should be configurable
5 participants