Send notifications when the user can vote again
MrDoudou opened this issue · comments
To speed up the server's evolution, the administrators ask for as many votes as possible. Unfortunately, the fields aren't 100% up to speed to set an alarm for each vote. We could set up a notification system on discord and/or on the server to motivate fields to vote.
I don't think a notification system is good, however we could have an api in the plugin.
You would have a plugin/addon on the game server that sends to the endpoint a list of users (most likely a list that represent the online users)
Then the endpoint computes the nextVoteTime for all configured site and returns a list. The in-game plugin/addon could then dispatch a message to the players that can vote
Here is a code i wrote a while back for a custom game :
public function fetch_votes(Request $request)
{
$accounts = json_decode($request->input('accounts'));
$users = User::whereIn('id', $accounts)->get();
$sites = Site::enabled()->get();
$result = $users->mapWithKeys(function (User $user) use ($sites) {
return [
$user->id => $sites->map(function (Site $site) use ($user) {
if ($site->getNextVoteTime($user, $user->last_login_ip) === null) {
return $site->name;
}
return '';
})->filter()->values(),
];
});
return response()->json($result);
}
it returns something like :
{
"user_id_1": ["vote-site", "another-vote-site"]
"user_id_2": ["another-vote-site"]
}