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

Feat/new counter n history fixes #4

Merged
merged 3 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions Commands/History/RecordEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public RecordEntity(ulong discordMemberId, CounterCategory category, string moti
public long Timestamp { get; set; }


public override string ToString()
public string ToString(bool shouldIncludeCategory = false)
{
return $"*« {Motive} »* – {DateHelper.FromDateTimeToStringDate(RecordedAt)}";
return shouldIncludeCategory
? $"*« {Motive} »* – {DateHelper.FromDateTimeToStringDate(RecordedAt)} as {Category}"
: $"*« {Motive} »* – {DateHelper.FromDateTimeToStringDate(RecordedAt)}";
}
}
21 changes: 13 additions & 8 deletions Commands/History/RecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ namespace Bishop.Commands.History;
[Description("History-related commands")]
public class RecordService : BaseCommandModule
{
private const int DefaultLimit = 10;
public Random Random { private get; set; } = null!;
public UserNameCache Cache { private get; set; } = null!;
public RecordRepository Repository { private get; set; } = null!;

[Command("rand")]
[Aliases("r")]
[Description("Picks a random record to expose")]
public async Task PickRandom(CommandContext context)
{
Expand Down Expand Up @@ -87,14 +89,14 @@ private async Task Consult(CommandContext context,
[Description("Category to know the history of")]
CounterCategory counterCategory,
[Description("Number of records to pull")]
int? limit = 10
int? limit = DefaultLimit
)
{
var records = await Repository.FindByUserAndCategory(member.Id, counterCategory);
var trueLimit = limit <= 0 ? records.Count : limit ?? records.Count;

if (records.Any())
await FormatRecordList(context, records, trueLimit);
await FormatRecordList(context, records, trueLimit, false);
else
await context.RespondAsync(
$"No history recorded for category user {member.Username} and {counterCategory}");
Expand All @@ -105,13 +107,13 @@ private async Task Consult(CommandContext context,
[Description("@User to know the history of")]
DiscordUser member,
[Description("Number of records to pull")]
int? limit = 10
int? limit = DefaultLimit
)
{
var records = await Repository.FindByUser(member.Id);

if (records.Any())
await FormatRecordList(context, records, limit ?? 10);
await FormatRecordList(context, records, limit ?? DefaultLimit, true);
else
await context.RespondAsync(
$"No history recorded for user {member.Username}");
Expand All @@ -122,24 +124,27 @@ private async Task Consult(CommandContext context,
[Description("Category to pull records of")]
CounterCategory category,
[Description("Number of records to pull")]
int? limit = 10
int? limit = DefaultLimit
)
{
var records = await Repository.FindByCategory(category);

if (records.Any())
await FormatRecordList(context, records, limit ?? 10);
await FormatRecordList(context, records, limit ?? DefaultLimit, false);
else
await context.RespondAsync(
$"No history recorded for category {category}");
}

private async Task FormatRecordList(CommandContext context, IReadOnlyCollection<RecordEntity> records, int limit)
private static async Task FormatRecordList(CommandContext context,
IReadOnlyCollection<RecordEntity> records,
int limit,
bool shouldIncludeCategory)
{
var trueLimit = limit <= 0 ? records.Count : limit;

var toSend = records
.Select(entity => entity.ToString())
.Select(record => record.ToString(shouldIncludeCategory))
.Take(trueLimit)
.ToList();

Expand Down
48 changes: 48 additions & 0 deletions Commands/Meter/Aliases/MaufoiCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;

namespace Bishop.Commands.Meter.Aliases;

public class MaufoiCounter : BaseCommandModule
{
public CounterService Service { private get; set; } = null!;

[Command("maufoi")]
[Description("Adds a provided value to @someone’s maufoi score")]
public async Task ScoreMaufoi(CommandContext context,
[Description("User to increment the maufoi score of")]
DiscordMember member,
[Description("To increment by")] long nb)
{
await Service.Score(context, member, CounterCategory.Maufoi, nb);
}

[Command("maufoi")]
[Description("Returns the value of @someone’s maufoi score")]
public async Task ScoreMaufoi(CommandContext context,
[Description("User to know the maufoi score of")]
DiscordMember member)
{
await Service.Score(context, member, CounterCategory.Maufoi);
}

[Command("maufoi")]
[Description("Returns all maufoi scores")]
public async Task ScoreMaufoi(CommandContext context)
{
await Service.Score(context, CounterCategory.Maufoi);
}

[Command("maufoi")]
[Description("Adds a provided value to @someone’s maufoi score")]
public async Task ScoreMaufoi(CommandContext context,
[Description("User to increment the maufoi score of by 1")]
DiscordMember member,
[RemainingText] [Description("Reason for the increment")]
string reason)
{
await Service.Score(context, member, CounterCategory.Maufoi, reason);
}
}
70 changes: 70 additions & 0 deletions Commands/Meter/Aliases/WindCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;

namespace Bishop.Commands.Meter.Aliases;

public class WindCounter : BaseCommandModule
{
public CounterService Service { private get; set; } = null!;

[Command("wind")]
[Description("Adds a provided value to @someone’s wind score")]
public async Task ScoreWind(CommandContext context,
[Description("User to increment the wind score of")]
DiscordMember member,
[Description("To increment by")] long nb)
{
await Service.Score(context, member, CounterCategory.Wind, nb);
}

[Command("wind")]
[Description("Returns the value of @someone’s wind score")]
public async Task ScoreWind(CommandContext context,
[Description("User to know the wind score of")]
DiscordMember member)
{
await Service.Score(context, member, CounterCategory.Wind);
}

[Command("wind")]
[Description("Returns all wind scores")]
public async Task ScoreWind(CommandContext context)
{
await Service.Score(context, CounterCategory.Wind);
}

[Command("wind")]
[Description("Adds a record to @someone’s wind history and increments their score")]
public async Task ScoreWind(CommandContext context,
[Description("User to increment the wind score of by 1")]
DiscordMember member,
[RemainingText] [Description("Reason for the increment")]
string reason)
{
await Service.Score(context, member, CounterCategory.Wind, reason);
}

[Command("rot")]
[Description("Adds a rot to @someone’s wind history and increments their score")]
public async Task ScoreRot(CommandContext context,
[Description("User to increment the wind score of by 1")]
DiscordMember member,
[RemainingText] [Description("Reason for the increment")]
string reason)
{
await Service.Score(context, member, CounterCategory.Wind, "(rot) " + reason);
}

[Command("pet")]
[Description("Adds a pet to @someone’s wind history and increments their score")]
public async Task ScorePet(CommandContext context,
[Description("User to increment the wind score of by 1")]
DiscordMember member,
[RemainingText] [Description("Reason for the increment")]
string reason)
{
await Service.Score(context, member, CounterCategory.Wind, "(pet) " + reason);
}
}
4 changes: 3 additions & 1 deletion Commands/Meter/CounterCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public enum CounterCategory
Sauce,
Sel,
Beauf,
Rass
Rass,
Maufoi,
Wind
}
5 changes: 4 additions & 1 deletion Config/Converters/MeterKeysConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ public Task<Optional<CounterCategory>> ConvertAsync(string value, CommandContext
{
return value.ToLower() switch
{
"add" => Task.FromResult(Optional.FromValue(CounterCategory.Bdm)),
"bdm" => Task.FromResult(Optional.FromValue(CounterCategory.Bdm)),
"beauf" => Task.FromResult(Optional.FromValue(CounterCategory.Beauf)),
"sauce" => Task.FromResult(Optional.FromValue(CounterCategory.Sauce)),
"sel" => Task.FromResult(Optional.FromValue(CounterCategory.Sel)),
"rass" => Task.FromResult(Optional.FromValue(CounterCategory.Rass)),
"maufoi" => Task.FromResult(Optional.FromValue(CounterCategory.Maufoi)),
"maufoy" => Task.FromResult(Optional.FromValue(CounterCategory.Maufoi)),
"wind" => Task.FromResult(Optional.FromValue(CounterCategory.Maufoi)),
_ => Task.FromResult(Optional.FromNoValue<CounterCategory>())
};
}
Expand Down
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ private static async Task MainAsync()
typeof(BdmCounter),
typeof(BeaufCounter),
typeof(SauceCounter),
typeof(MaufoiCounter),
typeof(SelCounter),
typeof(WindCounter),
typeof(RassCounter),
typeof(CounterService),
typeof(RecordService),
Expand Down