pyircbot/pyircbot/modules/LMGTFY.py

34 lines
871 B
Python
Raw Normal View History

2015-09-05 21:44:46 -07:00
#!/ysr/bin/env python3
"""
.. module::LMGTFY
2015-11-01 18:03:11 -08:00
:synopsis: LMGTFY
2015-09-05 21:44:46 -07:00
.. moduleauthor::Nick Krichevsky <nick@ollien.com>
"""
2015-09-05 22:26:19 -07:00
import urllib.parse
2017-11-27 18:58:20 -08:00
from pyircbot.modulebase import ModuleBase, command
from pyircbot.modules.ModInfo import info
2015-09-05 21:44:46 -07:00
BASE_URL = "http://lmgtfy.com/?q="
2017-01-01 14:59:01 -08:00
2015-09-05 21:44:46 -07:00
class LMGTFY(ModuleBase):
2017-11-27 18:58:20 -08:00
@info("lmgtfy <term> display a condescending internet query", cmds=["lmgtfy"])
@command("lmgtfy", require_args=True)
def handleMessage(self, msg, cmd):
message = msg.trailing.split(" ")[1:]
link = self.createLink(message)
self.bot.act_PRIVMSG(msg.args[0], "%s: %s" % (msg.prefix.nick, link))
2017-01-01 14:59:01 -08:00
2015-11-01 18:03:11 -08:00
def createLink(self, message):
finalUrl = BASE_URL
2015-09-05 21:44:46 -07:00
2015-11-01 18:03:11 -08:00
for word in message:
finalUrl += urllib.parse.quote(word)
if word != message[-1]:
2017-01-01 14:59:01 -08:00
finalUrl += "+"
2015-09-05 21:44:46 -07:00
2015-11-01 18:03:11 -08:00
return finalUrl