xmpp: Improve affiliation setting and react to SIGTERM
This commit is contained in:
parent
704ee770d4
commit
d385170165
@ -88,7 +88,10 @@ class BridgeComponent(ComponentXMPP):
|
||||
"""
|
||||
return JID(str(id_) + "@" + self._domain + "/discord")
|
||||
|
||||
async def on_sigint(self):
|
||||
async def on_shutdown_signal(self):
|
||||
"""
|
||||
Receiving SIGINT or SIGTERM means we need to pack up and shut down
|
||||
"""
|
||||
await self._discord.close()
|
||||
|
||||
# Remove all virtual users
|
||||
@ -112,7 +115,9 @@ class BridgeComponent(ComponentXMPP):
|
||||
|
||||
async def on_discord_ready(self):
|
||||
asyncio.get_event_loop().add_signal_handler(signal.SIGINT,
|
||||
lambda: asyncio.create_task(self.on_sigint()))
|
||||
lambda: asyncio.create_task(self.on_shutdown_signal()))
|
||||
asyncio.get_event_loop().add_signal_handler(signal.SIGTERM,
|
||||
lambda: asyncio.create_task(self.on_shutdown_signal()))
|
||||
|
||||
for ch in self._config["discord"]["channels"]:
|
||||
muc = ch["muc"]
|
||||
@ -204,23 +209,18 @@ class BridgeComponent(ComponentXMPP):
|
||||
reason="Bridging Discord and XMPP")
|
||||
self._webhooks[muc] = wh
|
||||
|
||||
# TODO: Check if we need to set it
|
||||
# Make sure our virtual users can join
|
||||
affiliation_delta = [
|
||||
(self.spoof_member_jid(member.id).bare, "member") for member in dchannel.members
|
||||
]
|
||||
|
||||
affiliation_list = await self.plugin["xep_0045"].get_affiliation_list(muc,
|
||||
"member",
|
||||
ifrom=self._bot_jid_full)
|
||||
for member in dchannel.members:
|
||||
bare_member_jid = self.spoof_member_jid(member.id).bare
|
||||
if not bare_member_jid in affiliation_list:
|
||||
await self.plugin["xep_0045"].set_affiliation(muc,
|
||||
"member",
|
||||
jid=self.spoof_member_jid(member.id).bare,
|
||||
jid=bare_member_jid,
|
||||
ifrom=self._bot_jid_full)
|
||||
|
||||
#await self.plugin["xep_0045"].send_affiliation_list(muc,
|
||||
# affiliation_delta,
|
||||
# ifrom=self._bot_jid_full)
|
||||
|
||||
for member in dchannel.members:
|
||||
self.virtual_user_join_muc(muc, member, update_state_tracking=False)
|
||||
|
||||
self._logger.info("%s is ready", muc)
|
||||
|
Loading…
Reference in New Issue
Block a user