Skip to content

Commit

Permalink
Remove map pool functionality, add configurable url
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdShullah committed Oct 27, 2020
1 parent 0b5b23e commit 2db31c8
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 85 deletions.
15 changes: 0 additions & 15 deletions OsuFriendsApi/Entities/Map.cs

This file was deleted.

2 changes: 1 addition & 1 deletion OsuFriendsApi/Entities/OsuUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal OsuUser(Guid? key, OsuFriendsClient client)
{
Key = key ?? Guid.NewGuid();
_client = client;
UriBuilder uriBuilder = new UriBuilder(OsuFriendsClient.url);
UriBuilder uriBuilder = new UriBuilder(client.Url);
uriBuilder.Path += $"auth/{Key}";
Url = uriBuilder.Uri;
}
Expand Down
11 changes: 0 additions & 11 deletions OsuFriendsApi/Entities/Party.cs

This file was deleted.

38 changes: 3 additions & 35 deletions OsuFriendsApi/OsuFriendsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Newtonsoft.Json;
using OsuFriendsApi.Entities;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -15,7 +14,7 @@ public class OsuFriendsClient
private string _token;
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
public const string url = "https://osufriends.ovh/";
public Uri Url { get; set; } = new Uri("https://osufriends.ovh/");

public OsuFriendsClient(HttpClient httpClient, ILogger<OsuFriendsClient> logger)
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public OsuUser CreateUser(Guid? key = null)

internal async Task<Status?> GetStatusAsync(OsuUser user)
{
UriBuilder uriBuilder = new UriBuilder(url);
UriBuilder uriBuilder = new UriBuilder(Url);
uriBuilder.Path += "status/";

NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
Expand All @@ -67,7 +66,7 @@ public OsuUser CreateUser(Guid? key = null)

internal async Task<OsuUserDetails> GetDetailsAsync(OsuUser user)
{
UriBuilder uriBuilder = new UriBuilder(url);
UriBuilder uriBuilder = new UriBuilder(Url);
uriBuilder.Path += "details/";

NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
Expand All @@ -82,36 +81,5 @@ internal async Task<OsuUserDetails> GetDetailsAsync(OsuUser user)
_logger.LogTrace("Details of {key}: {details}", user.Key, content);
return JsonConvert.DeserializeObject<OsuUserDetails>(content);
}

public async Task<IReadOnlyCollection<Party>> GetPartiesAsync()
{
UriBuilder uriBuilder = new UriBuilder(url);
uriBuilder.Path += "get_parties/";

NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["secret"] = _token;
uriBuilder.Query = query.ToString();

HttpResponseMessage response = await _httpClient.GetAsync(uriBuilder.Uri).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyCollection<Party>>(content);
}

public async Task<IReadOnlyCollection<Map>> GetMappoolAsync(Party party)
{
UriBuilder uriBuilder = new UriBuilder(url);
uriBuilder.Path += "get_mappool/";

NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["secret"] = _token;
query["party"] = party.Id.ToString();
uriBuilder.Query = query.ToString();

HttpResponseMessage response = await _httpClient.GetAsync(uriBuilder.Uri).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyCollection<Map>>(content);
}
}
}
2 changes: 2 additions & 0 deletions OsuFriendsBot/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Serilog.Events;
using System;

namespace OsuFriendsBot
{
public class Config
{
public string Token { get; set; }
public string OsuFriendsApiToken { get; set; }
public Uri OsuFriendsApiUrl { get; set; }
public string Prefix { get; set; }
public string ConnectionString { get; set; }
public string LogPath { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion OsuFriendsBot/Embeds/InfoEmbed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public InfoEmbed(RestApplication app)
ThumbnailUrl = app.IconUrl;
AddField("Author:", app.Owner);
AddField("Git repo:", @"https://github.com/AbdShullah/OsuFriendsBot");
AddField("Bot Version:", "0.0.9");
AddField("Bot Version:", "0.1.0");
Color = EmbedColors.Info;
}
}
Expand Down
22 changes: 0 additions & 22 deletions OsuFriendsBot/Modules/FunModule.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Discord;
using Discord.Commands;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OsuFriendsApi;
using OsuFriendsDb.Services;
using System.Linq;
using System.Threading.Tasks;

namespace OsuFriendsBot.Modules
Expand Down Expand Up @@ -32,25 +30,5 @@ public async Task UwuCmd()
int count = _dbUserData.FindById(Context.User.Id).Uwu;
await ReplyAsync($"{Format.Bold("What's this?")} | {Context.User.Username}, you've {Format.Bold("uwu")}'d {Format.Code(count.ToString())} times");
}

[Command("party")]
[Summary("party")]
public async Task PartyCmd()
{
System.Collections.Generic.IReadOnlyCollection<OsuFriendsApi.Entities.Party> parties = await _osuFriends.GetPartiesAsync();
await ReplyAsync(JsonConvert.SerializeObject(parties));
OsuFriendsApi.Entities.Map x = (await _osuFriends.GetMappoolAsync(parties.First())).First();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder
.WithTitle(x.Name)
.WithDescription(x.Url.ToString())
.AddField("Difficulty", x.Difficulty)
.AddField("Stars", x.Stars)
.AddField("Status", x.Status)
.AddField("BPM", x.Bpm)
.WithImageUrl(x.Image.ToString());

await ReplyAsync(embed: embedBuilder.Build());
}
}
}
6 changes: 6 additions & 0 deletions OsuFriendsBot/Services/StartupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public async Task StartAsync()
{
throw new Exception("Please enter your api token into the `config.json` file found in the applications root directory.");
}

_services.GetRequiredService<OsuFriendsClient>().SetToken(_config.OsuFriendsApiToken);

if (_config.OsuFriendsApiUrl != null)
{
_services.GetRequiredService<OsuFriendsClient>().Url = _config.OsuFriendsApiUrl;
}
_config.OsuFriendsApiToken = string.Empty;

_logger.LogInformation("Setting Discord Bot token");
Expand Down

0 comments on commit 2db31c8

Please sign in to comment.