Skip to content

Commit

Permalink
Selective update main menu icon redis handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xnyo committed Mar 31, 2019
1 parent 8f94604 commit b13207f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions objects/tokenList.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def getTokenFromUserID(self, userID, ignoreIRC=False, _all=False):
"""
# Make sure the token exists
ret = []
userID = int(userID)
for _, value in self.tokens.items():
if value.userID == userID:
if ignoreIRC and value.irc:
Expand Down
3 changes: 2 additions & 1 deletion pep.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from objects import chatFilters
from objects import fokabot
from objects import glob
from pubSubHandlers import changeUsernameHandler
from pubSubHandlers import changeUsernameHandler, setMainMenuIconHandler

from pubSubHandlers import disconnectHandler
from pubSubHandlers import banHandler
Expand Down Expand Up @@ -293,6 +293,7 @@ def make_app():
"peppy:silence": updateSilenceHandler.handler(),
"peppy:ban": banHandler.handler(),
"peppy:notification": notificationHandler.handler(),
"peppy:set_main_menu_icon": setMainMenuIconHandler.handler(),
}).start()

# Start tornado
Expand Down
34 changes: 34 additions & 0 deletions pubSubHandlers/setMainMenuIconHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from common.log import logUtils as log
from common.redis import generalPubSubHandler
from objects import glob
from constants import serverPackets


class handler(generalPubSubHandler.generalPubSubHandler):
def __init__(self):
super().__init__()
self.structure = {
"userID": 0,
"mainMenuIconID": 0
}

def handle(self, data):
data = super().parseData(data)
if data is None:
return
targetTokens = glob.tokens.getTokenFromUserID(data["userID"], ignoreIRC=True, _all=True)
if targetTokens:
icon = glob.db.fetch(
"SELECT file_id, url FROM main_menu_icons WHERE id = %s LIMIT 1",
(data["mainMenuIconID"],)
)
if icon is None:
log.warning("Tried to test an unknown main menu icon")
return
for x in targetTokens:
x.enqueue(
serverPackets.mainMenuIcon("{}|{}".format(
"https://i.ppy.sh/{}.png".format(icon["file_id"]),
icon["url"]
))
)

0 comments on commit b13207f

Please sign in to comment.