Giter Site home page Giter Site logo

torgeirl / tradingpost-errbot Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 1.0 656 KB

Bot for Slack that fetches Magic: the Gathering card pictures, oracle texts, prices and flavor texts on request

License: MIT License

Python 94.87% Dockerfile 5.13%
mtg errbot-plugin slack-bot

tradingpost-errbot's People

Contributors

goranfr avatar jvbrink avatar torgeirl avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

goranfr

tradingpost-errbot's Issues

Install randomization repo automatically

Randomization tasks was moved to another plugin in 7d2b9af, but it currently has to be installed manully:

!repos install https://github.com/torgeirl/random-errbot.git

Installing https://github.com/torgeirl/random-errbot.git...
A new plugin repository has been installed correctly from https://github.com/torgeirl/random-errbot.git.
Refreshing the plugins commands...
Plugins reloaded.

!card doesn't work for DFCs in ZNR

!card command doesn't work for DFCs in Zendikar Rising (ZNR). !oracle works for the same cards, and !card works for last DFC in boosters before that (Nicol Bolas, the Ravager) and the original DFCs from ISD block:

INFO     errbot.plugins.ACLs       Matching ACL {} against username @torgeirl for command Tradingpost:card.
INFO     errbot.core               Processing command "card" with parameters "Umara Wizard" from @torgeirl
INFO     errbot.plugins.tradingpost Connecting to https://api.scryfall.com
ERROR    errbot.core               An error happened while processing a message ("!card Umara Wizard"): Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/errbot/core.py", line 477, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 39, in card
    image=card['image_uris']['normal'],
KeyError: 'image_uris'
"
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/errbot/core.py", line 477, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 39, in card
    image=card['image_uris']['normal'],
KeyError: 'image_uris'

INFO     errbot.plugins.ACLs       Matching ACL {} against username @torgeirl for command Tradingpost:card.
INFO     errbot.core               Processing command "card" with parameters "huntmaster of the fells" from @torgeirl

Could be related to the API changes to Scryfall image URIs and download URIs in August.

Provide text arguments along with image responses

If possible, we should provide text arguments along with the image responses of !card and !sutcliffe:

Warning from the execution of !card:

/usr/local/lib/python3.10/site-packages/slack_sdk/web/internal_utils.py:258: UserWarning: The top-level `text` argument is missing in the request payload for a chat.postMessage call - It's a best practice to always provide a `text` argument when posting a message. The `text` argument is used in places where content cannot be rendered such as: system push notifications, assistive technology such as screen readers, etc.
  warnings.warn(message, UserWarning)

Update !sutcliffe for SlackRTM

After switching to the new SlackRTM backend in 644b41c, the!sutcliffe command still doesn't work:

An error happened while processing a message ("!sutcliffe Rampant Growth (M12) / Cultivate"):
(...)
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'method_deprecated', 'response_metadata': {'messages': ['[ERROR] This method is retired and can no longer be used. Please use conversations.list or users.conversations instead. Learn more: https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api.']}}

Github Container Registry

We didn't want to use Github Packages in July since it didn't offer non-authorized pulls.

That changed on September 1, with the introduction to Github Container Registry. It would be nice to remove Docker Hub from the project's workflow.

Echoing from container

Seems to have been introduced after the bot got containerized (issue #12):

TORGEIRL 09:16
!uptime

TRADINGPOST 09:16
I've been up for 37 hours and 23 minutes (since Monday, Aug 31 at 17:53).
I've been up for 37 hours and 23 minutes (since Monday, Aug 31 at 17:53).
I've been up for 37 hours and 23 minutes (since Monday, Aug 31 at 17:53).
I've been up for 37 hours and 23 minutes (since Monday, Aug 31 at 17:53).
I've been up for 37 hours and 23 minutes (since Monday, Aug 31 at 17:53).

Migrate from RTM API to Slack apps and Socket Mode

Trading Post has been prepared for the changes coming to Slack's rtm.start API method in September with Errbot's new SlackV3 backend. However, Slack have been asking us to migrate away from the RTM API for a while now:

While the RTM API will remain unchanged, we do encourage you to migrate to modern Slack apps and Socket Mode instead.

Luckily, the new Errbot backend also supports more modern integration methods such as Slack apps and Socket Mode so it shouldn't require too much work.

Switch to manamoji

The current mana emojis doesn't follow some standard, making the first time setup time consuming. We could instead switch to supporting Scryfall's Manamoji repo, the de facto standard for mana emojis.

It would also make it easy to switch between our and Scryfall's Slack bots, or run them together.

Errbot 6.0.0 upgrades

Errbot 6.0.0 was released yesterday. They dropped support for Python 3.5 so the upgrade to 3.7 I long have delayed needs to come soon, and might require some adjustments.

I hope the fix to dependency handling for Docker installations also solved issue #3 ๐Ÿคž

`!standard` doesn't work

The !standard command (issue #20) no longer works. The backend seems OK and isn't deprecated, but for some reason it no longer is able to calculate the Standard dates:

2021-10-13 12:39:18,618 INFO     errbot.plugins.ACLs       Matching ACL {} against username @torgeirl for command Tradingpost:standard.
2021-10-13 12:39:18,618 INFO     errbot.core               Processing command "standard" with parameters "" from @torgeirl
2021-10-13 12:39:18,619 INFO     errbot.plugins.tradingpost Connecting to https://whatsinstandard.com
2021-10-13 12:39:18,928 ERROR    errbot.core               An error happened while processing a message ("!standard"): Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 555, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 158, in standard
    enter_date = datetime.strptime(set['enterDate']['exact'], rfc3339).date()
TypeError: strptime() argument 1 must be str, not None
"
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/errbot/core.py", line 555, in _execute_and_send
    reply = method(msg, match) if match else method(msg, args)
  File "/app/plugins/tradingpost-errbot/tradingpost.py", line 158, in standard
    enter_date = datetime.strptime(set['enterDate']['exact'], rfc3339).date()
TypeError: strptime() argument 1 must be str, not None

Unable to set multiple admins

The Errbot backend switch from Slack to SlackV3 in we did in January has made it impossible to set more than one bot admin.

It seems the issue is caused by some problem with ACL matching multiple Slack user IDs. SlackV3 issue: errbotio/err-backend-slackv3#63

Update: the issue predate the backend switch, and is now solved.

Some commands only post their replies in-thread

If you write a bot command in reply to a Slack message (thread), the bot currently sends the answer to the channel for some of the commands:

  • !card (using Errbot's send_card) Fixed in Slackv3 v0.2.1 (October 3, 2022) โœ”๏ธ
  • !sutcliffe (using Errbot's send_stream_request)

PWP command fails

HTTPSConnectionPool(host='www.wizards.com', port=443): Max retries exceeded with url: /Magic/PlaneswalkerPoints/JavaScript/GetPointsHistoryModal (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

Github actions tests

Showstoppers like the following should be caught by tests:

$ microk8s.kubectl logs tradingpost-deployment-59886df5b9-5dfrx
2020-10-18 06:34:49,189 INFO     errbot.bootstrap          Found Storage plugin: Shelf.
2020-10-18 06:34:49,197 INFO     errbot.bootstrap          Found Backend plugin: Slack
2020-10-18 06:34:49,245 ERROR    errbot.backends.slack     Could not start the Slack back-end
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/errbot/backends/slack.py", line 24, in <module>
    from slackclient import SlackClient
ModuleNotFoundError: No module named 'slackclient'
2020-10-18 06:34:49,246 CRITICAL errbot.backends.slack     You need to install the slackclient support in order to use the Slack backend.
You can do `pip install errbot[slack]` to install it

Python 3.9

It seems Errbot for Slack doesn't work with Python 3.9 due to a problem with one of Errbot's dependencies; Dulwich:

Step 8/17 : RUN pip install --prefix=/install --no-warn-script-location errbot[slack]==6.1.5
Collecting errbot[slack]==6.1.5
  Downloading errbot-6.1.5-py3-none-any.whl (210 kB)
(...)
Collecting dulwich>=0.19.16
  Downloading dulwich-0.20.6.tar.gz (388 kB)
(...)
Building wheels for collected packages: dulwich, pygments-markdown-lexer, ansi, slackclient, MarkupSafe
  Building wheel for dulwich (setup.py): started
  Building wheel for dulwich (setup.py): finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-orbtbp3w/dulwich/setup.py'"'"'; __file__='"'"'/tmp/pip-install-orbtbp3w/dulwich/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-vm9mzhfc
       cwd: /tmp/pip-install-orbtbp3w/dulwich/

It could look like Python 3.9 doesn't include the same pre-build of Dulwich as 3.8:

Step 8/17 : RUN pip install --prefix=/install --no-warn-script-location errbot[slack]==6.1.5
 ---> Running in d221b509f8f1
Collecting errbot[slack]==6.1.5
  Downloading errbot-6.1.5-py3-none-any.whl (210 kB)
(...)
Collecting dulwich>=0.19.16
  Downloading dulwich-0.20.6-cp38-cp38-manylinux2010_x86_64.whl (504 kB)
(...)
Installing collected packages: (...) dulwich, (...) slackclient, errbot
Successfully installed (...) dulwich-0.20.6 (...) errbot-6.1.5 slackclient-1.3.2

Dependencies don't autoinstall

Errbot automatically installs dependencies if a plugin provides a requirements.txt file.

Even with AUTOINSTALL_DEPS = True it fails (tested with Pillow==5.4.*, already installed in venv):

Some plugins failed to start during bot startup:
<class 'subprocess.CalledProcessError'>: Command '['pip', 'install', '--requirement', '/home/self-assembler/self-assembler-bot/plugins/tradingpost-errbot/requirements.txt']' returned non-zero exit status 2
File "/home/self-assembler/self-assembler-bot/venv/lib/python3.5/site-packages/errbot/plugin_manager.py", line 76, in install_packages subprocess.check_call(['pip', 'install', '--requirement', req_path])
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call raise CalledProcessError(retcode, cmd)

Docker container

Added first draft for a Dockerfile in commit 46034bf, based on Python:3.7-alpine. With multi-stage builds it's down to 136MB vs Python:3.7-slim's 226MB.

Probably going to need some adjustments before it's working well.

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.