Skip to content

Commit

Permalink
Merge branch 'python3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmptrluke committed Jan 17, 2015
2 parents a02bd8b + 5cd8d1b commit a172b7d
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 484 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ persist/
logs/
config.json
*.db
*.mmdb
*.log
.idea/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Changelog
- **1.0.2** - Minor internal changes and fixes, banished minecraft_bukget and worldofwarcraft to CloudBotIRC/Plugins
- **1.0.1** - Fix history.py tracking
- **1.0.0** - Initial stable release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CloudBot

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

## Getting CloudBot

Expand Down
3 changes: 1 addition & 2 deletions cloudbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import warnings

# check python version
if sys.version_info < (3, 4, 0):
Expand All @@ -11,7 +10,7 @@
import logging
import os

__version__ = "1.0.0 Stable"
__version__ = "1.0.2"

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

Expand Down
6 changes: 3 additions & 3 deletions cloudbot/util/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
]


def size(bytes, system=traditional):
def size(b, system=traditional):
"""Human-readable file size.
Using the traditional system, where a factor of 1024 is used::
Expand Down Expand Up @@ -150,9 +150,9 @@ def size(bytes, system=traditional):
"""
for factor, suffix in system:
if bytes >= factor:
if b >= factor:
break
amount = int(bytes / factor)
amount = int(b / factor)
if isinstance(suffix, tuple):
singular, multiple = suffix
if amount == 1:
Expand Down
13 changes: 13 additions & 0 deletions cloudbot/util/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def truncate(content, length=100, suffix='...'):
strip_colors = strip_irc


def chunk_str(content, length=420):
"""
Chunks a string into smaller strings of given length. Returns chunks.
:rtype list
"""
def chunk(c, l):
while c:
out = (c+' ')[:l].rsplit(' ', 1)[0]
c = c[len(out):].strip()
yield out
return list(chunk(content, length))


def pluralize(num=0, text=''):
"""
Takes a number and a string, and pluralizes that string using the number and combines the results.
Expand Down
1 change: 0 additions & 1 deletion cloudbot/util/timeformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def format_time(seconds, count=3, accuracy=6, simple=False):
strings = []
i = 0
for period_name, period_seconds in periods:
print(i, period_name)
if i < count:
if seconds > period_seconds:
period_value, seconds = divmod(seconds, period_seconds)
Expand Down
2 changes: 1 addition & 1 deletion plugins/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@hook.command("amazon", "az")
def amazon(text):
""" <query> -- Searches Amazon for query"""
"""<query> -- Searches Amazon for query"""
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, '
'like Gecko) Chrome/22.0.1229.79 Safari/537.4',
Expand Down
36 changes: 15 additions & 21 deletions plugins/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


def fetch_db():
logger.info("fetch called")
if os.path.exists(PATH):
os.remove(PATH)
r = requests.get(DB_URL, stream=True)
Expand All @@ -34,28 +33,23 @@ def update_db():
"""
Updates the DB.
"""
try:
if os.path.isfile(PATH):
# check if file is over 2 weeks old
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
# geoip is outdated, re-download
fetch_db()
return geoip2.database.Reader(PATH)
else:
try:
return geoip2.database.Reader(PATH)
except:
# issue loading, geo
fetch_db()
return geoip2.database.Reader(PATH)
else:
# no geoip file
print("calling fetch_db")
if os.path.isfile(PATH):
# check if file is over 2 weeks old
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
# geoip is outdated, re-download
fetch_db()
print("fetch_db finished")
return geoip2.database.Reader(PATH)
except Exception as e:
print("GEOERROR" + e)
else:
try:
return geoip2.database.Reader(PATH)
except:
# issue loading, geo
fetch_db()
return geoip2.database.Reader(PATH)
else:
# no geoip file
fetch_db()
return geoip2.database.Reader(PATH)


def check_db(loop):
Expand Down
25 changes: 5 additions & 20 deletions plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

from cloudbot import hook
from cloudbot.util import formatting


@asyncio.coroutine
Expand Down Expand Up @@ -37,13 +38,7 @@ def help_command(text, conn, bot, notice, has_permission):
else:
notice("Unknown command '{}'".format(searching_for))
else:

# list of lines to send to the user
lines = []
# current line, containing words to join with " "
current_line = []
# current line length, to count how long the current line will be when joined with " "
current_line_length = 0
commands = []

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

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

if current_line_length + added_length > 450:
# if line limit is reached, add line to lines, and reset
lines.append(", ".join(current_line) + ",")
current_line = []
current_line_length = 0
commands.append(command)

current_line.append(command)
current_line_length += added_length

if current_line:
# make sure to include the last line
lines.append(", ".join(current_line))
# list of lines to send to the user
lines = formatting.chunk_str("Here's a list of commands you can use: " + ", ". join(commands))

notice("Here's a list of commands you can use:")
for line in lines:
notice(line)
notice("For detailed help, use {}help <command>, without the brackets.".format(conn.config["command_prefix"]))
173 changes: 0 additions & 173 deletions plugins/minecraft_bukget.py

This file was deleted.

3 changes: 3 additions & 0 deletions plugins/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def password(text, notice):
except ValueError:
length = 12

if length > 50:
notice("Maximum length is 50 characters.")

# add alpha characters
if "alpha" in text or "letter" in text:
okay += list(string.ascii_lowercase)
Expand Down
8 changes: 4 additions & 4 deletions plugins/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ def quote(text, nick, chan, db, notice):
notice(add_quote(db, chan, quoted_nick, nick, msg))
return
elif retrieve:
select, num = retrieve.groups()
by_chan = True if select.startswith('#') else False
selected, num = retrieve.groups()
by_chan = True if selected.startswith('#') else False
if by_chan:
return get_quote_by_chan(db, select, num)
return get_quote_by_chan(db, selected, num)
else:
return get_quote_by_nick(db, select, num)
return get_quote_by_nick(db, selected, num)
elif retrieve_chan:
chan, nick, num = retrieve_chan.groups()
return get_quote_by_nick_chan(db, chan, nick, num)
Expand Down
Loading

0 comments on commit a172b7d

Please sign in to comment.