Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PresenceController.cs #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions DiscordBot.App/Controllers/PresenceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,38 @@ namespace DiscordBot.Controllers;
public class PresenceController : ControllerBase
{
private readonly DiscordService _discordService;
// create a new variable in the database, instead of 400 this must be fetched from said database
private int allTimeHighPlayerCount = 400;

public PresenceController(DiscordService discordService)
{
_discordService = discordService;
}

private async Task SendMessageToGeneralChannel(string message)
{
DiscordChannel generalChannel = _discordService.GeneralChannel;

if (generalChannel != null)
{
await generalChannel.SendMessageAsync(message);
}
}

[HttpPost(Name = "players")]
public async Task PostPlayers(int playerCount)
{
Log.Information("Post players");
await _discordService.Client.UpdateStatusAsync(new DiscordActivity($"with {playerCount} players!", ActivityType.Playing));

if(playerCount > allTimeHighPlayerCount)
{
await _discordService.Client.UpdateStatusAsync(new DiscordActivity($"with a all time high of {allTimeHighPlayerCount} players!", ActivityType.Custom, ActivityProperties.None, "Roleplaying"));
//create post to replace allTimePlayerCount : allTimeHighPlayerCount = playerCount
SendMessageToGeneralChannel($"We hit a all time peak of {allTimeHighPlayerCount} players!!!");
}
else
{
await _discordService.Client.UpdateStatusAsync(new DiscordActivity($"with {playerCount} players!", ActivityType.Custom, ActivityProperties.None, "Roleplaying"));
}
}
}
}