Skip to content

Commit 8c01e4e

Browse files
authored
Merge branch 'gonzobot' into gonzobot+crypto-fix
2 parents a258a39 + add1c55 commit 8c01e4e

81 files changed

Lines changed: 1040 additions & 378 deletions

Some content is hidden

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

cloudbot/__init__.py

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

1313
__version__ = "1.0.9"
1414

15-
__all__ = ["util", "bot", "connection", "config", "permissions", "plugin", "event", "hook", "log_dir"]
15+
__all__ = ["clients", "util", "bot", "client", "config", "event", "hook", "permissions", "plugin", "reloader", "logging_dir"]
1616

1717

1818
def _setup():

cloudbot/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _init_routine(self):
221221
self.observer.start()
222222

223223
# Connect to servers
224-
yield from asyncio.gather(*[conn.connect() for conn in self.connections.values()], loop=self.loop)
224+
yield from asyncio.gather(*[conn.try_connect() for conn in self.connections.values()], loop=self.loop)
225225

226226
# Activate web interface.
227227
if self.config.get("web", {}).get("enabled", False) and web_installed:

cloudbot/client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import collections
33
import logging
4+
import random
45

56
from cloudbot.permissions import PermissionManager
67

@@ -59,7 +60,20 @@ def describe_server(self):
5960
raise NotImplementedError
6061

6162
@asyncio.coroutine
62-
def connect(self):
63+
def try_connect(self):
64+
timeout = 30
65+
while True:
66+
try:
67+
yield from self.connect(timeout)
68+
except Exception:
69+
logger.exception("[%s] Error occurred while connecting.")
70+
else:
71+
break
72+
73+
yield from asyncio.sleep(random.randrange(timeout))
74+
75+
@asyncio.coroutine
76+
def connect(self, timeout=None):
6377
"""
6478
Connects to the server, or reconnects if already connected.
6579
"""

cloudbot/clients/irc.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import random
34
import re
45
import ssl
56
from _ssl import PROTOCOL_SSLv23
@@ -106,7 +107,20 @@ def describe_server(self):
106107
return "{}:{}".format(self.server, self.port)
107108

108109
@asyncio.coroutine
109-
def connect(self):
110+
def try_connect(self):
111+
timeout = self.config["connection"].get("timeout", 30)
112+
while True:
113+
try:
114+
yield from self.connect(timeout)
115+
except (asyncio.TimeoutError, OSError):
116+
logger.exception("[%s] Error occurred while connecting", self.name)
117+
else:
118+
break
119+
120+
yield from asyncio.sleep(random.randrange(timeout))
121+
122+
@asyncio.coroutine
123+
def connect(self, timeout=None):
110124
"""
111125
Connects to the IRC server, or reconnects if already connected.
112126
"""
@@ -125,8 +139,15 @@ def connect(self):
125139
optional_params = {}
126140
if self.local_bind:
127141
optional_params["local_addr"] = self.local_bind
128-
self._transport, self._protocol = yield from self.loop.create_connection(
129-
lambda: _IrcProtocol(self), host=self.server, port=self.port, ssl=self.ssl_context, **optional_params)
142+
143+
coro = self.loop.create_connection(
144+
lambda: _IrcProtocol(self), host=self.server, port=self.port, ssl=self.ssl_context, **optional_params
145+
)
146+
147+
if timeout is not None:
148+
coro = asyncio.wait_for(coro, timeout)
149+
150+
self._transport, self._protocol = yield from coro
130151

131152
tasks = [
132153
self.bot.plugin_manager.launch(hook, Event(bot=self.bot, conn=self, hook=hook))

cloudbot/config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import os
44
import sys
55
import time
6+
from collections import OrderedDict
67

78
logger = logging.getLogger("cloudbot")
89

910

10-
class Config(dict):
11+
class Config(OrderedDict):
1112
"""
1213
:type filename: str
1314
:type path: str
@@ -41,8 +42,10 @@ def load_config(self):
4142
sys.exit()
4243

4344
with open(self.path) as f:
44-
self.update(json.load(f))
45-
logger.debug("Config loaded from file.")
45+
data = json.load(f, object_pairs_hook=OrderedDict)
46+
47+
self.update(data)
48+
logger.debug("Config loaded from file.")
4649

4750
# reload permissions
4851
if self.bot.connections:
@@ -51,5 +54,7 @@ def load_config(self):
5154

5255
def save_config(self):
5356
"""saves the contents of the config dict to the config file"""
54-
json.dump(self, open(self.path, 'w'), sort_keys=True, indent=4)
57+
with open(self.path, 'w') as f:
58+
json.dump(self, f, indent=4)
59+
5560
logger.info("Config saved to file.")

cloudbot/util/formatting.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4545
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4646
"""
47-
47+
import copy
4848
import re
4949
import html.entities
5050

@@ -318,3 +318,20 @@ def get_text_list(list_, last_word='or'):
318318
# Translators: This string is used as a separator between list elements
319319
', '.join([i for i in list_][:-1]),
320320
last_word, list_[-1])
321+
322+
323+
def gen_markdown_table(headers, rows):
324+
"""
325+
Generates a Markdown formatted table from the data
326+
"""
327+
rows = copy.copy(rows)
328+
rows.insert(0, headers)
329+
rotated = zip(*reversed(rows))
330+
331+
sizes = tuple(map(lambda l: max(max(map(len, l)), 3), rotated))
332+
rows.insert(1, tuple(('-' * size) for size in sizes))
333+
lines = [
334+
"| {} |".format(' | '.join(cell.ljust(sizes[i]) for i, cell in enumerate(row)))
335+
for row in rows
336+
]
337+
return '\n'.join(lines)

data/food/burger.json

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,25 @@
7575
"sriracha aioli"
7676
],
7777
"topping2": [
78-
"crispy bacon strips",
79-
"caramelized onions",
80-
"fried onion straws",
81-
"sauteed mushrooms",
82-
"a fried egg",
83-
"arugula",
84-
"romaine lettuce"
85-
],
78+
"crispy bacon strips",
79+
"caramelized onions",
80+
"fried onion straws",
81+
"sauteed mushrooms",
82+
"a fried egg",
83+
"arugula",
84+
"romaine lettuce"
85+
],
8686
"side": [
87-
"a side of fries tossed in parm and truffle oil",
88-
"a side of sweet potato fries",
89-
"a side of McDonald's fries",
90-
"a side of curly fries",
91-
"a side of thick-cut chips",
92-
"a side of onion rings",
93-
"side of sesame ginger coleslaw",
94-
"side of macaroni and cheese",
95-
"a large chilly soda",
96-
"a cup of BBQ dip"
97-
]
87+
"a side of fries tossed in parm and truffle oil",
88+
"a side of sweet potato fries",
89+
"a side of McDonald's fries",
90+
"a side of curly fries",
91+
"a side of thick-cut chips",
92+
"a side of onion rings",
93+
"side of sesame ginger coleslaw",
94+
"side of macaroni and cheese",
95+
"a large chilly soda",
96+
"a cup of BBQ dip"
97+
]
9898
}
9999
}
100-

data/food/soup.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"Cazuela",
1616
"Chicken Noodle",
1717
"Cock-a-leekie",
18-
"Cream of crab",
18+
"Cream of crab",
1919
"Fufu and Egusi",
2020
"Gomguk",
2121
"Goulash",
@@ -25,7 +25,7 @@
2525
"Lagman",
2626
"Leek",
2727
"Lentil",
28-
"Maryland crab",
28+
"Maryland crab",
2929
"Matzah ball",
3030
"Menudo",
3131
"Minestrone",

data/reaction_macros.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"https://i.imgur.com/8VYMSq8.gif",
3131
"https://i.imgur.com/WVn7B8O.jpg",
3232
"https://i.imgur.com/GTxRRuv.gif"
33-
],
34-
"head_desk_macros": [
33+
],
34+
"head_desk_macros": [
3535
"https://i.imgur.com/Pg9nt.gif",
3636
"https://baudattitude.files.wordpress.com/2012/02/twilightsparkleheaddesk.gif",
3737
"https://i.imgur.com/LFzzTd8.gif",

0 commit comments

Comments
 (0)