-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da0c685
commit 39b1861
Showing
6 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type Bridge, type Intent, MatrixUser, type message, Buffer } from './deps.ts'; | ||
|
||
export async function ensure_profile(bot: Bridge, mxintent: Intent, channel_id: string, msg: message) { | ||
const store = bot.getUserStore()!; | ||
|
||
let store_user = await store.getMatrixUser(mxintent.userId); | ||
|
||
if (!store_user) { | ||
store_user = new MatrixUser(mxintent.userId); | ||
} | ||
|
||
if ((store_user.get('avatar') !== msg.author.profile) && | ||
msg.author.profile) { | ||
const mxc = await mxintent.uploadContent( | ||
Buffer.from( | ||
await (await fetch(msg.author.profile)).arrayBuffer() | ||
) | ||
); | ||
store_user.set('avatar_mxc', mxc); | ||
} | ||
|
||
await store.setMatrixUser(store_user); | ||
|
||
await mxintent.setRoomUserProfile(channel_id, { | ||
avatar_url: store_user.get('avatar_mxc'), | ||
displayname: msg.author.username, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters