Skip to content

Commit f4a406c

Browse files
authored
Merge pull request CloudBotIRC#121 from linuxdaemon/gonzobot+hook-tests
Add basic tests for plugin hook registrations
2 parents 8595d1b + c5cf88a commit f4a406c

59 files changed

Lines changed: 337 additions & 210 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ python:
77

88
install:
99
- "sudo apt-get update -q"
10-
- "sudo apt-get install -y python3-lxml"
10+
- "sudo apt-get install -y python3-lxml libenchant-dev"
1111
- "pip install -r ./travis/requirements.txt"
1212

1313
script:

plugins/badwords.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@hook.on_start()
2121
@hook.command("loadbad", permissions=["badwords"], autohelp=False)
2222
def load_bad(db):
23-
"""Should run on start of bot to load the existing words into the regex"""
23+
"""- Should run on start of bot to load the existing words into the regex"""
2424
global badword_re, blacklist, black_re
2525
words = db.execute("select word from badwords").fetchall()
2626
out = ""
@@ -31,9 +31,9 @@ def load_bad(db):
3131
badwords_re = re.compile(black_re, re.IGNORECASE)
3232

3333

34-
@hook.command("addbad", permissions=["badwords"], autohelp=False)
34+
@hook.command("addbad", permissions=["badwords"])
3535
def add_bad(text, nick, db, conn):
36-
"""adds a bad word to the auto kick list must specify a channel with each word"""
36+
"""<word> <channel> - adds a bad word to the auto kick list must specify a channel with each word"""
3737
global blacklist, black_re, blacklist
3838
word = text.split(' ')[0].lower()
3939
channel = text.split(' ')[1].lower()
@@ -62,9 +62,9 @@ def add_bad(text, nick, db, conn):
6262
channel)
6363

6464

65-
@hook.command("rmbad", "delbad", permissions=["badwords"], autohelp=False)
65+
@hook.command("rmbad", "delbad", permissions=["badwords"])
6666
def del_bad(text, db, conn):
67-
"""removes the specified word from the specified channels bad word list"""
67+
"""<word> <channel> - removes the specified word from the specified channels bad word list"""
6868
global blacklist, black_re, blacklist
6969
word = text.split(' ')[0].lower()
7070
if not (text.split(' ')[1] or text.split(' ')[1]('#')):
@@ -82,9 +82,9 @@ def del_bad(text, db, conn):
8282
newlist)
8383

8484

85-
@hook.command("listbad", permissions=["badwords"], autohelp=False)
85+
@hook.command("listbad", permissions=["badwords"])
8686
def list_bad(text, db):
87-
"""Returns a list of bad words specify a channel to see words for a particular channel"""
87+
"""<channel> - Returns a list of bad words specify a channel to see words for a particular channel"""
8888
text = text.split(' ')[0].lower()
8989
out = ""
9090
if not text.startswith('#'):

plugins/bible.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from cloudbot import hook
44

5+
56
@hook.command("bible", "passage", singlethread=True)
67
def bible(text, reply):
7-
"""Prints the specified passage from the Bible"""
8+
"""<passage> - Prints the specified passage from the Bible"""
89
passage = text.strip()
910
params = {
10-
'passage':passage,
11-
'formatting':'plain',
12-
'type':'json'
11+
'passage': passage,
12+
'formatting': 'plain',
13+
'type': 'json'
1314
}
1415
try:
1516
r = requests.get("https://labs.bible.org/api", params=params)

plugins/books.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def load_key(bot):
1616

1717
@hook.command("books", "gbooks")
1818
def books(text, reply):
19-
"""books <query> -- Searches Google Books for <query>."""
19+
"""<query> - Searches Google Books for <query>."""
2020
if not dev_key:
2121
return "This command requires a Google Developers Console API key."
2222

plugins/cats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_data(url, reply, bot, params=None):
1717

1818
@hook.command(autohelp=False)
1919
def cats(reply, bot):
20-
"""gets a fucking fact about cats."""
20+
"""- gets a fucking fact about cats."""
2121
r = get_data('https://catfact.ninja/fact', reply, bot, params={'max_length': 100})
2222
json = r.json()
2323
response = json['facts']
@@ -26,6 +26,6 @@ def cats(reply, bot):
2626

2727
@hook.command(autohelp=False)
2828
def catgifs(reply, bot):
29-
"""gets a fucking cat gif."""
29+
"""- gets a fucking cat gif."""
3030
r = get_data("http://marume.herokuapp.com/random.gif", reply, bot)
3131
return "OMG A CAT GIF: {}".format(r.url)

plugins/chatbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_key(bot):
99

1010
@hook.command("ask", "gonzo", "gonzobot", "cleverbot", "cb")
1111
def chitchat(text):
12-
"""chat with cleverbot.com"""
12+
"""<text> - chat with cleverbot.com"""
1313
if not api_key:
1414
return "Please add an API key from http://www.cleverbot.com/api to enable this feature."
1515
return cb.say(text)

plugins/core/check_conn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@hook.command(autohelp=False, permissions=["botcontrol"])
99
def conncheck(nick, bot, notice):
10-
"""This command is an effort to make the bot reconnect to a network if it has been disconnected."""
10+
"""- This command is an effort to make the bot reconnect to a network if it has been disconnected."""
1111
# For each irc network return a notice on the connection state and send a message from
1212
# each connection to the nick that used the command.
1313
for conn in bot.connections:

plugins/core/help.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def help_command(text, chan, conn, bot, notice, message, has_permission):
6262
commands.append(command)
6363

6464
# list of lines to send to the user
65-
lines = formatting.chunk_str("Here's a list of commands you can use: " + ", ". join(commands))
65+
lines = formatting.chunk_str("Here's a list of commands you can use: " + ", ".join(commands))
6666

6767
for line in lines:
6868
if chan[:1] == "#":
6969
notice(line)
7070
else:
71-
#This is an user in this case.
71+
# This is an user in this case.
7272
message(line)
7373
notice("For detailed help, use {}help <command>, without the brackets.".format(conn.config["command_prefix"]))
7474

@@ -114,11 +114,11 @@ def cmdinfo(text, bot, notice, event):
114114

115115
@hook.command(permissions=["botcontrol"], autohelp=False)
116116
def generatehelp(conn, bot, notice, has_permission):
117-
"""Dumps a list of commands with their help text to the docs directory formatted using markdown."""
117+
"""- Dumps a list of commands with their help text to the docs directory formatted using markdown."""
118118
message = "{} Command list\n".format(conn.nick)
119119
message += "------\n"
120120
for plugin in sorted(set(bot.plugin_manager.commands.values()), key=attrgetter("name")):
121-
# use set to remove duplicate commands (from multiple aliases), and sorted to sort by name
121+
# use set to remove duplicate commands (from multiple aliases), and sorted to sort by name
122122
command = plugin.name
123123
aliases = ""
124124
doc = bot.plugin_manager.commands[command].doc
@@ -133,8 +133,8 @@ def generatehelp(conn, bot, notice, has_permission):
133133
aliases += alias + ", "
134134
aliases = aliases[:-2]
135135
if doc:
136-
doc = doc.replace("<","&lt;").replace(">","&gt;") \
137-
.replace("[", "&lt;").replace("]","&gt;")
136+
doc = doc.replace("<", "&lt;").replace(">", "&gt;") \
137+
.replace("[", "&lt;").replace("]", "&gt;")
138138
if aliases:
139139
message += "**{} ({}):** {}\n\n".format(command, aliases, doc)
140140
else:
@@ -146,10 +146,10 @@ def generatehelp(conn, bot, notice, has_permission):
146146
message = message[:-2]
147147
message += " ( *Permission required:* {})\n\n".format(permission)
148148
# toss the markdown text into a paste
149-
#out = web.paste(message.encode('utf-8'), ext="md")
149+
# out = web.paste(message.encode('utf-8'), ext="md")
150150
docs = os.path.join(os.path.abspath(os.path.curdir), "docs")
151151
docs = os.path.join(docs, "user")
152152
f = open(os.path.join(docs, "commands.md"), 'w')
153153
f.write(message)
154154
f.close()
155-
return #out
155+
return # out

plugins/dig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@hook.command
77
def dig(text, nick, notice):
8-
""".dig <domain> <recordtype> returns a list of records for the specified domain valid record types are A, NS, TXT, and MX. If a record type is not chosen A will be the default."""
8+
"""<domain> <recordtype> - returns a list of records for the specified domain valid record types are A, NS, TXT, and MX. If a record type is not chosen A will be the default."""
99
args = text.split()
1010
domain = args.pop(0)
1111

plugins/dogpile.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import requests
21
import random
32
import re
43
from urllib import parse
4+
5+
import requests
56
from bs4 import BeautifulSoup
7+
68
from cloudbot import hook
79

810
search_url = "http://dogpile.com/search"
911

10-
HEADERS = {'User-Agent': 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19'}
12+
HEADERS = {
13+
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19'
14+
}
15+
1116

1217
@hook.command("dpis", "gis")
1318
def dogpileimage(text):
14-
"""Uses the dogpile search engine to search for images."""
19+
"""<query> - Uses the dogpile search engine to search for images."""
1520
image_url = search_url + "/images"
1621
params = {'q': " ".join(text.split())}
1722
r = requests.get(image_url, params=params, headers=HEADERS)
@@ -20,18 +25,21 @@ def dogpileimage(text):
2025
data = soup.find_all("script")[6].string
2126
link_re = re.compile('"url":"(.*?)",')
2227
linklist = link_re.findall(data)
23-
#linklist = soup.find('div', id="webResults").find_all('a', {'class':'resultThumbnailLink'})
28+
# linklist = soup.find('div', id="webResults").find_all('a', {'class':'resultThumbnailLink'})
2429
image = parse.unquote(parse.unquote(random.choice(linklist)).split('ru=')[1].split('&')[0])
2530
return image
2631

32+
2733
@hook.command("dp", "g", "dogpile")
2834
def dogpile(text):
29-
"""Uses the dogpile search engine to find shit on the web."""
35+
"""<query> - Uses the dogpile search engine to find shit on the web."""
3036
web_url = search_url + "/web"
31-
params = {'q':" ".join(text.split())}
37+
params = {'q': " ".join(text.split())}
3238
r = requests.get(web_url, params=params, headers=HEADERS)
3339
r.raise_for_status()
3440
soup = BeautifulSoup(r.content)
35-
result_url = parse.unquote(parse.unquote(soup.find('div', id="webResults").find_all('a', {'class':'resultDisplayUrl'})[0]['href']).split('ru=')[1].split('&')[0])
36-
result_description = soup.find('div', id="webResults").find_all('div', {'class':'resultDescription'})[0].text
41+
result_url = parse.unquote(
42+
parse.unquote(soup.find('div', id="webResults").find_all('a', {'class': 'resultDisplayUrl'})[0]['href']).split(
43+
'ru=')[1].split('&')[0])
44+
result_description = soup.find('div', id="webResults").find_all('div', {'class': 'resultDescription'})[0].text
3745
return "{} -- \x02{}\x02".format(result_url, result_description)

0 commit comments

Comments
 (0)