Skip to content

Commit

Permalink
add /jobs cmd (v0.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
XHyperDEVX committed Nov 30, 2024
1 parent f365fa7 commit 72d9c2d
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 5 deletions.
98 changes: 97 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Program
public static SocketGuild guild;
public static SocketTextChannel logchannel;
public static SocketTextChannel welcomechannel;
public static SocketTextChannel jobchannel;
private static HttpListener healtcheck_host = new HttpListener();
public static void Main(string[] args) => new Program().Startup().GetAwaiter().GetResult();

Expand Down Expand Up @@ -55,6 +56,8 @@ public async Task Startup()
_client.SlashCommandExecuted += SlashCommandHandler;
_client.UserJoined += UserJoinedHandler;
_client.UserLeft += UserLeftHandler;
_client.ModalSubmitted += ModalSubmittedHandler;
_client.MessageReceived += MessageReceivedHandler;

//Connect to Discord
TaskCompletionSource<bool> readyTcs = new TaskCompletionSource<bool>();
Expand Down Expand Up @@ -99,6 +102,7 @@ public async Task SetVariables()
guild = _client.GetGuild(ulong.Parse(Environment.GetEnvironmentVariable("guild_id")));
logchannel = _client.GetChannel(ulong.Parse(Environment.GetEnvironmentVariable("logchannel_id"))) as SocketTextChannel;
welcomechannel = _client.GetChannel(ulong.Parse(Environment.GetEnvironmentVariable("welcomechannel_id"))) as SocketTextChannel;
jobchannel = _client.GetChannel(ulong.Parse(Environment.GetEnvironmentVariable("jobchannel_id"))) as SocketTextChannel;
}

public async Task RegisterCommands()
Expand All @@ -116,6 +120,11 @@ public async Task RegisterCommands()
roadmapcmd.WithName("roadmap");
roadmapcmd.WithDescription("Get the Roadmap");

//jobs cmd
var jobscmd = new SlashCommandBuilder();
jobscmd.WithName("jobs");
jobscmd.WithDescription("Post a job offer (For freelancers looking for work)");

//build message/user context command
//User Commands
//var usercmd = new UserCommandBuilder();
Expand All @@ -131,6 +140,7 @@ await guild.BulkOverwriteApplicationCommandAsync(new ApplicationCommandPropertie
//slash cmds
debugcmd.Build(),
roadmapcmd.Build(),
jobscmd.Build(),

//context cmds
//usercmd.Build(),
Expand Down Expand Up @@ -224,12 +234,98 @@ await command.FollowupAsync(
{
Label = "Roadmap 🚀",
Url = Environment.GetEnvironmentVariable("roadmap_link"),
//Emote = Emote.Parse("🚀"),
Style = ButtonStyle.Link,
});

await command.RespondAsync(embed: roadmap_embed, components: roadmap_button.Build(), ephemeral: true);
}

//handle jobs cmd
if(command.CommandName == "jobs")
{
/*if(command.Channel.Id != jobchannel.Id)
{
var wrongchannel_embed = new EmbedBuilder
{
Title = "You are in the wrong Channel!",
Description = $"For Job offers, switch the Channel to {jobchannel.Mention}",
Color = Color.Red,
}
.Build();
await command.RespondAsync(embed: wrongchannel_embed, ephemeral: true);
return;
}*/

var joboffer_input = new ModalBuilder()
.WithTitle("Job Offer")
.WithCustomId("joboffer_modal")
.AddTextInput("What is your designation?", "designation_input", TextInputStyle.Short, required: true, placeholder:"e.g. Freelancer")
.AddTextInput("Which programming languages do you know?", "p_languages_input", TextInputStyle.Paragraph, required: true, placeholder:"e.g. Python, React, MySQL or C#")
.AddTextInput("How much experience do you already have?", "experience_input", TextInputStyle.Short, required: true, placeholder:"e.g. 4 Years")
.AddTextInput("Do you have a Website? (only if yes)", "website_input", TextInputStyle.Short, required: false, placeholder:"e.g. https://mycoolsite.com")
.AddTextInput("Would you like to add anything else?", "other_input", TextInputStyle.Paragraph, required: false);

await command.RespondWithModalAsync(joboffer_input.Build());

//continue in modal funktion
}
}

private async Task ModalSubmittedHandler(SocketModal modal)
{
if(modal.Data.CustomId == "joboffer_modal")
{
var job_embed = new EmbedBuilder
{
Description = @$"# {modal.Data.Components.First(x => x.CustomId == "designation_input").Value} looking for assignments!
Hi, I'm {modal.User.Mention} and I'm happy to offer you my help with your project!",
Color = Color.Blue,
Footer = new EmbedFooterBuilder().WithText($"Regards, your {modal.User.GlobalName}!").WithIconUrl(modal.User.GetAvatarUrl()),
//Timestamp = (DateTimeOffset.Now)
}
.AddField("Which languages do I know?", modal.Data.Components.First(x => x.CustomId == "p_languages_input").Value)
.AddField("How much experience do I have?", $"{modal.Data.Components.First(x => x.CustomId == "experience_input").Value}{(modal.Data.Components.First(x => x.CustomId == "other_input").Value == "" ? "" : $"\n\n**{modal.Data.Components.First(x => x.CustomId == "other_input").Value}**")}\n\nHave I got you interested? Then write me a DM here on Discord! I can't wait to hear from you!")
.Build();

if(modal.Data.Components.First(x => x.CustomId == "website_input").Value != "")
{
var website_button = new ComponentBuilder();
website_button.WithButton(new ButtonBuilder()
{
Label = "Go to my Website! 🌐",
Url = modal.Data.Components.First(x => x.CustomId == "website_input").Value,
Style = ButtonStyle.Link,
});

await jobchannel.SendMessageAsync(embed: job_embed, components: website_button.Build());
}
else
{
await jobchannel.SendMessageAsync(embed: job_embed);
}

await modal.RespondAsync("done", ephemeral: true);
}
}

private async Task MessageReceivedHandler(SocketMessage message)
{
if(message.Channel.Id == jobchannel.Id)
{
await message.DeleteAsync();

//log
var log_embed = new EmbedBuilder
{
Author = new EmbedAuthorBuilder().WithName("Message deleted"),
Title = $"A message has been deleted in {jobchannel.Mention}.",
Description = $"Reason: The users should use the \"/jobs\" command.\nContent of the deleted message from {message.Author.Mention}:```\n{message.Content.Replace("`", "`​")}```", //caution! here are “zero-width blanks”
Color = Color.Red,
}
.Build();

await logchannel.SendMessageAsync(embed: log_embed);
}
}

private async Task UserJoinedHandler(SocketGuildUser user)
Expand Down
Binary file modified bin/Debug/net7.0/liebo.dll
Binary file not shown.
Binary file modified bin/Debug/net7.0/liebo.exe
Binary file not shown.
Binary file modified bin/Debug/net7.0/liebo.pdb
Binary file not shown.
Binary file modified obj/Debug/net7.0/apphost.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net7.0/liebo.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("liebo")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b6fc7246fbcd164326cf0421c7fa22fab410a7f4")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f365fa7ed3dded09d252bdddce72b03b11bf1245")]
[assembly: System.Reflection.AssemblyProductAttribute("liebo")]
[assembly: System.Reflection.AssemblyTitleAttribute("liebo")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion obj/Debug/net7.0/liebo.AssemblyInfoInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
abd135ca466547c1529be8d86d26de3492f04d34b030ca9a05d5d9156ed359ee
b91b4637c12d17bda3a28bd9eccd3c4345fcedb04bfc1f2f23541ad118f01841
Binary file modified obj/Debug/net7.0/liebo.dll
Binary file not shown.
Binary file modified obj/Debug/net7.0/liebo.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net7.0/liebo.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"C:\\Users\\TheKi\\Documents\\Liebo - LibreChat Bot\\*":"https://raw.githubusercontent.com/XHyperDEVX/Liebo/b6fc7246fbcd164326cf0421c7fa22fab410a7f4/*"}}
{"documents":{"C:\\Users\\TheKi\\Documents\\Liebo - LibreChat Bot\\*":"https://raw.githubusercontent.com/XHyperDEVX/Liebo/f365fa7ed3dded09d252bdddce72b03b11bf1245/*"}}
Binary file modified obj/Debug/net7.0/ref/liebo.dll
Binary file not shown.
Binary file modified obj/Debug/net7.0/refint/liebo.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2
0.3

0 comments on commit 72d9c2d

Please sign in to comment.