Skip to content

Instantly share code, notes, and snippets.

@ItsOnlyBinary
Last active July 24, 2022 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ItsOnlyBinary/d7e6f2adf8d371de131a5c5de97e885d to your computer and use it in GitHub Desktop.
Save ItsOnlyBinary/d7e6f2adf8d371de131a5c5de97e885d to your computer and use it in GitHub Desktop.
kiwiirc-plugin-robohash.js
kiwi.plugin('robohash', (kiwi) => {
const avatarUrl = 'https://robohash.org/%NICK%.png?set=set1&size=%SIZE%';
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);
});
});
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();
let url = avatarUrl.replace('%NICK%', lcNick);
user.avatar.small = url.replace('%SIZE%', '50x50');
user.avatar.large = url.replace('%SIZE%', '200x200');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment