Rafael Wenzel bio photo

Rafael Wenzel

Modern web expert

Twitter Github Stackoverflow

Just a short one today, as I just finished up adding another nice function to the IRC bot, where users can transfer points to other users, if they have enough. I was just proud of this erlang function, as I just see how my skills progress. So here we go.

transfer_points(_Sender, Parts) when length(Parts) < 2 -> ok;
transfer_points(_Sender, Parts) ->
  [_Receiver|[_Points|_]] = Parts,
  IPoints = list_to_integer(_Points),
  case ets:lookup(points, _Sender) of
    [{_Sender, NPoints}|_] when NPoints >= IPoints, IPoints > 0 -> remove_points(?SELF,[_Sender,_Points]),
    _ -> ok