Skip to content

Commit e0aabb7

Browse files
authored
Merge pull request #45 from GedasFX/dev
Dev
2 parents 6821384 + 5ea0e85 commit e0aabb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+637
-1000
lines changed

Alderto.Bot.Lua/Alderto.Bot.Lua.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFramework>netstandard2.1</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Alderto.Bot.Lua/CustomCommandProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public class CustomCommandProvider : ICustomCommandProvider
1616
/// </summary>
1717
private const int CustomCommandExecTimeout = 100;
1818

19-
private readonly IAldertoDbContext _context;
19+
private readonly AldertoDbContext _context;
2020
private readonly NLua.Lua _luaState;
2121
private readonly Dictionary<string, LuaFunction> _commands;
2222

23-
public CustomCommandProvider(IAldertoDbContext context)
23+
public CustomCommandProvider(AldertoDbContext context)
2424
{
2525
_context = context;
2626
_luaState = new NLua.Lua();

Alderto.Bot/Alderto.Bot.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
<UserSecretsId>c53fe5d3-16e9-400d-a588-4859345371e5</UserSecretsId>
77
<StartupObject>Alderto.Bot.Program</StartupObject>
8-
<Configurations>Debug;Release;Testing</Configurations>
8+
<Configurations>Debug;Release</Configurations>
99
</PropertyGroup>
1010

1111
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Testing|AnyCPU'">
@@ -36,7 +36,6 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<ProjectReference Include="..\Alderto.Bot.Lua\Alderto.Bot.Lua.csproj" />
4039
<ProjectReference Include="..\Alderto.Data\Alderto.Data.csproj" />
4140
<ProjectReference Include="..\Alderto.Services\Alderto.Services.csproj" />
4241
</ItemGroup>

Alderto.Bot/Modules/CurrencyModule.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public async Task CheckAsync(
107107
await this.ReplyEmbedAsync($"{user.Mention} has {dbUser.CurrencyCount} {currencySymbol}");
108108
}
109109

110-
[Command("Timely"), Alias("Tub", "ClaimTub", "Moon")]
110+
[Command("Timely"), Alias("Moon")]
111111
[Summary("Grants a timely currency reward.")]
112112
public async Task Timely()
113113
{

Alderto.Bot/Services/CommandHandler.cs

+36-39
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ public async Task StartAsync()
5050
//
5151
// If you do not use Dependency Injection, pass null.
5252
// See Dependency Injection guide for more information.
53-
using (var scope = _services.CreateScope())
54-
{
55-
await _commands.AddModulesAsync(Assembly.GetExecutingAssembly(), scope.ServiceProvider);
56-
}
57-
53+
using var scope = _services.CreateScope();
54+
await _commands.AddModulesAsync(Assembly.GetExecutingAssembly(), scope.ServiceProvider);
55+
5856
}
5957

6058
public async Task HandleCommandAsync(SocketMessage messageParam)
@@ -75,7 +73,8 @@ public async Task HandleCommandAsync(SocketMessage messageParam)
7573
var prefix = (await _guildPreferences.GetPreferencesAsync(guildUser.Guild.Id)).Prefix;
7674

7775
// Determine if the message is a command based on the prefix and make sure no bots trigger commands
78-
if (!(message.HasStringPrefix(prefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot)
76+
// TODO: Re add || message.Author.IsBot
77+
if (!(message.HasStringPrefix(prefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)))
7978
return;
8079

8180
// Create a WebSocket-based command context based on the message
@@ -85,46 +84,44 @@ public async Task HandleCommandAsync(SocketMessage messageParam)
8584
// created, along with the service provider for precondition checks.
8685

8786
// Create a scope to prevent leaks.
88-
using (var scope = _services.CreateScope())
89-
{
90-
// TODO: Upgrade this to RunMode.Async
87+
using var scope = _services.CreateScope();
88+
// TODO: Upgrade this to RunMode.Async
9189

92-
// Keep in mind that result does not indicate a return value
93-
// rather an object stating if the command executed successfully.
94-
var result = await _commands.ExecuteAsync(context, argPos, scope.ServiceProvider);
90+
// Keep in mind that result does not indicate a return value
91+
// rather an object stating if the command executed successfully.
92+
var result = await _commands.ExecuteAsync(context, argPos, scope.ServiceProvider);
9593

96-
// Delete successful triggers.
97-
if (result.IsSuccess)
94+
// Delete successful triggers.
95+
if (result.IsSuccess)
96+
{
97+
try
9898
{
99-
try
100-
{
101-
await message.DeleteAsync();
102-
}
103-
catch (Discord.Net.HttpException)
104-
{
105-
// Delete most likely failed due to no ManageMessages permission. Ignore regardless.
106-
}
99+
await message.DeleteAsync();
107100
}
101+
catch (Discord.Net.HttpException)
102+
{
103+
// Delete most likely failed due to no ManageMessages permission. Ignore regardless.
104+
}
105+
}
108106

109-
// Optionally, we may inform the user if the command fails
110-
// to be executed; however, this may not always be desired,
111-
// as it may clog up the request queue should a user spam a
112-
// command.
107+
// Optionally, we may inform the user if the command fails
108+
// to be executed; however, this may not always be desired,
109+
// as it may clog up the request queue should a user spam a
110+
// command.
113111

114-
else if (result.Error != CommandError.UnknownCommand)
112+
else if (result.Error != CommandError.UnknownCommand)
113+
{
114+
try
115+
{
116+
await context.Channel.SendMessageAsync(embed: new EmbedBuilder()
117+
.WithDefault(result.ErrorReason, EmbedColor.Error).Build());
118+
}
119+
catch (Discord.Net.HttpException e)
115120
{
116-
try
117-
{
118-
await context.Channel.SendMessageAsync(embed: new EmbedBuilder()
119-
.WithDefault(result.ErrorReason, EmbedColor.Error).Build());
120-
}
121-
catch (Discord.Net.HttpException e)
122-
{
123-
// 50013 occurs when bot cannot send embedded messages. All error reports use embeds.
124-
if (e.DiscordCode == 50013)
125-
await context.Channel.SendMessageAsync(
126-
"Bot requires guild permission EmbedLinks to function properly.");
127-
}
121+
// 50013 occurs when bot cannot send embedded messages. All error reports use embeds.
122+
if (e.DiscordCode == 50013)
123+
await context.Channel.SendMessageAsync(
124+
"Bot requires guild permission EmbedLinks to function properly.");
128125
}
129126
}
130127
}

Alderto.Bot/Startup.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Startup
1717
{
1818
public IServiceProvider ConfigureServices(IConfiguration config) => new ServiceCollection()
1919
// Add database
20-
.AddDbContext<IAldertoDbContext, AldertoDbContext>(options =>
20+
.AddDbContext<AldertoDbContext>(options =>
2121
{
2222
options.UseNpgsql(
2323
$"Server={config["Database:Host"]};" +
@@ -61,7 +61,7 @@ public async Task RunAsync()
6161
using (var scope = services.CreateScope())
6262
{
6363
Console.Out.WriteLine("Initializing database...");
64-
using (var context = scope.ServiceProvider.GetRequiredService<IAldertoDbContext>())
64+
using (var context = scope.ServiceProvider.GetRequiredService<AldertoDbContext>())
6565
{
6666
await context.Database.MigrateAsync();
6767
}

Alderto.Data/Alderto.Data.csproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFramework>netstandard2.1</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<ApplicationIcon />
88
<StartupObject />
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
13-
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="2.2.0" />
14-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
12+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.0" />
1513
</ItemGroup>
1614

1715
</Project>

Alderto.Data/AldertoDbContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Alderto.Data
66
{
7-
public class AldertoDbContext : DbContext, IAldertoDbContext
7+
public class AldertoDbContext : DbContext
88
{
99
public DbSet<Guild> Guilds { get; set; }
1010
public DbSet<GuildMember> GuildMembers { get; set; }

0 commit comments

Comments
 (0)