sopel-plugins/cytat#.py

30 lines
922 B
Python

# coding=utf-8
# https://pypi.org/project/wikiquote/
# https://pypi.org/project/sopel/
# Author xmszkn(at)disroot.org
# GPLv3 license
from sopel import plugin, tools # sopel modules
import wikiquote # from wikiquote
import random
@plugin.command('cytat')
@plugin.action_command('cytat')
@plugin.example('.cytat', r'¯\_(ツ)_/¯')
def cytat(bot, trigger):
query = trigger.group(2)
if not query:
bot.reply('Podaj zapytanie (autor, pojęcie)')
return
autor_znal = wikiquote.search(query, lang='pl')
if len(autor_znal) == 0:
bot.say('Nie ma cytatu odpowiadającego twojemu zapytaniu.')
return
autor_def = (autor_znal[0])
cytat = wikiquote.quotes((autor_def), lang='pl')
if len(cytat) == 0:
bot.say('Nie ma cytatu odpowiadającego twojemu zapytaniu.')
return
answer = random.choice(wikiquote.quotes((autor_def), lang='pl'))
bot.say(answer)