Skip to content

Commit

Permalink
Added Component Lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Glowstudent777 committed Aug 1, 2023
1 parent d4045af commit 9fbdd08
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 106 deletions.
6 changes: 6 additions & 0 deletions Bot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33712.159
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot", "Bot\Bot.csproj", "{B34BEC68-5B8A-4A3F-9A8A-2BE053BC78E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentLib", "ComponentLib\ComponentLib.csproj", "{632BFA9C-D9C8-4729-B1E8-8B4F466AE2BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{B34BEC68-5B8A-4A3F-9A8A-2BE053BC78E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B34BEC68-5B8A-4A3F-9A8A-2BE053BC78E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B34BEC68-5B8A-4A3F-9A8A-2BE053BC78E1}.Release|Any CPU.Build.0 = Release|Any CPU
{632BFA9C-D9C8-4729-B1E8-8B4F466AE2BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{632BFA9C-D9C8-4729-B1E8-8B4F466AE2BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{632BFA9C-D9C8-4729-B1E8-8B4F466AE2BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{632BFA9C-D9C8-4729-B1E8-8B4F466AE2BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions Bot/Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
<Folder Include="Migrations\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ComponentLib\ComponentLib.csproj" />
</ItemGroup>

</Project>
105 changes: 0 additions & 105 deletions Bot/Modules/Buttons/StyleCycler.cs

This file was deleted.

4 changes: 3 additions & 1 deletion Bot/Modules/Interaction/GeneralModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public async Task DisplayButtons()

var buttons = new ActionRowBuilder()
.AddComponent(ButtonComponents.ToggleButton("Toggle Me", "toggle", false, ButtonStyle.Success))
.AddComponent(ButtonComponents.TriButton("Cycle Me", "cycle", false, ButtonStyle.Success));
.AddComponent(ButtonComponents.TriButton("Cycle Me", "cycle", false, ButtonStyle.Success))
.AddComponent(ComponentLib.Buttons.ToggleButton("Lib Toggle", "toggle1", false, ButtonStyle.Success))
.AddComponent(ComponentLib.Buttons.TriButton("Lib Toggle", "cycle1", false, ButtonStyle.Success));

var actionRow = new ComponentBuilder()
.AddRow(buttons)
Expand Down
12 changes: 12 additions & 0 deletions Bot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;

using ComponentLib;

namespace Bot
{
public class Startup
Expand Down Expand Up @@ -62,12 +64,22 @@ public async Task InstallCommandsAsync()

var assembly = Assembly.GetEntryAssembly();
_interactionModules = await _interactions.AddModulesAsync(assembly, _services);

// add modules from ComponentLib
_interactionModules = _interactionModules.Concat(await _interactions.AddModulesAsync(typeof(ComponentLib.ComponentLib).Assembly, new ComponentLib.ComponentLib()._services));
}

private async Task RegisterCommands(DiscordSocketClient client)
{
if (client.ShardId != 0) return;

_ = new ComponentLib.ComponentLib().Initialize(_client);
await _interactions.AddModulesGloballyAsync(true, _interactionModules.ToArray());

foreach (var module in _interactionModules)
{
Console.WriteLine($"Registered {module.Name}");
}
}

private static Task LogAsync(LogMessage log)
Expand Down
17 changes: 17 additions & 0 deletions ToggleButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Discord;

namespace ComponentLib
{
public class ToggleButton
{
public static ButtonComponent ToggleButton(string Label, string CustomId, bool IsDisabled = false, ButtonStyle Style = ButtonStyle.Success)
{
return new ButtonBuilder()
.WithLabel(Label)
.WithCustomId("togglebutton:" + CustomId)
.WithStyle(Style)
.WithDisabled(IsDisabled)
.Build();
}
}
}

0 comments on commit 9fbdd08

Please sign in to comment.