Skip to content

Commit

Permalink
Queue name trimming
Browse files Browse the repository at this point in the history
Added pickup queue name trimming since name can incorrectly contain spaces and/or quotations
Bumped version nr
  • Loading branch information
Floydan committed Sep 6, 2020
1 parent ff4ad22 commit c23545a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions PickupBot.Commands/Modules/Pickup/PickupListModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Discord;
Expand Down Expand Up @@ -106,6 +107,8 @@ public async Task Create(
if (!await _miscCommandService.VerifyUserFlaggedStatus((IGuildUser)Context.User, Context.Channel).ConfigureAwait(false))
return;

queueName = queueName.Trim(' ', '"').Trim();

//find queue with name {queueName}
var queue = await _queueRepository.FindQueue(queueName, Context.Guild.Id.ToString()).ConfigureAwait(false);

Expand Down Expand Up @@ -133,6 +136,9 @@ public async Task Rename([Name("Queue name")] string queueName, [Name("New name"
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel)) return;

queueName = queueName.Trim(' ', '"').Trim();
newName = newName.Trim(' ', '"').Trim();

var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel).ConfigureAwait(false);
if (queue == null) return;

Expand Down Expand Up @@ -181,6 +187,8 @@ public async Task Update(
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _listCommandService.UpdateOperators(queueName, operators, (SocketGuildUser)Context.User).ConfigureAwait(false);

Expand All @@ -204,6 +212,8 @@ public async Task Delete([Name("Queue name"), Summary("Queue name"), Remainder]
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel).ConfigureAwait(false);
if (queue == null)
{
Expand Down Expand Up @@ -304,6 +314,8 @@ public async Task WaitList([Name("Queue name"), Summary("Queue name"), Remainder
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _queueRepository.FindQueue(queueName, Context.Guild.Id.ToString());

Expand Down Expand Up @@ -332,6 +344,8 @@ public async Task Promote([Name("Queue name"), Summary("Queue name"), Remainder]
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

PickupQueue queue = null;
if (!string.IsNullOrWhiteSpace(queueName))
Expand All @@ -358,6 +372,8 @@ public async Task Promote([Name("Queue name"), Summary("Queue name"), Remainder]
public async Task Start([Name("Queue name"), Summary("Queue name"), Remainder] string queueName)
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel)) return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel).ConfigureAwait(false);
if (queue == null || queue.Started) return;
Expand Down Expand Up @@ -418,6 +434,8 @@ public async Task Teams([Name("Queue name"), Remainder] string queueName)
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel).ConfigureAwait(false);
if (queue == null) return;
Expand All @@ -437,6 +455,8 @@ public async Task Stop([Name("Queue name"), Summary("Queue name")]string queueNa
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

var queue = await _miscCommandService.VerifyQueueByName(queueName, (IGuildChannel)Context.Channel).ConfigureAwait(false);
if (queue == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public async Task Add([Name("Queue name"), Summary("Queue name"), Remainder]stri
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

//find queue with name {queueName}
await _subscriberCommandService.Add(queueName, Context.Channel, (IGuildUser)Context.User).ConfigureAwait(false);
Expand All @@ -51,6 +53,8 @@ public async Task Add([Name("Queue name"), Summary("Queue name"), Remainder]stri
{
if (!PickupHelpers.IsInPickupChannel((IGuildChannel)Context.Channel))
return;

queueName = queueName.Trim(' ', '"').Trim();

if (string.IsNullOrWhiteSpace(queueName))
{
Expand Down
2 changes: 1 addition & 1 deletion PickupBot/PickupBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<UserSecretsId>a7bb364b-0d73-420c-a3b9-18270f20e20f</UserSecretsId>
<Version>1.16.0</Version>
<Version>1.17.0</Version>
<Authors>Joakim Höglund</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Floydan/discord-pickup-bot</PackageProjectUrl>
Expand Down

0 comments on commit c23545a

Please sign in to comment.