Skip to content

Commit

Permalink
ARC v2.0 - Squashed commit
Browse files Browse the repository at this point in the history
* Added Slash commands functionality and utilities commands

* Added modmail system

* Added guild config editing and polished modmail system

* Finished user notes system

* Added ban appeals system

---------

Co-authored-by: Israel Aristide <[email protected]>
  • Loading branch information
IzzyDotExe and IzzyDotExe authored Apr 10, 2023
1 parent 248f08e commit 1d768ee
Show file tree
Hide file tree
Showing 25 changed files with 1,239 additions and 59 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.ARC V2/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.ARC V2/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.ARC V2/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.ARC V2/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.ARC V2/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ARC/ARC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DSharpPlus\DSharpPlus.Interactivity\DSharpPlus.Interactivity.csproj" />
<ProjectReference Include="..\DSharpPlus\DSharpPlus.SlashCommands\DSharpPlus.SlashCommands.csproj" />
<ProjectReference Include="..\DSharpPlus\DSharpPlus.VoiceNext\DSharpPlus.VoiceNext.csproj" />
<ProjectReference Include="..\DSharpPlus\DSharpPlus\DSharpPlus.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations" />
<Folder Include="Modules" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 28 additions & 1 deletion ARC/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Arc.Exceptions;
using Arc.Schema;
using Arc.Services;
using ARC.Services;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -93,26 +95,48 @@ private static async Task StartDiscordBot(IConfigurationRoot settings)
LoggerFactory = logFactory
};

_clientInstance = new DiscordClient(discordConfig);
_clientInstance = new DiscordClient(discordConfig)
{
ClientVersion = "2.0"
};
_serviceProvider = ConfigureServices(settings);

// Run any necessary steps before starting the bot here.
ServiceProvider.GetRequiredService<UptimeService>();
ServiceProvider.GetRequiredService<ModMailService>();
ServiceProvider.GetRequiredService<SlashCommandsService>();
ServiceProvider.GetRequiredService<InteractionService>();
ServiceProvider.GetRequiredService<BanAppealService>();


// Connect to discord!
await _clientInstance.ConnectAsync();
_clientInstance.Ready += ClientInstanceOnReady;
_clientInstance.ClientErrored += ClientInstanceOnClientErrored;

await Task.Delay(-1);
}

private static async Task ClientInstanceOnClientErrored(DiscordClient sender, ClientErrorEventArgs args)
{
var debug_log = await ClientInstance.GetChannelAsync(ulong.Parse(GlobalConfig.GetSection("discord:debug_log").Value));
var errorEmbed = new DiscordEmbedBuilder()
.WithTitle("Error!")
.WithColor(DiscordColor.Red)
.WithDescription($"***An error occured <t:{DateTimeOffset.Now.ToUnixTimeSeconds()}:R>!***\n```{args.Exception}```");

await debug_log.SendMessageAsync(errorEmbed);

}

private static async Task ClientInstanceOnReady(DiscordClient sender, ReadyEventArgs e)
{
await Task.Run(() =>
{
Log.Logger.Information($"Logged in as {sender.CurrentUser}");
Log.Logger.Information($"Ready!");
//ClientInstance.BulkOverwriteGlobalApplicationCommandsAsync(new List<DiscordApplicationCommand>() { });
//ClientInstance.BulkOverwriteGuildApplicationCommandsAsync(975717691564376084, new List<DiscordApplicationCommand>() { });
});
}

Expand All @@ -139,6 +163,9 @@ private static IServiceProvider ConfigureServices(IConfigurationRoot settings)
.AddSingleton<IConfigurationRoot>(settings)
.AddSingleton<UptimeService>()
.AddSingleton<ModMailService>()
.AddSingleton<SlashCommandsService>()
.AddSingleton<InteractionService>()
.AddSingleton<BanAppealService>()
.BuildServiceProvider();

return services;
Expand Down
5 changes: 5 additions & 0 deletions ARC/Exceptions/ArcExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public ArcNotInitializedException(string? message = null) : base($"ARC was not p
public class ArcInitFailedException : ArcException
{
public ArcInitFailedException(string? message = null) : base($"ARC Initialization failed: {message ?? Empty}") { }
}

public class ArcModmailFailedException : ArcException
{
public ArcModmailFailedException(string? message = null) : base($"ARC Modmail failed: {message ?? Empty}") { }
}
5 changes: 0 additions & 5 deletions ARC/Extensions/ClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using DSharpPlus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC.Extensions
{
Expand Down
8 changes: 2 additions & 6 deletions ARC/Extensions/EmbedBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Arc.Schema;

using DSharpPlus.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ARC.Extensions
{
Expand Down
25 changes: 25 additions & 0 deletions ARC/Extensions/GuildExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Arc.Schema;
using DSharpPlus.Entities;
using DSharpPlus;
namespace ARC.Extensions;

public static class GuildExtensions
{

private static ArcDbContext DbContext => Arc.Arc.ArcDbContext;
private static DiscordClient ClientInstance => Arc.Arc.ClientInstance;

public static async Task Log(this DiscordGuild guild, DiscordMessageBuilder message)
{

if (!DbContext.Config[guild.Id].ContainsKey("logchannel"))
return;

ulong logChannelSnowflake = ulong.Parse(DbContext.Config[guild.Id]["logchannel"]);
var channel = await ClientInstance.GetChannelAsync(logChannelSnowflake);

await channel.SendMessageAsync(message);

}

}
124 changes: 124 additions & 0 deletions ARC/Migrations/20230408134552_ArcV2-1.1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions ARC/Migrations/20230408134552_ArcV2-1.1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ARC.Migrations
{
/// <inheritdoc />
public partial class ArcV211 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "GuildSnowflake",
table: "UserNotes",
type: "bigint",
nullable: false,
defaultValue: 0L);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "GuildSnowflake",
table: "UserNotes");
}
}
}
3 changes: 3 additions & 0 deletions ARC/Migrations/ArcDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTime>("DateAdded")
.HasColumnType("timestamp with time zone");

b.Property<long>("GuildSnowflake")
.HasColumnType("bigint");

b.Property<string>("Note")
.IsRequired()
.HasColumnType("text");
Expand Down
38 changes: 38 additions & 0 deletions ARC/Modules/ArcModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

using Arc.Schema;
using DSharpPlus;
using DSharpPlus.SlashCommands;
using Microsoft.Extensions.Configuration;
using Serilog;


namespace ARC.Modules
{
internal abstract class ArcModule : ApplicationCommandModule
{

protected static bool _loaded = false;
protected readonly ArcDbContext DbContext;
protected readonly IServiceProvider ServiceProvider;
protected readonly DiscordClient ClientInstance;
protected readonly IConfigurationRoot GlobalConfig;

protected ArcModule(string moduleName)
{

DbContext = Arc.Arc.ArcDbContext;
ServiceProvider = Arc.Arc.ServiceProvider;
ClientInstance = Arc.Arc.ClientInstance;
GlobalConfig = Arc.Arc.GlobalConfig;

if (_loaded)
return;
RegisterEvents();
Log.Logger.Information($"MODULE LOADED: {moduleName}");
_loaded = true;
}

protected abstract void RegisterEvents();

}
}
Loading

0 comments on commit 1d768ee

Please sign in to comment.