Skip to content

Commit

Permalink
Convert to Sopel 7+ URL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed May 16, 2020
1 parent 13ae69b commit a5f6b71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests
sopel
sopel>=7,<8
14 changes: 5 additions & 9 deletions sopel_modules/imdb/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

import re
import requests
from sopel.module import commands, example, rule
from sopel.module import commands, example, url
from sopel.config.types import StaticSection, ValidatedAttribute
from sopel.logger import get_logger
from sopel.tools import SopelMemory


LOGGER = get_logger(__name__)

yearfmt = re.compile(r'\(?(\d{4})\)?')
imdb_re = re.compile(r'.*(https?:\/\/(www\.)?imdb\.com\/title\/)(tt[0-9]+).*')
imdb_re = re.compile(r'https?:\/\/(www\.)?imdb\.com\/title\/)(tt[0-9]+)')


class IMDBSection(StaticSection):
Expand All @@ -34,9 +33,6 @@ def configure(config):

def setup(bot):
bot.config.define_section('imdb', IMDBSection)
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = SopelMemory()
bot.memory['url_callbacks'][imdb_re] = imdb_re


def shutdown(bot):
Expand Down Expand Up @@ -122,9 +118,9 @@ def run_omdb_query(params, verify_ssl, api_key, add_url=True):
return message


@rule(imdb_re)
def imdb_url(bot, trigger, found_match=None):
match = found_match or trigger
@url(imdb_re)
def imdb_url(bot, trigger, match=None):
match = match or trigger

if bot.config.imdb.api_key is None or bot.config.imdb.api_key == '':
return bot.reply("OMDb API key missing. Please configure this module.")
Expand Down

0 comments on commit a5f6b71

Please sign in to comment.