Add message sounds

Thanks to Boctor for notification_chicago.wav and
notification_whister.wav
This commit is contained in:
Fierelier 2020-11-25 00:13:16 +01:00
parent 74fda1795b
commit ec643880ef
5 changed files with 49 additions and 11 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,4 +39,8 @@ userHighlight = color: #ff0000; font-weight: bold
userOnline = color: #00ff00
userAway = color: #ffff00
userBusy = color: #ff0000
userOffline = color: #999999
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

View File

@ -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_())