Skip to content

Commit a172b7d

Browse files
committed
Merge branch 'python3.4'
2 parents a02bd8b + 5cd8d1b commit a172b7d

22 files changed

Lines changed: 126 additions & 484 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ persist/
5555
logs/
5656
config.json
5757
*.db
58+
*.mmdb
5859
*.log
5960
.idea/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Changelog
2+
- **1.0.2** - Minor internal changes and fixes, banished minecraft_bukget and worldofwarcraft to CloudBotIRC/Plugins
3+
- **1.0.1** - Fix history.py tracking
4+
- **1.0.0** - Initial stable release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CloudBot
22

3-
CloudBot is a simple, fast, extendable open-source Python IRC Bot!
3+
CloudBot is a simple, fast, expandable open-source Python IRC Bot!
44

55
## Getting CloudBot
66

cloudbot/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
import warnings
32

43
# check python version
54
if sys.version_info < (3, 4, 0):
@@ -11,7 +10,7 @@
1110
import logging
1211
import os
1312

14-
__version__ = "1.0.0 Stable"
13+
__version__ = "1.0.2"
1514

1615
__all__ = ["util", "bot", "connection", "config", "permissions", "plugin", "event", "hook", "log_dir"]
1716

cloudbot/util/filesize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
]
100100

101101

102-
def size(bytes, system=traditional):
102+
def size(b, system=traditional):
103103
"""Human-readable file size.
104104
105105
Using the traditional system, where a factor of 1024 is used::
@@ -150,9 +150,9 @@ def size(bytes, system=traditional):
150150
151151
"""
152152
for factor, suffix in system:
153-
if bytes >= factor:
153+
if b >= factor:
154154
break
155-
amount = int(bytes / factor)
155+
amount = int(b / factor)
156156
if isinstance(suffix, tuple):
157157
singular, multiple = suffix
158158
if amount == 1:

cloudbot/util/formatting.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ def truncate(content, length=100, suffix='...'):
168168
strip_colors = strip_irc
169169

170170

171+
def chunk_str(content, length=420):
172+
"""
173+
Chunks a string into smaller strings of given length. Returns chunks.
174+
:rtype list
175+
"""
176+
def chunk(c, l):
177+
while c:
178+
out = (c+' ')[:l].rsplit(' ', 1)[0]
179+
c = c[len(out):].strip()
180+
yield out
181+
return list(chunk(content, length))
182+
183+
171184
def pluralize(num=0, text=''):
172185
"""
173186
Takes a number and a string, and pluralizes that string using the number and combines the results.

cloudbot/util/timeformat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def format_time(seconds, count=3, accuracy=6, simple=False):
107107
strings = []
108108
i = 0
109109
for period_name, period_seconds in periods:
110-
print(i, period_name)
111110
if i < count:
112111
if seconds > period_seconds:
113112
period_value, seconds = divmod(seconds, period_seconds)

plugins/amazon.py

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

1212
@hook.command("amazon", "az")
1313
def amazon(text):
14-
""" <query> -- Searches Amazon for query"""
14+
"""<query> -- Searches Amazon for query"""
1515
headers = {
1616
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, '
1717
'like Gecko) Chrome/22.0.1229.79 Safari/537.4',

plugins/geoip.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121

2222
def fetch_db():
23-
logger.info("fetch called")
2423
if os.path.exists(PATH):
2524
os.remove(PATH)
2625
r = requests.get(DB_URL, stream=True)
@@ -34,28 +33,23 @@ def update_db():
3433
"""
3534
Updates the DB.
3635
"""
37-
try:
38-
if os.path.isfile(PATH):
39-
# check if file is over 2 weeks old
40-
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
41-
# geoip is outdated, re-download
42-
fetch_db()
43-
return geoip2.database.Reader(PATH)
44-
else:
45-
try:
46-
return geoip2.database.Reader(PATH)
47-
except:
48-
# issue loading, geo
49-
fetch_db()
50-
return geoip2.database.Reader(PATH)
51-
else:
52-
# no geoip file
53-
print("calling fetch_db")
36+
if os.path.isfile(PATH):
37+
# check if file is over 2 weeks old
38+
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
39+
# geoip is outdated, re-download
5440
fetch_db()
55-
print("fetch_db finished")
5641
return geoip2.database.Reader(PATH)
57-
except Exception as e:
58-
print("GEOERROR" + e)
42+
else:
43+
try:
44+
return geoip2.database.Reader(PATH)
45+
except:
46+
# issue loading, geo
47+
fetch_db()
48+
return geoip2.database.Reader(PATH)
49+
else:
50+
# no geoip file
51+
fetch_db()
52+
return geoip2.database.Reader(PATH)
5953

6054

6155
def check_db(loop):

plugins/help.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44

55
from cloudbot import hook
6+
from cloudbot.util import formatting
67

78

89
@asyncio.coroutine
@@ -37,13 +38,7 @@ def help_command(text, conn, bot, notice, has_permission):
3738
else:
3839
notice("Unknown command '{}'".format(searching_for))
3940
else:
40-
41-
# list of lines to send to the user
42-
lines = []
43-
# current line, containing words to join with " "
44-
current_line = []
45-
# current line length, to count how long the current line will be when joined with " "
46-
current_line_length = 0
41+
commands = []
4742

4843
for plugin in sorted(set(bot.plugin_manager.commands.values()), key=attrgetter("name")):
4944
# use set to remove duplicate commands (from multiple aliases), and sorted to sort by name
@@ -62,22 +57,12 @@ def help_command(text, conn, bot, notice, has_permission):
6257

6358
# add the command to lines sent
6459
command = plugin.name
65-
added_length = len(command) + 2 # + 2 to account for space and comma
6660

67-
if current_line_length + added_length > 450:
68-
# if line limit is reached, add line to lines, and reset
69-
lines.append(", ".join(current_line) + ",")
70-
current_line = []
71-
current_line_length = 0
61+
commands.append(command)
7262

73-
current_line.append(command)
74-
current_line_length += added_length
75-
76-
if current_line:
77-
# make sure to include the last line
78-
lines.append(", ".join(current_line))
63+
# list of lines to send to the user
64+
lines = formatting.chunk_str("Here's a list of commands you can use: " + ", ". join(commands))
7965

80-
notice("Here's a list of commands you can use:")
8166
for line in lines:
8267
notice(line)
8368
notice("For detailed help, use {}help <command>, without the brackets.".format(conn.config["command_prefix"]))

0 commit comments

Comments
 (0)