master
exsersewo 5 years ago
parent 793b5d8195
commit 2a4720e790
  1. 24
      Kehyeedra3/Command handler.cs
  2. 8
      Kehyeedra3/Kehyeedra3.csproj
  3. 6
      Kehyeedra3/Properties/PublishProfiles/FolderProfile.pubxml
  4. 22
      Kehyeedra3/Services/ReminderService.cs

@ -130,6 +130,30 @@ namespace Kehyeedra3
var jojoke = WeebClient.DownloadString("https://api.skuldbot.uk/fun/jojoke/?raw"); var jojoke = WeebClient.DownloadString("https://api.skuldbot.uk/fun/jojoke/?raw");
await context.Channel.SendMessageAsync($"{context.User.Mention} is that a fucksnifflerling {jojoke} reference?"); await context.Channel.SendMessageAsync($"{context.User.Mention} is that a fucksnifflerling {jojoke} reference?");
} }
if (message.Channel is IGuildChannel chan)
{
var perms = chan.GetPermissionOverwrite(_bot.CurrentUser);
if (perms.HasValue)
{
if (perms.Value.SendMessages == PermValue.Deny) return;
}
var botGuild = _bot.GetGuild(chan.GuildId).GetUser(_bot.CurrentUser.Id);
bool exit = false;
botGuild.Roles.OrderByDescending(x => x.Position).ToList().ForEach(x =>
{
perms = chan.GetPermissionOverwrite(x);
if (perms.HasValue)
{
if (perms.Value.SendMessages == PermValue.Deny) { exit = true; return; }
}
});
if (exit) return;
}
if (!(message.HasStringPrefix(Configuration.Load().Prefix, ref argPos))) return; if (!(message.HasStringPrefix(Configuration.Load().Prefix, ref argPos))) return;
{ {
var result = await _cmds.ExecuteAsync(context, argPos, _dmap); var result = await _cmds.ExecuteAsync(context, argPos, _dmap);

@ -2,14 +2,16 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>2020.4.0.0</AssemblyVersion>
<FileVersion>2020.4.0.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Discord.Addons.Interactive" Version="1.0.1" /> <PackageReference Include="Discord.Addons.Interactive" Version="1.0.1" />
<PackageReference Include="Discord.Net" Version="2.1.1" /> <PackageReference Include="Discord.Net" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>

@ -7,9 +7,11 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Any CPU</Platform> <Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.1\publish\</PublishDir> <PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained> <SelfContained>false</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

@ -15,27 +15,31 @@ namespace Kehyeedra3.Services
} }
public async Task Tick() public async Task Tick()
{ {
using (var Database = new ApplicationDbContextFactory().CreateDbContext()) while (true)
{ {
List<Reminder> toRemove = new List<Reminder>(); using (var Database = new ApplicationDbContextFactory().CreateDbContext())
while (true)
{ {
var reminders = Database.Reminders.ToList();
if(Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected) if(Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected)
{ {
foreach(var x in Database.Reminders) bool hasChanged = false;
foreach (var x in reminders)
{ {
if (x.Send <= DateTime.UtcNow.ToYeedraStamp()) if (x.Send <= DateTime.UtcNow.ToYeedraStamp())
{ {
await SendReminderAsync(x).ConfigureAwait(false); await SendReminderAsync(x).ConfigureAwait(false);
toRemove.Add(x); Database.Reminders.Remove(x);
hasChanged = true;
} }
} }
Database.Reminders.RemoveRange(toRemove);
await Database.SaveChangesAsync().ConfigureAwait(false); if (hasChanged)
toRemove.Clear(); {
await Database.SaveChangesAsync().ConfigureAwait(false);
}
} }
await Task.Delay(250);
} }
await Task.Delay(250);
} }
} }
} }

Loading…
Cancel
Save