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

Configurable mirroring of discord description, icon

+39 -34
+39 -34
xmpp_discord_bridge/main.py
··· 68 68 self._muc_mention_compat = self._config["general"].get("muc_mention_compat", True) 69 69 self._remove_url_on_embed = self._config["general"].get("remove_url_on_embed", False) 70 70 71 + self._mirror_subject = self._config["general"].get("mirror_subject", True) 72 + self._mirror_icon = self._config["general"].get("mirror_icon", True) 73 + 71 74 register_stanza_plugin(XMPPMessage, OOBData) 72 75 register_stanza_plugin(XMPPMessage, StanzaID) 73 76 register_stanza_plugin(XMPPMessage, Reply) ··· 169 172 presence_options=presence_options).send() 170 173 self._logger.info("Joined %s as %s", muc, self._bot_jid_full) 171 174 172 - # Set the subject 173 - room_config = await self.plugin["xep_0045"].get_room_config(muc, 174 - ifrom=self._bot_jid_full) 175 - room_config_fields = room_config.get_values() 176 - should_update = False 177 - description = room_config_fields.get("muc#roomconfig_roomdesc", None) 178 - name = room_config_fields.get("muc#roomconfig_roomname", None) 179 - room_config.reply() 180 - if not description or description != (dchannel.topic or ""): 181 - should_update = True 182 - room_config.set_values({ 183 - "muc#roomconfig_roomdesc": dchannel.topic or "No topic" 184 - }) 185 - self.plugin["xep_0045"].set_subject(muc, 186 - dchannel.topic or "No subject", 187 - mfrom=self._bot_jid_full) 175 + if self._mirror_subject: 176 + # Set the subject 177 + room_config = await self.plugin["xep_0045"].get_room_config(muc, 178 + ifrom=self._bot_jid_full) 179 + room_config_fields = room_config.get_values() 180 + should_update = False 181 + description = room_config_fields.get("muc#roomconfig_roomdesc", None) 182 + name = room_config_fields.get("muc#roomconfig_roomname", None) 183 + room_config.reply() 184 + if not description or description != (dchannel.topic or ""): 185 + should_update = True 186 + room_config.set_values({ 187 + "muc#roomconfig_roomdesc": dchannel.topic or "No topic" 188 + }) 189 + self.plugin["xep_0045"].set_subject(muc, 190 + dchannel.topic or "No subject", 191 + mfrom=self._bot_jid_full) 188 192 189 - if not name or name != dchannel.name: 190 - should_update = True 191 - room_config.set_values({ 192 - "muc#roomconfig_roomname": dchannel.name 193 - }) 193 + if not name or name != dchannel.name: 194 + should_update = True 195 + room_config.set_values({ 196 + "muc#roomconfig_roomname": dchannel.name 197 + }) 194 198 195 - # NOTE: To prevent messages in clients that the roomconfig changed at every restart, 196 - # check first if we really have to change stuff 197 - if should_update: 198 - await self.plugin["xep_0045"].set_room_config(muc, 199 - room_config, 200 - ifrom=self._bot_jid_full) 199 + # NOTE: To prevent messages in clients that the roomconfig changed at every restart, 200 + # check first if we really have to change stuff 201 + if should_update: 202 + await self.plugin["xep_0045"].set_room_config(muc, 203 + room_config, 204 + ifrom=self._bot_jid_full) 201 205 202 206 # TODO: Is this working? 203 207 # Mirror the guild's icon 204 - icon_url = dchannel.guild.icon.url 205 - if icon_url: 206 - req = requests.get(icon_url) 208 + if self._mirror_icon: 209 + icon_url = dchannel.guild.icon.url 210 + if icon_url: 211 + req = requests.get(icon_url) 207 212 208 - vcard = self.plugin["xep_0054"].make_vcard() 209 - vcard["PHOTO"]["TYPE"] = "image/png" 210 - vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content) 211 - await self.plugin["xep_0054"].publish_vcard(vcard) 213 + vcard = self.plugin["xep_0054"].make_vcard() 214 + vcard["PHOTO"]["TYPE"] = "image/png" 215 + vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content) 216 + await self.plugin["xep_0054"].publish_vcard(vcard) 212 217 213 218 # Acquire a webhook 214 219 wh = None