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 6b0a89b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 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
15 changes: 4 additions & 11 deletions sopel_modules/imdb/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

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]+).*')


class IMDBSection(StaticSection):
Expand All @@ -34,9 +32,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,14 +117,12 @@ 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(r'https?:\/\/(?:www\.)?imdb\.com\/title\/(tt[0-9]+)')
def imdb_url(bot, trigger, match=None):
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.")

bot.say(run_omdb_query({'i': match.group(3)}, bot.config.core.verify_ssl, bot.config.imdb.api_key, False))
bot.say(run_omdb_query({'i': match.group(1)}, bot.config.core.verify_ssl, bot.config.imdb.api_key, False))


if __name__ == "__main__":
Expand Down

0 comments on commit 6b0a89b

Please sign in to comment.