Skip to content

Commit

Permalink
Amazing welcome system.
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityDevTech committed Oct 7, 2024
1 parent f1121a2 commit f9af68a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Boolean/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class Strings
"Once completed, you may review our [issues](https://github.com/conaticusgrp/boolean/issues) and choose whichever task you are interested in.";

public static string WelcomeMsg(string userDisplay, string serverName) =>
$"Hello {userDisplay}, thank you for joining the **{serverName}** server!";
$"Whats up {userDisplay} you skibidi sigma, thank you for joining this hell hole called **{serverName}**.";
}

// Each represents the unicode for that emoji
Expand Down
49 changes: 24 additions & 25 deletions Boolean/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,7 @@ public async Task ButtonExecuted(SocketMessageComponent component)
Color = EmbedColors.Fail,
}.Build(), ephemeral: true);
}

public async Task UserJoined(IGuildUser user)
{
if (user.IsBot)
return;

// We can't pass in data context to the class because EventHandlers is a singleton and data context is scoped
var db = serviceProvider.GetRequiredService<DataContext>();

var guild = await db.Guilds.FirstOrDefaultAsync(g => g.Snowflake == user.Guild.Id);
if (guild?.JoinRoleSnowflake != null)
await user.AddRoleAsync(guild.JoinRoleSnowflake ?? 0);

var dbWelcomeChannel = await SpecialChannelTools.GetSpecialChannel(db, user.Guild.Id, SpecialChannelType.Welcome);
if (dbWelcomeChannel == null)
return;

var welcomeChannel = await user.Guild.GetChannelAsync(dbWelcomeChannel.Snowflake) as IMessageChannel;
await welcomeChannel?.SendMessageAsync(text: user.Mention, embed: new EmbedBuilder
{
Description = Config.Strings.WelcomeMsg(user.DisplayName, user.Guild.Name),
Color = EmbedColors.Normal,
}.Build())!;
}


public async Task ReactionAdded(Cacheable<IUserMessage, ulong> cachedMessage,
Cacheable<IMessageChannel, ulong> originChannel, SocketReaction reaction)
{
Expand Down Expand Up @@ -206,4 +182,27 @@ public async Task ReactionRemoved(Cacheable<IUserMessage, ulong> cachedMessage,
starReaction.ReactionCount--;
await db.SaveChangesAsync();
}

public async Task UserJoined(IGuildUser user)
{
// We can't pass in data context to the class because EventHandlers is a singleton and data context is scoped
// Whoever wrote this above is actually a nerd. 🤓👆
var db = serviceProvider.GetRequiredService<DataContext>();

var guild = await db.Guilds.FirstOrDefaultAsync(g => g.Snowflake == user.Guild.Id);
// Gotta add it, i mean, the guy needs a role.
if (guild?.JoinRoleSnowflake != null) await user.AddRoleAsync(guild.JoinRoleSnowflake ?? 0);

// I bet its a special channel.
var dbWelcomeChannel = await SpecialChannelTools.GetSpecialChannel(db, user.Guild.Id, SpecialChannelType.Welcome);
if (dbWelcomeChannel == null) return;

// Get the channel and send this epic skibidi message!
var welcomeChannel = await user.Guild.GetChannelAsync(dbWelcomeChannel.Snowflake) as IMessageChannel;
await welcomeChannel?.SendMessageAsync(text: user.Mention, embed: new EmbedBuilder
{
Description = Config.Strings.WelcomeMsg(user.DisplayName, user.Guild.Name),
Color = EmbedColors.Normal,
}.Build())!;
}
}

0 comments on commit f9af68a

Please sign in to comment.