Skip to content

Instantly share code, notes, and snippets.

@ItsOnlyBinary
Created June 28, 2022 20:07
Show Gist options
  • Save ItsOnlyBinary/a17d184c02456a258f2d9b43fa9ced96 to your computer and use it in GitHub Desktop.
Save ItsOnlyBinary/a17d184c02456a258f2d9b43fa9ced96 to your computer and use it in GitHub Desktop.
kiwi.plugin('simple-avatars', (kiwi) => {
kiwi.on('irc.join', (event, net) => {
kiwi.Vue.nextTick(() => {
updateAvatar(net, event.nick, false);
});
});
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.nick', (event, net) => {
kiwi.Vue.nextTick(() => {
updateAvatar(net, event.new_nick, true);
});
});
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 lcNick = user.nick.toLowerCase();
user.avatar.small = lcNick + '.png';
user.avatar.large = lcNick + '.png';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment