Skip to content

Commit 39f9729

Browse files
committed
Merge branch 'gonzobot' into gonzobot+fix-readme
2 parents f3feaa3 + fd6e4be commit 39f9729

5 files changed

Lines changed: 74 additions & 28 deletions

File tree

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",

plugins/chan_track.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
Requires:
55
server_info.py
66
"""
7+
import gc
78
import weakref
9+
from collections import Mapping
10+
from contextlib import suppress
811
from operator import attrgetter
912
from weakref import WeakValueDictionary
1013

@@ -105,6 +108,34 @@ def get_chan_data(bot):
105108
update_conn_data(conn)
106109

107110

111+
def clean_user_data(user):
112+
for memb in user.get("channels", {}).values():
113+
status = list(set(memb.get("status", [])))
114+
status.sort(key=attrgetter("level"), reverse=True)
115+
memb["status"] = status
116+
117+
118+
def clean_chan_data(chan):
119+
with suppress(KeyError):
120+
del chan["new_users"]
121+
122+
with suppress(KeyError):
123+
del chan["receiving_names"]
124+
125+
126+
def clean_conn_data(conn):
127+
for user in conn.memory.get("users", {}).values():
128+
clean_user_data(user)
129+
130+
for chan in conn.memory.get("chan_data", {}).values():
131+
clean_chan_data(chan)
132+
133+
134+
def clean_data(bot):
135+
for conn in bot.connections.values():
136+
clean_conn_data(conn)
137+
138+
108139
@hook.connect
109140
def init_chan_data(conn, _clear=True):
110141
chan_data = conn.memory.setdefault("chan_data", ChanDict())
@@ -158,15 +189,16 @@ def replace_user_data(conn, chan_data):
158189
nick = user_data["nick"]
159190
new_users[nick] = memb_data
160191
if nick in old_users:
161-
old_data = old_users[nick]
192+
old_data = old_users[nick] # Old membership object
162193
old_data.update(memb_data) # New data takes priority over old data
163194
memb_data.update(old_data)
164195

165196
old_user_data = users.getuser(nick)
197+
user_data["channels"] = old_user_data["channels"]
198+
add_user_membership(user_data, chan_data["name"], memb_data)
166199
old_user_data.update(user_data)
167200
user_data = old_user_data
168201
memb_data["user"] = user_data
169-
add_user_membership(user_data, chan_data["name"], memb_data)
170202

171203
old_users.clear()
172204
old_users.update(new_users) # Reassigning the dict would break other references to the data, so just update instead
@@ -201,7 +233,7 @@ def dump_dict(data, indent=2, level=0, _objects=None):
201233
yield ((" " * (indent * level)) + "{}:".format(key))
202234
if id(value) in _objects:
203235
yield ((" " * (indent * (level + 1))) + "[...]")
204-
elif isinstance(value, dict):
236+
elif isinstance(value, Mapping):
205237
_objects.append(id(value))
206238
yield from dump_dict(value, indent=indent, level=level + 1, _objects=_objects)
207239
else:
@@ -257,6 +289,20 @@ def updateusers(bot):
257289
return "Updating all channel data"
258290

259291

292+
@hook.command(permissions=["botcontrol"], autohelp=False)
293+
def cleanusers(bot):
294+
clean_data(bot)
295+
gc.collect()
296+
return "Data cleaned."
297+
298+
299+
@hook.command(permissions=["botcontrol"], autohelp=False)
300+
def clearusers(bot):
301+
init_chan_data(bot, True)
302+
gc.collect()
303+
return "Data cleared."
304+
305+
260306
@hook.irc_raw('JOIN')
261307
def on_join(nick, user, host, conn, irc_paramlist):
262308
chan, *other_data = irc_paramlist

travis/test_json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
exit_code |= 2
3232
print("Travis: {} is not a properly formatted JSON file".format(file))
3333

34-
sys.exit(exit_code)
34+
if exit_code != 0:
35+
sys.exit(exit_code)

0 commit comments

Comments
 (0)