Skip to content

Commit e7c2647

Browse files
author
Foxlet
committed
Merge remote-tracking branch 'upstream/python3.4' into python3.4
sary, Updating RoboCop
2 parents 34c0f45 + 553543f commit e7c2647

58 files changed

Lines changed: 1067 additions & 685 deletions

Some content is hidden

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

.gitattributes

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# Force LF on all files
1+
# default all files as text with lf
22
* text eol=lf
3+
4+
# mmdb files are binary
5+
*.mmdb binary
6+
7+

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: python
2+
python:
3+
- "3.4"
4+
5+
install:
6+
- "sudo apt-get update -q"
7+
- "sudo apt-get install -y python3-lxml"
8+
- "pip install -r ./travis/requirements.txt"
9+
10+
script:
11+
- "python ./travis/test_json.py"
12+
- "py.test . -v --cov . --cov-report term-missing"
13+
14+
after_success:
15+
- "coveralls"
16+
17+
notifications:
18+
irc:
19+
channels:
20+
- "irc.esper.net#cloudbot"
21+
template:
22+
- "%{repository}#%{build_number} (%{branch} - %{commit}) %{author}: %{message}"
23+
on_failure: always
24+
on_success: change

CONTRIBUTORS

Lines changed: 0 additions & 46 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# CloudBot Refresh
1+
# CloudBot [![Build Status](https://travis-ci.org/CloudBotIRC/CloudBot.svg?branch=python3.4)](https://travis-ci.org/CloudBotIRC/CloudBot) [![Coverage Status](https://coveralls.io/repos/CloudBotIRC/CloudBot/badge.png?branch=python3.4)](https://coveralls.io/r/CloudBotIRC/CloudBot?branch=python3.4)
22

3-
CloudBotRefresh is the newest generation of CloudBot, the fun, fast, extendable Python IRC bot!
3+
CloudBot Refresh is the newest generation of CloudBot, the fun, fast, extendable Python IRC bot!
44

55
## Installing CloudBot
66

7-
Firstly, CloudBot will only run on **Python 3.4 or higher**. Because we use the asyncio module, you will not be able to use any other versions of Python. If you **really** want to run CloudBot on Python 2.x, you can find the old **unsupported** version of CloudBot at [this location](https://github.com/ClouDev/CloudBot).
7+
Firstly, CloudBot will only run on **Python 3.4 or higher**. Because we use the asyncio module, you will not be able to use any other versions of Python.
88

9-
To install CloudBotRefresh on *nix (linux, etc), see [docs/installing-unix.md](https://github.com/CloudBotIRC/CloudBotRefresh/blob/python3.4/docs/installing-unix.md)
9+
To install CloudBot on *nix (linux, etc), see [here](https://github.com/CloudBotIRC/CloudBot/wiki/Installing-on-*nix)
1010

11-
To install CloudBotRefresh on Windows, see [docs/installing-windows.md](https://github.com/CloudBotIRC/CloudBotRefresh/blob/python3.4/docs/installing-windows.md)
11+
To install CloudBot on Windows, see [here](https://github.com/CloudBotIRC/CloudBot/wiki/Installing-on-Windows)
1212

13-
If you're going to be actively developing on CloudBotRefresh, and submitting PRs back, we recommend running CloudBotRefresh inside Vagrant. This allows everyone to have an identical development environment.
13+
If you're going to be actively developing on CloudBot, and submitting PRs back, you can run CloudBot inside Vagrant. This allows everyone to have an identical development environment.
1414

15-
To install CloudBotRefresh in Vagrant (both *Unix and Windows), see [docs/installing-vagrant.md](https://github.com/CloudBotIRC/CloudBotRefresh/blob/python3.4/docs/installing-vagrant.md)
15+
To install CloudBot in Vagrant (both *Unix and Windows), see [here](https://github.com/CloudBotIRC/CloudBot/wiki/Installing-with-Vagrant)
1616

1717

1818
### Running CloudBot
1919

20-
Before you run the bot, rename `config.default` to `config.json` and edit it with your preferred settings. You can check if your JSON is valid using [jsonlint.com](http://jsonlint.com/)!
20+
Before you run the bot, rename `config.default.json` to `config.json` and edit it with your preferred settings. You can check if your JSON is valid using [jsonlint.com](http://jsonlint.com/)!
2121

2222
Once you have installed the required dependencies and renamed the config file, you can run the bot! Make sure you are in the correct folder and run the following command:
2323

@@ -35,15 +35,12 @@ Specify the path as /path/to/repository/cloudbot/__main__.py, where `cloudbot` i
3535

3636
### Documentation
3737

38-
To configure your CloudBot, visit the [Config Wiki Page](https://github.com/CloudBotIRC/CloudBotRefresh/wiki/Config).
38+
The CloudBot documentation is currently somewhat outdated and may not be correct. If you need any help, please visit our [IRC channel](irc://irc.esper.net/cloudbot) and we will be happy to assist you.
3939

40-
To write your own modules, visit the [Module Wiki Page](https://github.com/CloudBotIRC/CloudBotRefresh/wiki/Writing-Refresh-Modules).
40+
To write your own plugins, visit the [Plugins Wiki Page](https://github.com/CloudBotIRC/CloudBotRefresh/wiki/Writing-Refresh-Modules).
4141

4242
More at the [Wiki Main Page](https://github.com/CloudBotIRC/CloudBotRefresh/wiki).
4343

44-
Note that the configuration page, and the main wiki page, are still for CloudBot Develop. The Module Wiki Page has been
45-
rewritten for refresh, but the other pages are outdated.
46-
4744
### Support
4845

4946
The developers reside in [#CloudBot](irc://irc.esper.net/cloudbot) on [EsperNet](http://esper.net) and would be glad to help you.

cloudbot/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def load_config(self):
5757
# if there is no config, show an error and die
5858
logger.critical("No config file found, bot shutting down!")
5959
print("No config file found! Bot shutting down in five seconds.")
60-
print("Copy 'config.default' to 'config.json' for defaults.")
60+
print("Copy 'config.default.json' to 'config.json' for defaults.")
6161
print("For help, see http://git.io/cloudbotirc. Thank you for using CloudBot!")
6262
time.sleep(5)
6363
sys.exit()

cloudbot/irc/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
}
2525

2626

27+
def decode(bytestring):
28+
"""
29+
Tries to decode a bytestring using multiple encoding formats
30+
"""
31+
for codec in ('utf-8', 'iso-8859-1', 'shift_jis', 'cp1252'):
32+
try:
33+
return bytestring.decode(codec)
34+
except UnicodeDecodeError:
35+
continue
36+
return bytestring.decode('utf-8', errors='ignore')
37+
38+
2739
class IrcClient(Client):
2840
"""
2941
An implementation of Client for IRC.
@@ -275,7 +287,7 @@ def data_received(self, data):
275287

276288
while b"\r\n" in self._input_buffer:
277289
line_data, self._input_buffer = self._input_buffer.split(b"\r\n", 1)
278-
line = line_data.decode()
290+
line = decode(line_data)
279291

280292
# parse the line into a message
281293
if line.startswith(":"):

cloudbot/util/colors.py

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
"""
2+
colours.py by Zarthus <[email protected]>:
3+
Pretty colours, colours everywhere
4+
Parses colours using a $(colour) or $(formatting) template.
5+
Supports both the American and British spellings of many colours and words.
6+
7+
This file is licenced under the MIT License (MIT)
8+
9+
Copyright (c) 2014 - 2015 Zarthus [email protected]
10+
11+
Permission is hereby granted, free of charge, toany person obtaining a copy of this software and associated
12+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
14+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
17+
Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
"""
24+
25+
import re
26+
from random import randint
27+
28+
29+
IRC_COLOUR_DICT = {
30+
"white": "00",
31+
"black": "01",
32+
"dblue": "02",
33+
"dark_blue": "02",
34+
"dark_green": "03",
35+
"dgreen": "03",
36+
"red": "04",
37+
"dark_red": "05",
38+
"dred": "05",
39+
"brown": "05", # Note: This appears to show up as brown for some clients, dark red for others.
40+
"purple": "06",
41+
"orange": "07",
42+
"yellow": "08",
43+
"green": "09",
44+
"lime": "09",
45+
"cyan": "10",
46+
"teal": "11",
47+
"blue": "12",
48+
"pink": "13",
49+
"dgrey": "14",
50+
"dark_grey": "14",
51+
"dgray": "14",
52+
"dark_gray": "14",
53+
"grey": "15",
54+
"gray": "15",
55+
"random": "" # Special keyword, generate a random number.
56+
}
57+
58+
IRC_FORMATTING_DICT = {
59+
"colour": "\x03",
60+
"color": "\x03",
61+
62+
"bold": "\x02",
63+
"b": "\x02",
64+
65+
"underlined": "\x1F",
66+
"underline": "\x1F",
67+
"ul": "\x1F",
68+
69+
"italics": "\x1D",
70+
"italic": "\x1D",
71+
"i": "\x1D",
72+
73+
"reverse": "\x16",
74+
75+
"reset": "\x0F",
76+
"clear": "\x0F"
77+
}
78+
79+
80+
COLOR_RE = re.compile(r"\$\(.*?\)", re.I)
81+
82+
83+
def get_color(colour, return_formatted=True):
84+
"""
85+
Return numeric in string format of human readable colour formatting.
86+
Set return_formatted to False to get just the numeric.
87+
Throws KeyError if colour is not found.
88+
"""
89+
colour = colour.lower()
90+
91+
if colour not in IRC_COLOUR_DICT:
92+
raise KeyError("The colour '{}' is not in the list of available colours.".format(colour))
93+
94+
if colour == "random": # Special keyword for a random colour
95+
rand = randint(0, 15)
96+
if rand < 10: # Prepend '0' before colour so it always is double digits.
97+
rand = "0" + str(rand)
98+
rand = str(rand)
99+
100+
if return_formatted:
101+
return get_format("colour") + rand
102+
return rand
103+
104+
if return_formatted:
105+
return get_format("colour") + IRC_COLOUR_DICT[colour]
106+
return IRC_COLOUR_DICT[colour]
107+
108+
109+
def get_format(formatting):
110+
"""
111+
Return hex-character in string format of human readable formatting.
112+
Throws KeyError if formatting is not found.
113+
"""
114+
115+
if formatting.lower() not in IRC_FORMATTING_DICT:
116+
raise KeyError("The formatting '{}' is not found in the list of available formats.".format(formatting))
117+
118+
return IRC_FORMATTING_DICT[formatting.lower()]
119+
120+
121+
def get_available_formats():
122+
"""List the formats you can use in self.getFormat in a comma separated list (string)"""
123+
124+
ret = ""
125+
for formats in IRC_FORMATTING_DICT:
126+
ret += formats + ", "
127+
128+
return ret[:-2]
129+
130+
131+
def get_available_colours():
132+
"""List the colours you can use in self.getColour in a comma separated list (string)"""
133+
134+
ret = ""
135+
for colours in IRC_COLOUR_DICT:
136+
ret += colours + ", "
137+
138+
return ret[:-2]
139+
140+
141+
def parse(string):
142+
"""
143+
parse: Formats a string, replacing words wrapped in $( ) with actual colours or formatting.
144+
example:
145+
parse("The quick $(brown)brown$(clear) fox jumps over the$(bold) lazy dog$(clear).")
146+
This method will not throw any KeyErrors, but will instead ignore input between $() if it doesn't know what to
147+
replace it with.
148+
"""
149+
150+
formatted = string
151+
regex = COLOR_RE.findall(string)
152+
for match in regex:
153+
formatted = formatted.replace(match, _convert(match), 1)
154+
return formatted
155+
156+
157+
def strip(string):
158+
"""strip: Similiar to parse, only this removes colour codes"""
159+
160+
stripped = ""
161+
162+
regex = COLOR_RE.split(string)
163+
for match in regex:
164+
stripped += match
165+
166+
return stripped.strip()
167+
168+
169+
def _convert(string):
170+
if not string.startswith("$(") and not string.endswith(")"):
171+
return string
172+
string = string[2:-1]
173+
ret = ""
174+
count = 1
175+
formattings = string.lower().replace(" ", "").split(",")
176+
for formatting in formattings:
177+
if formatting in IRC_COLOUR_DICT:
178+
if count % 2 == 0:
179+
ret += "," + get_color(formatting, False)
180+
else:
181+
ret += get_color(formatting)
182+
count += 1
183+
elif formatting in IRC_FORMATTING_DICT:
184+
ret += get_format(formatting)
185+
186+
return ret.strip()

cloudbot/util/filesize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
are listed in the accompanying credits file.
5353
"""
5454

55+
5556
traditional = [
5657
(1024 ** 5, 'P'),
5758
(1024 ** 4, 'T'),

0 commit comments

Comments
 (0)