fork of https://f-hub.org/XMPP/xmpp-discord-bridge

xmpp: Better mirror channel name and description

+29 -4
+29 -4
xmpp_discord_bridge/main.py
··· 145 145 pfrom=self._bot_jid_full) 146 146 147 147 # Set the subject 148 - subject = dchannel.topic or "" 149 - self.plugin["xep_0045"].set_subject(muc, 150 - subject, 151 - mfrom=self._bot_jid_full) 148 + room_config = await self.plugin["xep_0045"].get_room_config(muc, 149 + ifrom=self._bot_jid_full) 150 + room_config_fields = room_config.get_values() 151 + should_update = False 152 + description = room_config_fields.get("muc#roomconfig_roomdesc", None) 153 + name = room_config_fields.get("muc#roomconfig_roomname", None) 154 + room_config.reply() 155 + if not description or description != (dchannel.topic or ""): 156 + should_update = True 157 + room_config.set_values({ 158 + "muc#roomconfig_roomdesc": dchannel.topic or "" 159 + }) 160 + self.plugin["xep_0045"].set_subject(muc, 161 + dchannel.topic or "", 162 + mfrom=self._bot_jid_full) 163 + 164 + if not name or name != dchannel.name: 165 + should_update = True 166 + room_config.set_values({ 167 + "muc#roomconfig_roomname": dchannel.name 168 + }) 169 + 170 + # NOTE: To prevent messages in clients that the roomconfig changed at every restart, 171 + # check first if we really have to change stuff 172 + if should_update: 173 + await self.plugin["xep_0045"].set_room_config(muc, 174 + room_config, 175 + ifrom=self._bot_jid_full) 152 176 153 177 # TODO: Is this working? 154 178 # Mirror the guild's icon ··· 158 182 vcard = self.plugin["xep_0054"].make_vcard() 159 183 vcard["PHOTO"]["TYPE"] = "image/png" 160 184 vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon) 185 + # TODO: Replace with provided API 161 186 self.send_raw(""" 162 187 <iq type="set" from="{}" to="{}"> 163 188 <vCard xmlns="vcard-temp">