tangled
alpha
login
or
join now
zenfyr.dev
/
xmpp-discord-bridge
0
fork
atom
fork of https://f-hub.org/XMPP/xmpp-discord-bridge
0
fork
atom
overview
issues
pulls
pipelines
Configurable mirroring of discord description, icon
James Shiffer
1 year ago
0f209add
52c51ec5
+39
-34
1 changed file
expand all
collapse all
unified
split
xmpp_discord_bridge
main.py
+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
71
+
self._mirror_subject = self._config["general"].get("mirror_subject", True)
72
72
+
self._mirror_icon = self._config["general"].get("mirror_icon", True)
73
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
172
-
# Set the subject
173
173
-
room_config = await self.plugin["xep_0045"].get_room_config(muc,
174
174
-
ifrom=self._bot_jid_full)
175
175
-
room_config_fields = room_config.get_values()
176
176
-
should_update = False
177
177
-
description = room_config_fields.get("muc#roomconfig_roomdesc", None)
178
178
-
name = room_config_fields.get("muc#roomconfig_roomname", None)
179
179
-
room_config.reply()
180
180
-
if not description or description != (dchannel.topic or ""):
181
181
-
should_update = True
182
182
-
room_config.set_values({
183
183
-
"muc#roomconfig_roomdesc": dchannel.topic or "No topic"
184
184
-
})
185
185
-
self.plugin["xep_0045"].set_subject(muc,
186
186
-
dchannel.topic or "No subject",
187
187
-
mfrom=self._bot_jid_full)
175
175
+
if self._mirror_subject:
176
176
+
# Set the subject
177
177
+
room_config = await self.plugin["xep_0045"].get_room_config(muc,
178
178
+
ifrom=self._bot_jid_full)
179
179
+
room_config_fields = room_config.get_values()
180
180
+
should_update = False
181
181
+
description = room_config_fields.get("muc#roomconfig_roomdesc", None)
182
182
+
name = room_config_fields.get("muc#roomconfig_roomname", None)
183
183
+
room_config.reply()
184
184
+
if not description or description != (dchannel.topic or ""):
185
185
+
should_update = True
186
186
+
room_config.set_values({
187
187
+
"muc#roomconfig_roomdesc": dchannel.topic or "No topic"
188
188
+
})
189
189
+
self.plugin["xep_0045"].set_subject(muc,
190
190
+
dchannel.topic or "No subject",
191
191
+
mfrom=self._bot_jid_full)
188
192
189
189
-
if not name or name != dchannel.name:
190
190
-
should_update = True
191
191
-
room_config.set_values({
192
192
-
"muc#roomconfig_roomname": dchannel.name
193
193
-
})
193
193
+
if not name or name != dchannel.name:
194
194
+
should_update = True
195
195
+
room_config.set_values({
196
196
+
"muc#roomconfig_roomname": dchannel.name
197
197
+
})
194
198
195
195
-
# NOTE: To prevent messages in clients that the roomconfig changed at every restart,
196
196
-
# check first if we really have to change stuff
197
197
-
if should_update:
198
198
-
await self.plugin["xep_0045"].set_room_config(muc,
199
199
-
room_config,
200
200
-
ifrom=self._bot_jid_full)
199
199
+
# NOTE: To prevent messages in clients that the roomconfig changed at every restart,
200
200
+
# check first if we really have to change stuff
201
201
+
if should_update:
202
202
+
await self.plugin["xep_0045"].set_room_config(muc,
203
203
+
room_config,
204
204
+
ifrom=self._bot_jid_full)
201
205
202
206
# TODO: Is this working?
203
207
# Mirror the guild's icon
204
204
-
icon_url = dchannel.guild.icon.url
205
205
-
if icon_url:
206
206
-
req = requests.get(icon_url)
208
208
+
if self._mirror_icon:
209
209
+
icon_url = dchannel.guild.icon.url
210
210
+
if icon_url:
211
211
+
req = requests.get(icon_url)
207
212
208
208
-
vcard = self.plugin["xep_0054"].make_vcard()
209
209
-
vcard["PHOTO"]["TYPE"] = "image/png"
210
210
-
vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content)
211
211
-
await self.plugin["xep_0054"].publish_vcard(vcard)
213
213
+
vcard = self.plugin["xep_0054"].make_vcard()
214
214
+
vcard["PHOTO"]["TYPE"] = "image/png"
215
215
+
vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content)
216
216
+
await self.plugin["xep_0054"].publish_vcard(vcard)
212
217
213
218
# Acquire a webhook
214
219
wh = None