Skip to content

Commit

Permalink
Merge pull request #22 from j4asper/cleanup-embeds
Browse files Browse the repository at this point in the history
Did some cleanup
  • Loading branch information
j4asper authored Dec 31, 2024
2 parents a573466 + b746b71 commit a533dc2
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 76 deletions.
9 changes: 7 additions & 2 deletions KanbanCord.Bot/Commands/RepositoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ public async ValueTask ExecuteAsync(SlashCommandContext context)
var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithAuthor("KanbanCord Repository")
.WithDescription($"**KanbanCord** is an open-source Discord bot licensed under [GPL-3.0]({Source.LicenseUrl}). You can host it yourself, explore the code, or contribute by adding features and fixing bugs. The github repository link is available below.");
.AddField("What is KanbanCord?",
"**KanbanCord** is a powerful open-source Discord bot that integrates Kanban boards into your server for efficient task management and smooth team collaboration. Whether you're managing a project, organizing tasks, or planning events, KanbanCord makes it easy to track progress and stay organized. All within Discord!")
.AddField("Open Source Project",
$"Licensed under the [GPL-3.0]({Source.LicenseUrl}), you’re free to host it yourself, explore the code, and even contribute to its development by adding new features or fixing bugs. Check out the GitHub repository below to get started.");

var response = new DiscordMessageBuilder()
.AddEmbed(embed)
.AddComponents(new DiscordLinkButtonComponent(Source.RepositoryUrl, "Github Repository"));
.AddComponents(
new DiscordLinkButtonComponent(Source.RepositoryUrl, "Github Repository"),
new DiscordLinkButtonComponent($"https://discord.com/oauth2/authorize?client_id={context.Client.CurrentUser.Id}", "Invite Bot"));

await context.RespondAsync(response);
}
Expand Down
14 changes: 6 additions & 8 deletions KanbanCord.Bot/Commands/Task/TaskArchiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ partial class TaskCommandGroup
public async ValueTask TaskArchiveCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<AllTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -39,9 +39,7 @@ partial class TaskCommandGroup

var commands = await context.Client.GetGlobalApplicationCommandsAsync();

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The task \"{taskItem.Title}\" has been moved from **{fromColumn.ToFormattedString()}** to **{BoardStatus.Archived.ToFormattedString()}**. View it using {commands.GetMention(["archive"])}.");

await context.RespondAsync(embed);
Expand Down
12 changes: 5 additions & 7 deletions KanbanCord.Bot/Commands/Task/TaskCommentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ partial class TaskCommandGroup
public async ValueTask TaskCommentCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<AllTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(embed);
return;
Expand Down Expand Up @@ -64,9 +64,7 @@ partial class TaskCommandGroup

var commands = await context.Client.GetGlobalApplicationCommandsAsync();

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"A comment has been added to task \"{taskItem.Title}\". View it using {commands.GetMention(["task", "view"])}.");

await response.Result.Interaction.CreateResponseAsync(
Expand Down
14 changes: 6 additions & 8 deletions KanbanCord.Bot/Commands/Task/TaskCompleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ partial class TaskCommandGroup
public async ValueTask TaskCompleteCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<InProgressTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -37,9 +37,7 @@ partial class TaskCommandGroup

var commands = await context.Client.GetGlobalApplicationCommandsAsync();

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The task \"{taskItem.Title}\" has been completed and moved to the **Completed** column. View it using {commands.GetMention(["board"])}.");

await context.RespondAsync(embed);
Expand Down
13 changes: 6 additions & 7 deletions KanbanCord.Bot/Commands/Task/TaskDeleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ partial class TaskCommandGroup
public async ValueTask TaskDeleteCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<AllTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

var deleteButton = new DiscordButtonComponent(DiscordButtonStyle.Danger, Guid.NewGuid().ToString(), "Delete");

var author = await context.Client.GetUserAsync(taskItem.AuthorId);

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
embed
.WithAuthor("Delete Task")
.WithDescription("Are you sure you want to delete this task?")
.AddField("Title:", taskItem.Title)
Expand Down
17 changes: 9 additions & 8 deletions KanbanCord.Bot/Commands/Task/TaskEditCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ partial class TaskCommandGroup
public async ValueTask TaskEditCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<AllTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(embed);
return;
Expand Down Expand Up @@ -69,12 +69,13 @@ partial class TaskCommandGroup

var commands = await context.Client.GetGlobalApplicationCommandsAsync();

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The task \"{taskItem.Title}\" has been edited. View it using {commands.GetMention(["board"])}.");

await response.Result.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AddEmbed(embed));
await response.Result.Interaction.CreateResponseAsync(
DiscordInteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.AddEmbed(embed));
}
}
}
21 changes: 8 additions & 13 deletions KanbanCord.Bot/Commands/Task/TaskMoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@ public async ValueTask TaskMoveCommand(
[SlashChoiceProvider<ColumnChoiceProvider>] int to)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

if (taskItem.Status == (BoardStatus)to)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
$"The selected task is already in column **{((BoardStatus)to).ToFormattedString()}**.");
embed.WithDescription($"The selected task is already in column **{((BoardStatus)to).ToFormattedString()}**.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -50,9 +47,7 @@ public async ValueTask TaskMoveCommand(

await _taskItemRepository.UpdateTaskItemAsync(taskItem);

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The task \"{taskItem.Title}\" has been moved from **{fromColumn.ToFormattedString()}** to **{((BoardStatus)to).ToFormattedString()}**.");

await context.RespondAsync(embed);
Expand Down
14 changes: 6 additions & 8 deletions KanbanCord.Bot/Commands/Task/TaskPriorityCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public async ValueTask TaskPriorityCommand(
[SlashChoiceProvider<PriorityChoiceProvider>] int priority)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -50,9 +50,7 @@ public async ValueTask TaskPriorityCommand(

await _taskItemRepository.UpdateTaskItemAsync(taskItem);

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The priority for task \"{taskItem.Title}\" has been updated from **{fromPriority.ToString()}** to **{((Priority)priority).ToString()}**.");

await context.RespondAsync(embed);
Expand Down
14 changes: 6 additions & 8 deletions KanbanCord.Bot/Commands/Task/TaskStartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ partial class TaskCommandGroup
public async ValueTask TaskStartCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<BacklogTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -37,9 +37,7 @@ partial class TaskCommandGroup

var commands = await context.Client.GetGlobalApplicationCommandsAsync();

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
embed.WithDescription(
$"The task \"{taskItem.Title}\" has been started and moved to the **In Progress** column. View it using {commands.GetMention(["board"])}.");

await context.RespondAsync(embed);
Expand Down
13 changes: 6 additions & 7 deletions KanbanCord.Bot/Commands/Task/TaskViewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ partial class TaskCommandGroup
public async ValueTask TaskViewCommand(SlashCommandContext context, [Description("Search for the task to select")] [SlashAutoCompleteProvider<AllTaskItemsAutoCompleteProvider>] string task)
{
var taskItem = await _taskItemRepository.GetTaskItemByObjectIdOrDefaultAsync(new ObjectId(task));

var embed = new DiscordEmbedBuilder()
.WithDefaultColor();

if (taskItem is null)
{
var notFoundEmbed = new DiscordEmbedBuilder()
.WithDefaultColor()
.WithDescription(
"The selected task was not found, please try again.");
embed.WithDescription("The selected task was not found, please try again.");

await context.RespondAsync(notFoundEmbed);
await context.RespondAsync(embed);
return;
}

Expand All @@ -47,8 +47,7 @@ partial class TaskCommandGroup
_ => ":orange_circle: Medium"
};

var embed = new DiscordEmbedBuilder()
.WithDefaultColor()
embed
.WithAuthor(author.Username, iconUrl: author.AvatarUrl)
.AddField("Title:", taskItem.Title)
.AddField("Description:", taskItem.Description)
Expand Down

0 comments on commit a533dc2

Please sign in to comment.