Browse Source

Remove a few broken modules

master
sfan5 6 years ago
parent
commit
c35bb87af1
  1. 7
      COMMANDS.md
  2. 72
      search.py
  3. 93
      twitter.py

7
COMMANDS.md

@ -5,7 +5,7 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in [
<i>$botname</i> refers to the name of the IRC bot, e.g. MinetestBot
<table>
<tr> <th>Command</th> <th>Description</th> <th>Usable by</th> </tr>
<tr> <th>Command</th> <th>Description</th> <th>Usable by</th> </tr>
<tr> <td><b>admin.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!join {channel} [channel-key]</td> <td>Join the specified channel</td> <td><i>Admins</i></td> </tr>
<tr> <td>!part {channel}</td> <td>Leave the specified channel</td> <td><i>Admins</i></td> </tr>
@ -43,9 +43,6 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in [
<tr> <td>!b16d {string}</td> <td>Base16-decode a string</td> <td>Anyone</td> </tr>
<tr> <td>!hash {hashtype} {string}</td> <td>Hash a string, supports various hash functions</td> <td>Anyone</td> </tr>
<tr> <td>!rand [min] {max}</td> <td>Says a random number between(incl.) min and max</td> <td>Anyone</td> </tr>
<tr> <td><b>search.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!g {string}</td> <td>Output first Google result for string</td> <td>Anyone</td> </tr>
<tr> <td>!gc {string}</td> <td>Output Google result count for string</td> <td>Anyone</td> </tr>
<tr> <td><b>seen.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!seen {person}</td> <td>Output when person was last seen</td> <td>Anyone</td> </tr>
<tr> <td><b>server.py</b></td> <td></td> <td></td> </tr>
@ -70,8 +67,6 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in [
<tr> <td></td> <td>Supports multiple Ports e.g. 123-456,999</td> <td></td> </tr>
<tr> <td><b>title.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!title [link]</td> <td>Query Page Title</td> <td>Anyone</td> </tr>
<tr> <td><b>twitter.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!tw {link/username/tweet_id}</td> <td>Query Tweet from Twitter</td> <td>Anyone</td> </tr>
<tr> <td><b>wiki.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!wik {term}</td> <td>Query wiki.minetest.com for term</td> <td>Anyone</td> </tr>
<tr> <td><b>devwiki.py</b></td> <td></td> <td></td> </tr>

72
search.py

@ -1,72 +0,0 @@
#!/usr/bin/env python
"""
search.py - Phenny Web Search Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
Modified by sfan5 2012
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import web
import re
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.urlencode(query)
data, sc = web.get(uri + args)
data = str(data, 'utf-8')
return web.json(data)
def google_search(query):
results = google_ajax(query)
try: return results['responseData']['results'][0]['unescapedUrl']
except IndexError: return None
except TypeError:
return False
def g(phenny, input):
"""Queries Google for the specified input."""
query = input.group(2)
if not query:
return phenny.reply('.g what?')
log.log("event", "%s searched Google for '%s'" % (log.fmt_user(input), query), phenny)
uri = google_search(query)
if uri:
phenny.reply(uri)
phenny.bot.last_seen_uri = uri
elif uri is False: phenny.reply("Problem getting data from Google.")
else: phenny.reply("No results found for '%s'." % query)
g.commands = ['g']
g.priority = 'high'
g.example = '.g minetest'
def gc(phenny, input):
query = input.group(2)
if not query:
return phenny.reply("No query term.")
log.log("event", "%s searched Google for '%s'" % (log.fmt_user(input), query), phenny)
result = new_gc(query)
if result:
phenny.say(query + ": " + result)
else: phenny.reply("Sorry, couldn't get a result.")
def new_gc(query):
uri = 'https://www.google.com/search?hl=en&q='
uri = uri + web.urlencode(query).replace('+', '%2B')
if '"' in query: uri += '&tbs=li:1'
data, sc = web.get(uri)
data = str(data, 'utf-8')
if "did not match any documents" in data:
return "0"
for result in re.compile(r'(?ims)([0-9,]+) results?').findall(data):
return result
return None
gc.commands = ['gc']
gc.priority = 'high'
gc.example = '.gc minetest'
if __name__ == '__main__':
print(__doc__.strip())

93
twitter.py

@ -1,93 +0,0 @@
#!/usr/bin/env python
"""
twitter.py - Phenny Twitter Module
Copyright 2012, Sean B. Palmer, inamidst.com
Modified by sfan5 2012
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import re, time
import web
r_username = re.compile(r'^@[a-zA-Z0-9_]{1,15}$')
r_link = re.compile(r'^https?://twitter.com/\S+$')
r_p = re.compile(r'(?ims)(<p class="js-tweet-text.*?</p>)')
r_tag = re.compile(r'(?ims)<[^>]+>')
r_anchor = re.compile(r'(?ims)(<a.*?</a>)')
r_expanded = re.compile(r'(?ims)data-expanded-url=["\'](.*?)["\']')
r_whiteline = re.compile(r'(?ims)[ \t]+[\r\n]+')
r_breaks = re.compile(r'(?ims)[\r\n]+')
def entity(*args, **kargs):
return web.entity(*args, **kargs)
def decode(html):
return web.r_entity.sub(entity, html)
def expand(tweet):
def replacement(match):
anchor = match.group(1)
for link in r_expanded.findall(anchor):
return link
return r_tag.sub('', anchor)
return r_anchor.sub(replacement, tweet)
def read_tweet(url):
bytes, sc = web.get(url)
bytes = str(bytes, 'utf-8')
shim = '<div class="content clearfix">'
if shim in bytes:
bytes = bytes.split(shim, 1).pop()
for text in r_p.findall(bytes):
text = expand(text)
text = r_tag.sub('', text)
text = text.strip()
text = r_whiteline.sub(' ', text)
text = r_breaks.sub(' ', text)
return decode(text)
return "Sorry, couldn't get a tweet from %s" % url
def format(tweet, username):
return '%s (@%s)' % (tweet, username)
def user_tweet(username):
tweet = read_tweet('https://twitter.com/' + username + "?" + str(time.time()))
return format(tweet, username)
def id_tweet(tid):
link = 'https://twitter.com/twitter/status/' + tid
headers, status = web.head(link)
if status == 301:
if not "Location" in headers:
return "Sorry, couldn't get a tweet from %s" % link
url = headers["Location"]
username = url.split('/')[3]
tweet = read_tweet(url)
return format(tweet, username)
return "Sorry, couldn't get a tweet from %s" % link
def twitter(phenny, input):
arg = input.group(2)
if not arg:
return phenny.reply("Give me a link, a @username, or a tweet id")
arg = arg.strip()
log.log("event", "%s queried Twitter for '%s'" % (log.fmt_user(input), arg), phenny)
if arg.isdigit():
phenny.say(id_tweet(arg))
elif r_username.match(arg):
phenny.say(user_tweet(arg[1:]))
elif r_link.match(arg):
username = arg.split('/')[3]
tweet = read_tweet(arg)
phenny.say(format(tweet, username))
else: phenny.reply("Give me a link, a @username, or a tweet id")
twitter.commands = ['tw', 'twitter']
twitter.thread = True
if __name__ == '__main__':
print(__doc__)
Loading…
Cancel
Save