Skip to content

Commit

Permalink
I did something again oh no
Browse files Browse the repository at this point in the history
  • Loading branch information
VelvetToroyashi committed Jan 26, 2021
1 parent d373034 commit 434dddf
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 123 deletions.
14 changes: 6 additions & 8 deletions src/Silk.Core/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void InitializeCommands()
Assembly asm = Assembly.GetExecutingAssembly();
IReadOnlyDictionary<int, CommandsNextExtension> cNext = Client.GetCommandsNextAsync().GetAwaiter().GetResult();
CommandsNextExtension[] extension = cNext.Select(c => c.Value).ToArray();

var sw = Stopwatch.StartNew();
foreach (CommandsNextExtension c in extension)
c.RegisterCommands(asm);
Expand All @@ -80,7 +80,8 @@ private async Task InitializeClientAsync()
{
UseDefaultCommandHandler = false,
Services = _services,
IgnoreExtraArguments = true
IgnoreExtraArguments = true,

};
Client.Ready += async (c, _) => _logger.LogInformation($"Recieved OP 10 - HELLO from Discord on shard {c.ShardId + 1}!");

Expand All @@ -95,7 +96,7 @@ await Client.UseInteractivityAsync(new()
PaginationBehaviour = PaginationBehaviour.WrapAround,
PaginationDeletion = PaginationDeletion.DeleteMessage,
PollBehaviour = PollBehaviour.KeepEmojis,
Timeout = TimeSpan.FromMinutes(1),
Timeout = TimeSpan.FromMinutes(1)
});


Expand All @@ -109,17 +110,14 @@ await Client.UseInteractivityAsync(new()
t.RegisterConverter(memberConverter);
}
await Client.StartAsync();
Program.Sw.Stop();

double startupDt = DateTime.Now.Subtract(Program.Startup).TotalMilliseconds;
_logger.LogInformation($"Startup time: {startupDt:N0} ms.");
}

public async Task StartAsync(CancellationToken cancellationToken) => await InitializeClientAsync();

public async Task StopAsync(CancellationToken cancellationToken)
{
await Client.StopAsync();
}
public async Task StopAsync(CancellationToken cancellationToken) => await Client.StopAsync();

}
}
2 changes: 1 addition & 1 deletion src/Silk.Core/Commands/Bot/ShardsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Shards(CommandContext ctx)

totalPing += shard.Ping;
}
embed.AddField(embedTitle, sb.ToString());
embed.WithDescription($"**{embedTitle}** \n{sb}");
//embed.AddField()
sb.Clear();

Expand Down
13 changes: 9 additions & 4 deletions src/Silk.Core/Commands/General/DiceRoll/DiceRollCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ public async Task Random(CommandContext ctx, int max = 100) =>
[Description("Roll die like it's DnD! Example: 2d4 + 10 + d7")]
public async Task Roll(CommandContext ctx, [RemainingText] string roll)
{
if (string.IsNullOrEmpty(roll))
{
await ThrowHelper.EmptyArgument(ctx);
return;
}
var parser = new DiceParser(roll);
IList<Step> steps = parser.Run();

var embed = InitEmbed(new());
DiscordEmbedBuilder embed = InitEmbed(new());
var ran = new Random((int) ctx.Message.Id);
var modifiers = new List<int>();
var rolls = new List<int>();

for (int i = 0; i < steps.Count; i++)
{
if (steps[i].Type == StepType.Addition)
if (steps[i].Type is StepType.Addition)
{
modifiers.Add(steps[i].TotalNumber);
}
Expand All @@ -52,11 +57,11 @@ public async Task Roll(CommandContext ctx, [RemainingText] string roll)


embed.AddField("Modifiers", $"\t{string.Join(", ", modifiers)} | {modifiers.Sum()}");
embed.AddField("Total", $"{(rolls.Sum() + modifiers.Sum())}");
embed.AddField("Total", $"{rolls.Sum() + modifiers.Sum()}");
await ctx.RespondAsync(embed: embed).ConfigureAwait(false);
}

private DiscordEmbedBuilder InitEmbed(DiscordEmbedBuilder embed) =>
private static DiscordEmbedBuilder InitEmbed(DiscordEmbedBuilder embed) =>
embed
.WithColor(DiscordColor.PhthaloGreen)
.WithTitle("You rolled:")
Expand Down
1 change: 1 addition & 0 deletions src/Silk.Core/Commands/General/PingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PingCommand : BaseCommandModule
public PingCommand(IDbContextFactory<SilkDbContext> dbFactory) => _dbFactory = dbFactory;

[Command("ping")]
[Aliases("pong")]
[Description("Check the responsiveness of Silk")]
public async Task Ping(CommandContext ctx)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Silk.Core/Commands/Moderation/TempMuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ await ctx.RespondAsync($"{user.Username} is {user.Roles.Last().Position - bot.Ro

if (config.MuteRoleId is 0)
{
await ErrorHelper.MuteRoleNotFoundInDatabase(ctx.Channel);
await ThrowHelper.MuteRoleNotFoundInDatabase(ctx.Channel);
return;
}

Expand Down
28 changes: 0 additions & 28 deletions src/Silk.Core/Commands/Roles/ObtainRoleCommand.cs

This file was deleted.

72 changes: 0 additions & 72 deletions src/Silk.Core/Commands/Roles/SetAssignableRole.cs

This file was deleted.

25 changes: 25 additions & 0 deletions src/Silk.Core/Commands/Server/Configuration/BaseConfigCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;

namespace Silk.Core.Commands.Server.Configuration
{

[RequireGuild]
[Group("config")]
[Aliases("configuration")]
[RequireUserPermissions(Permissions.ManageGuild)]
[Description("Edit configurations the caveman way!\nOr perhaps we just haven't launched the dashboard yet..")]
public partial class BaseConfigCommand : BaseCommandModule
{
[GroupCommand]
public async Task Config(CommandContext ctx) =>
await new DiscordMessageBuilder()
.WithReply(ctx.Message.Id, true)
.WithContent($"See `{ctx.Prefix}help config` instead.")
.SendAsync(ctx.Channel);
// This just serves to tell the user to see the help instead.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;

namespace Silk.Core.Commands.Server.Configuration
{
public partial class BaseConfigCommand
{
[Group("edit")]
public partial class BaseEditConfigCommand : BaseCommandModule
{
[GroupCommand]
public async Task EditConfig(CommandContext ctx) =>
await new DiscordMessageBuilder()
.WithReply(ctx.Message.Id, true)
.WithContent($"See `{ctx.Prefix}help config edit`.")
.SendAsync(ctx.Channel);
}
}

}
30 changes: 30 additions & 0 deletions src/Silk.Core/Commands/Server/Configuration/ResetConfigCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity.Extensions;

namespace Silk.Core.Commands.Server.Configuration
{
//[Group("config")]
public class ResetConfigCommand : BaseCommandModule
{
[Command]
public async Task Reset(CommandContext ctx)
{
var builder = new DiscordMessageBuilder();
var confirmationCode = new Random((int) ctx.Message.Id).Next(1000, 10000);
builder.WithReply(ctx.Message.Id, true);
builder.WithContent($"**All settings will be reset** (This does not include server prefix) | Are you sure? Type `{confirmationCode}` to confirm. Type cancel to cancel");
await ctx.RespondAsync(builder);

var interactivity = ctx.Client.GetInteractivity();
var result = await interactivity.WaitForMessageAsync(m => m.Content.Equals("cancel", StringComparison.CurrentCultureIgnoreCase) || m.Content.Equals(confirmationCode));




}
}
}
11 changes: 11 additions & 0 deletions src/Silk.Core/Constants/GeneralMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Silk.Core.Constants
{
/// <summary>
/// A class containing const
/// </summary>
public static class GeneralMessages
{
public const string
NoConfigValue = "Not configured";
}
}
5 changes: 2 additions & 3 deletions src/Silk.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Silk.Core
public class Program
{
public static DateTime Startup { get; } = DateTime.Now;
public static Stopwatch Sw { get; } = Stopwatch.StartNew();


public static string HttpClientName { get; } = "Silk";

Expand All @@ -30,8 +30,7 @@ public class Program
DiscordIntents.GuildMessageReactions | // Role-menu
DiscordIntents.DirectMessages | // DM Commands
DiscordIntents.DirectMessageReactions |
DiscordIntents.GuildPresences, // Auto-mod
ShardCount = 3,
DiscordIntents.GuildPresences, // Auto-mod,
MessageCacheSize = 1024,
MinimumLogLevel = LogLevel.Error
};
Expand Down
6 changes: 5 additions & 1 deletion src/Silk.Core/Silk.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<ItemGroup>
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="CommandLineParser" Version="2.9.0-preview1" />
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00779" />
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00783" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-nightly-00779" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-nightly-00779" />
<PackageReference Include="Humanizer" Version="2.8.26" />
Expand Down Expand Up @@ -99,5 +99,9 @@
<Compile Remove="Commands\Bot\GuildJoinHandler.cs" />
<Compile Remove="Commands\Bot\Restart.cs" />
</ItemGroup>

<ItemGroup>
<Folder Include="Commands\Server\Roles" />
</ItemGroup>

</Project>
12 changes: 11 additions & 1 deletion src/Silk.Core/Tools/EventHelpers/GuildAddedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class GuildAddedHandler
private readonly ILogger<GuildAddedHandler> _logger;

private readonly Dictionary<int, int> _shards = new();
private readonly Dictionary<int, bool> _completedShards = new();
private readonly Dictionary<int, List<CacheObject>> _cacheQueue = new();
private readonly Dictionary<int, (int, int)> _guildCounters = new();

Expand All @@ -38,6 +39,7 @@ public GuildAddedHandler(ILogger<GuildAddedHandler> logger, IDatabaseService dbS
{
_cacheQueue.TryAdd(i, new());
_shards.TryAdd(i, 0);
_completedShards.TryAdd(i, false);
_guildCounters.TryAdd(i, new());
}
}
Expand All @@ -58,6 +60,14 @@ public Task OnGuildDownloadComplete(DiscordClient c, GuildDownloadCompletedEvent
{
_logger.LogTrace($"Guild download complete for shard {c.ShardId + 1}");
_logger.LogTrace("Preparing to iterate over cache objects");

bool[] completedShards = new bool[Bot.Instance!.Client.ShardClients.Count];

for (int i = 0; i < Bot.Instance!.Client.ShardClients.Count; i++)
completedShards[i] = _completedShards[i];
startupCacheCompleted = completedShards.All(s => s);


_ = Task.Run(async () =>
{
for (var i = 0; i < _cacheQueue[c.ShardId].Count; i++)
Expand Down Expand Up @@ -113,7 +123,7 @@ private async Task SendWelcomeMessage(DiscordClient c, GuildCreateEventArgs e)
.Append("If there's an issue, feel free to [Open an issue on GitHub](https://github.com/VelvetThePanda/Silk/issues), ")
.AppendLine("or if you're not familiar with GitHub, feel free")
.AppendLine($"to message the developers directly via {Bot.DefaultCommandPrefix}`ticket create <your message>`.")
.Append($"By default, the prefix is `{Bot.DefaultCommandPrefix}`, or <@{c.CurrentUser.Id}>, but this can be changed by !setprefix <your prefix here>.");
.Append($"By default, the prefix is `{Bot.DefaultCommandPrefix}`, or <@{c.CurrentUser.Id}>, but this can be changed by {Bot.DefaultCommandPrefix}setprefix <your prefix here>.");

embed.WithDescription(sb.ToString());

Expand Down
Loading

0 comments on commit 434dddf

Please sign in to comment.