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")
|
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()
|
await self._discord.close()
|
||||||
|
|
||||||
# Remove all virtual users
|
# Remove all virtual users
|
||||||
@ -112,7 +115,9 @@ class BridgeComponent(ComponentXMPP):
|
|||||||
|
|
||||||
async def on_discord_ready(self):
|
async def on_discord_ready(self):
|
||||||
asyncio.get_event_loop().add_signal_handler(signal.SIGINT,
|
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"]:
|
for ch in self._config["discord"]["channels"]:
|
||||||
muc = ch["muc"]
|
muc = ch["muc"]
|
||||||
@ -204,23 +209,18 @@ class BridgeComponent(ComponentXMPP):
|
|||||||
reason="Bridging Discord and XMPP")
|
reason="Bridging Discord and XMPP")
|
||||||
self._webhooks[muc] = wh
|
self._webhooks[muc] = wh
|
||||||
|
|
||||||
# TODO: Check if we need to set it
|
|
||||||
# Make sure our virtual users can join
|
# Make sure our virtual users can join
|
||||||
affiliation_delta = [
|
affiliation_list = await self.plugin["xep_0045"].get_affiliation_list(muc,
|
||||||
(self.spoof_member_jid(member.id).bare, "member") for member in dchannel.members
|
"member",
|
||||||
]
|
ifrom=self._bot_jid_full)
|
||||||
|
|
||||||
for member in dchannel.members:
|
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,
|
await self.plugin["xep_0045"].set_affiliation(muc,
|
||||||
"member",
|
"member",
|
||||||
jid=self.spoof_member_jid(member.id).bare,
|
jid=bare_member_jid,
|
||||||
ifrom=self._bot_jid_full)
|
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.virtual_user_join_muc(muc, member, update_state_tracking=False)
|
||||||
|
|
||||||
self._logger.info("%s is ready", muc)
|
self._logger.info("%s is ready", muc)
|
||||||
|
Loading…
Reference in New Issue
Block a user