Skip to content

Commit

Permalink
Moved names to constants
Browse files Browse the repository at this point in the history
Removed additiona ConfigureAwait calls
Bumped version to v1.18.1
  • Loading branch information
Floydan committed Nov 20, 2020
1 parent ae811f0 commit f881305
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 114 deletions.
12 changes: 12 additions & 0 deletions PickupBot.Commands/Constants/CategoryNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PickupBot.Commands.Constants
{
public class CategoryNames
{
public const string Pickups = "Pickups";
public const string PickupVoiceChannels = "Pickup voice channels";
}
}
14 changes: 14 additions & 0 deletions PickupBot.Commands/Constants/ChannelNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PickupBot.Commands.Constants
{
public class ChannelNames
{
public const string ActivePickups = "active-pickups";
public const string Pickup = "pickup";

public const string Duel = "duel";
}
}
12 changes: 12 additions & 0 deletions PickupBot.Commands/Constants/RoleNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace PickupBot.Commands.Constants
{
public class RoleNames
{
public const string PickupPromote = "pickup-promote";
public const string Duellist = "duellist";
}
}
9 changes: 5 additions & 4 deletions PickupBot.Commands/Infrastructure/Helpers/PickupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using PickupBot.Commands.Constants;
using PickupBot.Data.Models;

namespace PickupBot.Commands.Infrastructure.Helpers
Expand All @@ -15,14 +16,14 @@ public static async Task<IVoiceChannel> GetOrCreateVoiceChannel(string name, ulo
?? await guild.CreateVoiceChannelAsync(name, properties => properties.CategoryId = categoryId);
}

public static bool IsInPickupChannel(IChannel channel) => channel.Name.StartsWith("pickup", StringComparison.OrdinalIgnoreCase);
public static bool IsInDuelChannel(IChannel channel) => channel.Name.Equals("duel", StringComparison.OrdinalIgnoreCase);
public static bool IsInPickupChannel(IChannel channel) => channel.Name.StartsWith(ChannelNames.Pickup, StringComparison.OrdinalIgnoreCase);
public static bool IsInDuelChannel(IChannel channel) => channel.Name.Equals(ChannelNames.Duel, StringComparison.OrdinalIgnoreCase);

public static async Task<ITextChannel> GetPickupQueuesChannel(SocketGuild guild)
{
var queuesChannel = (ITextChannel)guild.TextChannels.FirstOrDefault(c =>
c.Name.Equals("active-pickups", StringComparison.OrdinalIgnoreCase)) ??
await guild.CreateTextChannelAsync("active-pickups",
c.Name.Equals(ChannelNames.ActivePickups, StringComparison.OrdinalIgnoreCase)) ??
await guild.CreateTextChannelAsync(ChannelNames.ActivePickups,
properties => { properties.Topic = "Active pickups, use reactions to signup"; });
return queuesChannel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using PickupBot.Commands.Constants;
using PickupBot.Commands.Extensions;
using PickupBot.Commands.Infrastructure.Helpers;
using PickupBot.Commands.Infrastructure.Utilities;
Expand Down Expand Up @@ -147,7 +148,7 @@ public async Task Promote(PickupQueue queue, ITextChannel pickupChannel, IGuildU
return;
}

var role = guild.Roles.FirstOrDefault(w => w.Name == "pickup-promote");
var role = guild.Roles.FirstOrDefault(w => w.Name == RoleNames.PickupPromote);
if (role == null) return; //Failed to get role;

var users = guild.Users.Where(w => w.Roles.Any(r => r.Id == role.Id)).ToList();
Expand Down
15 changes: 7 additions & 8 deletions PickupBot.Commands/Infrastructure/Services/MiscCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public MiscCommandService(

public async Task<PickupQueue> VerifyQueueByName(string queueName, IGuildChannel channel)
{
var queue = await _queueRepository.FindQueue(queueName, channel.Guild.Id.ToString()).ConfigureAwait(false);
var queue = await _queueRepository.FindQueue(queueName, channel.Guild.Id.ToString());

if (queue != null) return queue;

await ((ITextChannel)channel).SendMessageAsync($"`Queue with the name '{queueName}' doesn't exists!`").AutoRemoveMessage(10).ConfigureAwait(false);
await ((ITextChannel)channel).SendMessageAsync($"`Queue with the name '{queueName}' doesn't exists!`").AutoRemoveMessage(10);
return null;
}

public async Task<bool> VerifyUserFlaggedStatus(IGuildUser user, ISocketMessageChannel channel)
{
var flagged = await _flagRepository.IsFlagged(user).ConfigureAwait(false);
var flagged = await _flagRepository.IsFlagged(user);
if (flagged == null) return true;

var sb = new StringBuilder()
Expand All @@ -73,19 +73,18 @@ public async Task<bool> VerifyUserFlaggedStatus(IGuildUser user, ISocketMessageC
}.Build();

await channel.SendMessageAsync(embed: embed)
.AutoRemoveMessage(10)
.ConfigureAwait(false);
.AutoRemoveMessage(10);

return false;
}

public void TriggerDelayedRconNotification(PickupQueue queue)
{
// 2 minute delay message
AsyncUtilities.DelayAction(TimeSpan.FromMinutes(2), async t => { await TriggerRconNotification(queue).ConfigureAwait(false); });
AsyncUtilities.DelayAction(TimeSpan.FromMinutes(2), async t => { await TriggerRconNotification(queue); });

// 4 minute delay message
AsyncUtilities.DelayAction(TimeSpan.FromMinutes(4), async t => { await TriggerRconNotification(queue).ConfigureAwait(false); });
AsyncUtilities.DelayAction(TimeSpan.FromMinutes(4), async t => { await TriggerRconNotification(queue); });
}

[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
Expand Down Expand Up @@ -121,7 +120,7 @@ public async Task TriggerRconNotification(PickupQueue queue)
$"^1RED TEAM: ^5{string.Join(", ", redTeam.Subscribers.Select(w => w.Name))} ^7- " +
$"^4BLUE TEAM: ^5{string.Join(", ", blueTeam.Subscribers.Select(w => w.Name))}\"";

await RCON.UDPSendCommand(command, rconHost, rconPassword, rconPort, true).ConfigureAwait(false);
await RCON.UDPSendCommand(command, rconHost, rconPassword, rconPort, true);

}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using PickupBot.Commands.Constants;
using PickupBot.Commands.Extensions;
using PickupBot.Commands.Infrastructure.Helpers;
using PickupBot.Data.Models;
Expand Down Expand Up @@ -65,24 +66,28 @@ public async Task Add(string queueName, ISocketMessageChannel channel, IGuildUse

queue.Updated = DateTime.UtcNow;

bool updateStaticMessage = false;

if (queue.Subscribers.Count >= queue.MaxInQueue)
{
if (queue.WaitingList.All(w => w.Id != user.Id))
{
queue.WaitingList.Add(new Subscriber { Id = user.Id, Name = PickupHelpers.GetNickname(user) });
queue = await _listCommandService.SaveStaticQueueMessage(queue, guild);
updateStaticMessage = true;

await channel.SendMessageAsync($"`You have been added to the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
if(channel.Name != ChannelNames.ActivePickups)
await channel.SendMessageAsync($"`You have been added to the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
}
else
{
await channel.SendMessageAsync($"`You are already on the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
if(channel.Name != ChannelNames.ActivePickups)
await channel.SendMessageAsync($"`You are already on the '{queue.Name}' waiting list`").AutoRemoveMessage(10);
}
}
else
{
updateStaticMessage = true;
queue.Subscribers.Add(new Subscriber { Id = user.Id, Name = PickupHelpers.GetNickname(user) });
queue = await _listCommandService.SaveStaticQueueMessage(queue, guild);

if (queue.Subscribers.Count == queue.MaxInQueue)
{
Expand All @@ -92,11 +97,18 @@ await PickupHelpers.NotifyUsers(
user,
queue.Subscribers.Select(s => guild.GetUser(s.Id)).Where(u => u != null).ToArray());
}

if(channel.Name != ChannelNames.ActivePickups)
await channel.SendMessageAsync($"`{queue.Name} - {PickupHelpers.ParseSubscribers(queue)}`");
}

await channel.SendMessageAsync($"`{queue.Name} - {PickupHelpers.ParseSubscribers(queue)}`");
if (updateStaticMessage)
{
queue = await _listCommandService.SaveStaticQueueMessage(queue, guild);
}

await _queueRepository.UpdateQueue(queue);
await _activitiesRepository.Update(activity);
}

public async Task<PickupQueue> Leave(PickupQueue queue, ISocketMessageChannel channel, IGuildUser user, bool notify = true)
Expand Down
5 changes: 3 additions & 2 deletions PickupBot.Commands/Modules/DuelModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Discord;
using Discord.Commands;
using Microsoft.Extensions.Logging;
using PickupBot.Commands.Constants;
using PickupBot.Commands.Extensions;
using PickupBot.Commands.Infrastructure.Helpers;
using PickupBot.Data.Models;
Expand Down Expand Up @@ -444,8 +445,8 @@ private static SkillLevel Parse(string level)
}

private async Task<IRole> GetDuellistRole() =>
Context.Guild.Roles.FirstOrDefault(r => r.Name.Equals("duellist", StringComparison.OrdinalIgnoreCase)) ??
(IRole)await Context.Guild.CreateRoleAsync("duellist", GuildPermissions.None, isHoisted: false, isMentionable: false);
Context.Guild.Roles.FirstOrDefault(r => r.Name.Equals(RoleNames.Duellist, StringComparison.OrdinalIgnoreCase)) ??
(IRole)await Context.Guild.CreateRoleAsync(RoleNames.Duellist, GuildPermissions.None, isHoisted: false, isMentionable: false);

}
}
Loading

0 comments on commit f881305

Please sign in to comment.