Skip to content
Merged
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
29 changes: 22 additions & 7 deletions DiscordBot/Modules/TipModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ private bool IsAuthorized(IUser user)
[Command("Tip")]
[Summary("Find and provide pre-authored tips (images or text) by their keywords.")]
/* removing [RequireModerator] for custom check */
public async Task Tip(string keywords)
public async Task Tip(params string[] keywords)
{
var user = Context.Message.Author;
if (!IsAuthorized(user))
return;

var tips = TipService.GetTips(keywords);
var terms = string.Join(",", keywords);
var tips = TipService.GetTips(terms);
if (tips.Count == 0)
{
await ReplyAsync("No tips for the keywords provided were found.");
Expand Down Expand Up @@ -173,15 +174,29 @@ public async Task ReloadTipDatabase()
[Command("ListTips")]
[Summary("List available tips by their keywords.")]
/* removing [RequireModerator] for custom check */
public async Task ListTips()
public async Task ListTips(params string[] keywords)
{
var user = Context.Message.Author;
if (!IsAuthorized(user))
return;

List<Tip> tips = TipService.GetAllTips().OrderBy(t => t.Id).ToList();
List<Tip> tips = null;
if (keywords?.Length > 0)
{
var terms = string.Join(",", keywords);
tips = TipService.GetTips(terms);
if (tips.Count == 0)
{
await ReplyAsync("No tips for the keywords provided were found.");
return;
}
}
else
{
tips = TipService.GetAllTips().OrderBy(t => t.Id).ToList();
}
int chunkCount = 10;
int chunkTime = 2000;
int chunkTime = 1500;
bool first = true;

while (tips.Count > 0)
Expand All @@ -198,11 +213,11 @@ public async Task ListTips()
int chunk = 0;
while (tips.Count > 0 && chunk < chunkCount)
{
string keywords = string.Join("`, `", tips[0].Keywords.OrderBy(k => k));
string keywordlist = string.Join("`, `", tips[0].Keywords.OrderBy(k => k));
string images = String.Concat(
Enumerable.Repeat(" :frame_photo:",
tips[0].ImagePaths.Count).ToArray());
builder.AddField($"ID: {tips[0].Id} {images}", $"`{keywords}`");
builder.AddField($"ID: {tips[0].Id} {images}", $"`{keywordlist}`");
tips.RemoveAt(0);
chunk++;
}
Expand Down
Loading