get_server_by_alias() and save dm subscriptions

This commit is contained in:
Ben Harris 2020-07-13 11:37:22 -04:00
parent 5ffd16c225
commit dd3dba5d40
1 changed files with 49 additions and 29 deletions

View File

@ -97,43 +97,54 @@ class Module(ModuleManager.BaseModule):
self.save_nowplaying(event["data"])
# new dj online!
if self.dj != "" and self.dj != previous_dj:
newdj_message = f"{self.dj} is now online playing {self.song}! tune in here now: {LISTEN_URL}"
if self.is_online:
self.mastodon.toot(newdj_message)
server = self.bot.get_server_by_alias("tilde")
if server is not None:
# TODO: send dm notifications
# TODO: send email notifications
if self.dj != "" and self.dj != previous_dj:
newdj_message = f"{self.dj} is now online playing {self.song}! tune in here now: {LISTEN_URL}"
if "tilde" in self.bot.servers:
server = self.bot.servers["tilde"]
for channel_name in NOTIFY_CHANNELS:
if channel_name in server.channels:
channel = server.channels[channel_name]
self.mastodon.toot(newdj_message)
# send dm notifications
for n in self.bot.get_setting("tilderadio-subscriptions", []):
if n in server.users:
user = server.users[n]
self.events.on("send.stdout").call(
target=user,
module_name="Tilderadio",
server=server,
message=newdj_message,
)
# TODO: send email notifications
for channel_name in NOTIFY_CHANNELS:
if channel_name in server.channels:
channel = server.channels[channel_name]
self.events.on("send.stdout").call(
target=channel,
module_name="Tilderadio",
server=server,
message=newdj_message,
)
# post new songs while streaming
if self.song != "" and self.song != previous_song:
if CHANNEL in server.channels:
channel = server.channels[CHANNEL]
self.events.on("send.stdout").call(
target=channel,
module_name="Tilderadio",
server=server,
message=newdj_message,
message=utils.irc.color(
self.format_nowplaying(), utils.consts.GREEN
),
)
# post new songs while streaming
if self.is_online and self.song != previous_song:
if "tilde" in self.bot.servers:
server = self.bot.servers["tilde"]
if CHANNEL in server.channels:
channel = server.channels[CHANNEL]
self.events.on("send.stdout").call(
target=channel,
module_name="Tilderadio",
server=server,
message=utils.irc.color(
self.format_nowplaying(), utils.consts.GREEN
),
)
@utils.hook("received.command.np", alias_of="nowplaying")
@utils.hook("received.command.nowplaying")
@utils.kwarg("help", "show the current song on tilderadio")
@ -168,13 +179,22 @@ class Module(ModuleManager.BaseModule):
@utils.hook("received.command.subscribe")
@utils.kwarg("help", "sign up to get a direct message when a new dj goes online")
def subscribe(self, event):
# TODO: save subscribe to db
subs = self.bot.get_setting("tilderadio-subscriptions", [])
nick = event["user"].nickname
if not nick in subs:
subs.append(nick)
self.bot.set_setting("tilderadio-subscriptions", subs)
event["stdout"].write("i'll send you a message when a dj goes online")
@utils.hook("received.command.unsubscribe")
@utils.kwarg("help", "unsubscribe from dj announcements")
def unsubscribe(self, event):
# TODO: remove sender from subscribers
subs = self.bot.get_setting("tilderadio-subscriptions", [])
if nick in subs:
subs.remove(nick)
self.bot.set_setting("tilderadio-subscriptions", subs)
event["stdout"].write("ok, i'll no longer send you dj announcements")
@utils.hook("received.command.emailsubscribe")