diff --git a/assets/sounds/notification_chicago.wav b/assets/sounds/notification_chicago.wav new file mode 100644 index 0000000..a7460ff Binary files /dev/null and b/assets/sounds/notification_chicago.wav differ diff --git a/assets/sounds/notification_pda.wav b/assets/sounds/notification_pda.wav new file mode 100644 index 0000000..b750d43 Binary files /dev/null and b/assets/sounds/notification_pda.wav differ diff --git a/assets/sounds/notification_whistler.wav b/assets/sounds/notification_whistler.wav new file mode 100644 index 0000000..adf1279 Binary files /dev/null and b/assets/sounds/notification_whistler.wav differ diff --git a/default.ini b/default.ini index af5a061..18d5519 100644 --- a/default.ini +++ b/default.ini @@ -39,4 +39,8 @@ userHighlight = color: #ff0000; font-weight: bold userOnline = color: #00ff00 userAway = color: #ffff00 userBusy = color: #ff0000 -userOffline = color: #999999 \ No newline at end of file +userOffline = color: #999999 + +[sound] +; Sound played when a new message arrives. Set to none, if you want no sound. +notification = assets/sounds/notification_whistler.wav \ No newline at end of file diff --git a/discord-but-fast.py b/discord-but-fast.py index a49088c..d6ea05c 100644 --- a/discord-but-fast.py +++ b/discord-but-fast.py @@ -16,12 +16,14 @@ if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): else: s = os.path.realpath(__file__) sp = pUp(s) +os.chdir(sp) # script start import qtpy from qtpy.QtGui import * from qtpy.QtWidgets import * from qtpy.QtCore import * +from qtpy.QtMultimedia import QSound import urllib.parse import html import threading @@ -62,6 +64,9 @@ def getChannelDisplayName(channel): return "Group: " +channel.name return "Group: [No name]" +def playNotificationSound(): + if notificationSound: notificationSound.play() + class dbfApp: def __init__(self): self.app = QApplication(sys.argv) @@ -509,28 +514,47 @@ def discordClient(token): newTime = None async for msg in channel.history(limit=1): newTime = msg.created_at - if not newTime: return + if not newTime: return False oldTime = getLastMessageTime(channel) if not oldTime: setLastMessageTime(channel,newTime) - return + return False - async for message in channel.history(limit=100,before=newTime,after=oldTime): - guiLock.acquire() - for gui in openGuis: - if gui.type == "channel": - if message.channel != gui.channel: continue - addGuiTask(gui,gui.addMessage,(message,),{}) - guiLock.release() + fetchMsgs = False + guiLock.acquire() + for gui in openGuis: + if gui.type == "channel": + if channel != gui.channel: continue + fetchMsgs = True + break + guiLock.release() + + if fetchMsgs == True: + async for message in channel.history(limit=100,before=newTime,after=oldTime): + guiLock.acquire() + for gui in openGuis: + if gui.type == "channel": + if channel != gui.channel: continue + addGuiTask(gui,gui.addMessage,(message,),{}) + guiLock.release() setLastMessageTime(channel,newTime) + return True async def fetchAllLostMessages(): print("fetching all lost messages...") + newMessages = False for channel in client.private_channels: if not type(channel) in channelFilter: continue - await fetchLostMessages(channel) + r = await fetchLostMessages(channel) + if newMessages == False and r == True: newMessages = True + + if newMessages == True: + guiLock.acquire() + addGuiTask(None,playNotificationSound,(),{}) + guiLock.release() + print("done fetching.") @client.event @@ -600,6 +624,10 @@ def discordClient(token): setLastMessageTime(message.channel,message.created_at) guiLock.acquire() + + if type(message.channel) in channelFilter: + addGuiTask(None,playNotificationSound,(),{}) + for gui in openGuis: if gui.type == "channel": if message.channel != gui.channel: continue @@ -728,6 +756,12 @@ def main(): app = dbfApp() loadStyle(config) + global notificationSound + if config["sound"]["notification"].lower() != "none": + notificationSound = QSound(config["sound"]["notification"]) + else: + notificationSound = None + loginGui = guiLoginChooser() openGuis.append(loginGui) sys.exit(app.app.exec_())