Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ItsOnlyBinary/de30bb24b7ea3cb4c796cbd1d3bb2268 to your computer and use it in GitHub Desktop.
Save ItsOnlyBinary/de30bb24b7ea3cb4c796cbd1d3bb2268 to your computer and use it in GitHub Desktop.
kiwi.plugin('avatars', (kiwi) => {
kiwi.on('irc.join', (event, net) => {
kiwi.Vue.nextTick(() => {
updateAvatar(net, event.nick);
});
});
kiwi.on('irc.wholist', (event, net) => {
let nicks = event.users.map((user) => user.nick);
kiwi.Vue.nextTick(() => {
nicks.forEach((nick) => {
updateAvatar(net, nick, false);
});
});
});
kiwi.on('irc.account', (event, net) => {
kiwi.Vue.nextTick(() => {
updateAvatar(net, event.nick, true);
});
});
function updateAvatar(net, nick, _force) {
let force = !!_force;
let user = kiwi.state.getUser(net.id, nick);
if (!user) {
return;
}
if (!force && user.avatar && user.avatar.small) {
return;
}
let url = (user.account) ?
'https://www.example.com/profiles/' + user.account + '.jpg' :
'https://www.example.com/noprofile.jpg';
user.avatar.small = url;
user.avatar.large = url;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment