This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Bytespeicher/refactor-irc3
Refactor irc3
- Loading branch information
Showing
6 changed files
with
85 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8 -*- | ||
|
||
from plugins.plugin import Plugin | ||
from bytebot_config import BYTEBOT_PLUGIN_CONFIG | ||
import requests | ||
import urllib | ||
|
||
|
||
class wikipedia(Plugin): | ||
""" | ||
With this plugin you can search for wikipedia entries. | ||
""" | ||
def __init__(self): | ||
pass | ||
|
||
def registerCommand(self, irc): | ||
irc.registerCommand( | ||
'!wiki TOPIC', | ||
'wikipedia article summary for TOPIC' | ||
) | ||
|
||
def onPrivmsg(self, irc, msg, channel, user): | ||
if msg.find('!wiki') == -1: | ||
return | ||
|
||
self.irc = irc | ||
self.channel = channel | ||
|
||
config = BYTEBOT_PLUGIN_CONFIG['wikipedia'] | ||
|
||
if msg.find(' ') == -1: | ||
irc.msg(channel, 'usage: !wiki TOPIC') | ||
return | ||
else: | ||
request = " ".join(msg.split(' ')[1:]) | ||
|
||
url = config['url'] + urllib.quote(request) | ||
|
||
try: | ||
r = requests.get(url) | ||
|
||
if r.status_code != 200: | ||
irc.msg(channel, 'Error while retrieving wikipedia data') | ||
return | ||
|
||
w = r.json()["query"]["pages"] | ||
text = w[list(w.keys())[0]]["extract"][0:300] | ||
text = text[0:text.rfind(" ")] + "[. . .]" | ||
|
||
except KeyError: | ||
irc.msg(channel, "Error while retrieving wikipedia data") | ||
return | ||
|
||
irc.msg(channel, "%s: %s" % (request, text)) |