Add message sounds
Thanks to Boctor for notification_chicago.wav and notification_whister.wav
This commit is contained in:
parent
74fda1795b
commit
ec643880ef
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -39,4 +39,8 @@ userHighlight = color: #ff0000; font-weight: bold
|
||||||
userOnline = color: #00ff00
|
userOnline = color: #00ff00
|
||||||
userAway = color: #ffff00
|
userAway = color: #ffff00
|
||||||
userBusy = color: #ff0000
|
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
|
|
@ -16,12 +16,14 @@ if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
||||||
else:
|
else:
|
||||||
s = os.path.realpath(__file__)
|
s = os.path.realpath(__file__)
|
||||||
sp = pUp(s)
|
sp = pUp(s)
|
||||||
|
os.chdir(sp)
|
||||||
|
|
||||||
# script start
|
# script start
|
||||||
import qtpy
|
import qtpy
|
||||||
from qtpy.QtGui import *
|
from qtpy.QtGui import *
|
||||||
from qtpy.QtWidgets import *
|
from qtpy.QtWidgets import *
|
||||||
from qtpy.QtCore import *
|
from qtpy.QtCore import *
|
||||||
|
from qtpy.QtMultimedia import QSound
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import html
|
import html
|
||||||
import threading
|
import threading
|
||||||
|
@ -62,6 +64,9 @@ def getChannelDisplayName(channel):
|
||||||
return "Group: " +channel.name
|
return "Group: " +channel.name
|
||||||
return "Group: [No name]"
|
return "Group: [No name]"
|
||||||
|
|
||||||
|
def playNotificationSound():
|
||||||
|
if notificationSound: notificationSound.play()
|
||||||
|
|
||||||
class dbfApp:
|
class dbfApp:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = QApplication(sys.argv)
|
self.app = QApplication(sys.argv)
|
||||||
|
@ -509,28 +514,47 @@ def discordClient(token):
|
||||||
newTime = None
|
newTime = None
|
||||||
async for msg in channel.history(limit=1):
|
async for msg in channel.history(limit=1):
|
||||||
newTime = msg.created_at
|
newTime = msg.created_at
|
||||||
if not newTime: return
|
if not newTime: return False
|
||||||
oldTime = getLastMessageTime(channel)
|
oldTime = getLastMessageTime(channel)
|
||||||
|
|
||||||
if not oldTime:
|
if not oldTime:
|
||||||
setLastMessageTime(channel,newTime)
|
setLastMessageTime(channel,newTime)
|
||||||
return
|
return False
|
||||||
|
|
||||||
async for message in channel.history(limit=100,before=newTime,after=oldTime):
|
fetchMsgs = False
|
||||||
guiLock.acquire()
|
guiLock.acquire()
|
||||||
for gui in openGuis:
|
for gui in openGuis:
|
||||||
if gui.type == "channel":
|
if gui.type == "channel":
|
||||||
if message.channel != gui.channel: continue
|
if channel != gui.channel: continue
|
||||||
addGuiTask(gui,gui.addMessage,(message,),{})
|
fetchMsgs = True
|
||||||
guiLock.release()
|
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)
|
setLastMessageTime(channel,newTime)
|
||||||
|
return True
|
||||||
|
|
||||||
async def fetchAllLostMessages():
|
async def fetchAllLostMessages():
|
||||||
print("fetching all lost messages...")
|
print("fetching all lost messages...")
|
||||||
|
newMessages = False
|
||||||
for channel in client.private_channels:
|
for channel in client.private_channels:
|
||||||
if not type(channel) in channelFilter: continue
|
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.")
|
print("done fetching.")
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
|
@ -600,6 +624,10 @@ def discordClient(token):
|
||||||
setLastMessageTime(message.channel,message.created_at)
|
setLastMessageTime(message.channel,message.created_at)
|
||||||
|
|
||||||
guiLock.acquire()
|
guiLock.acquire()
|
||||||
|
|
||||||
|
if type(message.channel) in channelFilter:
|
||||||
|
addGuiTask(None,playNotificationSound,(),{})
|
||||||
|
|
||||||
for gui in openGuis:
|
for gui in openGuis:
|
||||||
if gui.type == "channel":
|
if gui.type == "channel":
|
||||||
if message.channel != gui.channel: continue
|
if message.channel != gui.channel: continue
|
||||||
|
@ -728,6 +756,12 @@ def main():
|
||||||
app = dbfApp()
|
app = dbfApp()
|
||||||
loadStyle(config)
|
loadStyle(config)
|
||||||
|
|
||||||
|
global notificationSound
|
||||||
|
if config["sound"]["notification"].lower() != "none":
|
||||||
|
notificationSound = QSound(config["sound"]["notification"])
|
||||||
|
else:
|
||||||
|
notificationSound = None
|
||||||
|
|
||||||
loginGui = guiLoginChooser()
|
loginGui = guiLoginChooser()
|
||||||
openGuis.append(loginGui)
|
openGuis.append(loginGui)
|
||||||
sys.exit(app.app.exec_())
|
sys.exit(app.app.exec_())
|
||||||
|
|
Loading…
Reference in New Issue