Skip to content

Commit

Permalink
calc: make Tumbolia (Oblique) URL configurable
Browse files Browse the repository at this point in the history
For Sopel instances that want a bit more resilience (and that want/need
the `.py` command to be available—two sets that likely have little
overlap, to be fair), the Oblique service location is now configurable.

Lives in the `[calc]` section, because nothing else uses it.
  • Loading branch information
dgw committed Apr 23, 2019
1 parent 6edca1a commit 0d4fc85
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sopel/modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
calc.py - Sopel Calculator Module
Copyright 2008, Sean B. Palmer, inamidst.com
Copyright 2019, dgw, technobabbl.es
Licensed under the Eiffel Forum License 2.
https://sopel.chat
Expand All @@ -12,6 +13,7 @@

from requests import get

from sopel.config.types import StaticSection, ValidatedAttribute
from sopel.module import commands, example
from sopel.tools.calculation import eval_equation

Expand All @@ -27,7 +29,14 @@ def quote(s):
unichr = chr


BASE_TUMBOLIA_URI = 'https://tumbolia-sopel.appspot.com/'
class CalcSection(StaticSection):
oblique_url = ValidatedAttribute('oblique_url',
default='https://tumbolia-sopel.appspot.com/')
"""Full URL of the Oblique service instance to use for Python evaluation"""


def setup(bot):
bot.config.define_section('calc', CalcSection)


@commands('c', 'calc')
Expand Down Expand Up @@ -62,7 +71,7 @@ def py(bot, trigger):
return bot.say("Need an expression to evaluate")

query = trigger.group(2)
uri = BASE_TUMBOLIA_URI + 'py/'
uri = bot.config.calc.oblique_url + 'py/'
answer = get(uri + quote(query)).content.decode('utf-8')
if answer:
# bot.say can potentially lead to 3rd party commands triggering.
Expand Down

0 comments on commit 0d4fc85

Please sign in to comment.